Close btn

In this category you can exchange your programming questions and solutions.
Post Reply
cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

Close btn

Post: # 1097Post cvirus
Wed Jul 24, 2013 2:32 pm

Hello, how can i trap the red x button on the form to break a loop?

thanks

:D

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Close btn

Post: # 1098Post Marco
Wed Jul 24, 2013 3:26 pm

This will do, it is also in the folder with examples (forms).

best regards



`form with a onclose dialog

object myform as form
  caption="Onclose dialog"
  center
  onclose=myformClose
end object

myform.showmodal

sub myformclose(s as form,action as integer)
  dim answer as integer
  answer=messagedlg("Really want to abort this form?",myform.caption,mbokcancel+mbiconquestion)
  if answer=2 then action=0
end sub

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

Close btn

Post: # 1099Post cvirus
Wed Jul 24, 2013 4:12 pm

but how to trap it when there`s none messagedlg?

imagine that i what to finish a loop when that red btn is pushed.

Thanks

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Close btn

Post: # 1100Post Marco
Mon Jul 29, 2013 3:32 pm

That is not easy because you must intercept the nonclientarea messages.
Here` s an example to do that, mostly used for games.
best regards

` example to intercept window messages
const htclose=20
const pm_remove=1
const WM_NCLBUTTONDOWN=&ha1
const WM_NCLBUTTONUP=&ha2

record MSGrecord
  hwnd as integer
  mes as integer
  wparam as integer
  lparam as integer
  tim as integer
  pt as integer
  pt1 as integer
end record

Declare SendMessage as "SendMessageA" of "user32"
  hwnd As Long
  wMsg As Long
  wParam As Long
  lParam As Long
end declare

declare peekmessage as "PeekMessageA" of user32
  Msg as msgrecord
  hWnd as integer
  wMsgFilterMin as integer
  wMsgFilterMax  as integer
  wproces as integer
  result as integer
end declare

object f as form
  onpaint=enterloop
  showmodal
end object

sub enterloop
  dim closeapp as boolean
  `` Enter the infinite message loop
  do
    do
      peekmessage.wproces=1
      peekmessage.execute
      if peekmessage.msg.mes=WM_NCLBUTTONdown then
        if peekmessage.msg.wparam=htclose then closeapp=true
      end if
      if peekmessage.result=0 then exit do
      sendmessage.hwnd=peekmessage.msg.hwnd
      sendmessage.wmsg=peekmessage.msg.mes
      sendmessage.wparam=peekmessage.msg.wparam
      sendmessage.lparam=peekmessage.msg.lparam
      sendmessage.execute
    loop
    ` Run your code here (example)
    dim t as integer
    inc(t)
    f.caption=str$(t)
    ` end code
  loop until closeapp=true
  end
end sub

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

Close btn

Post: # 1101Post cvirus
Tue Jul 30, 2013 1:23 pm

Thanks, it looks complicated, but i will try it.

Thanks

Post Reply