Page 1 of 1

Close btn

Posted: Wed Jul 24, 2013 2:32 pm
by cvirus
Hello, how can i trap the red x button on the form to break a loop?

thanks

:D

Close btn

Posted: Wed Jul 24, 2013 3:26 pm
by Marco
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

Close btn

Posted: Wed Jul 24, 2013 4:12 pm
by cvirus
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

Close btn

Posted: Mon Jul 29, 2013 3:32 pm
by Marco
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

Close btn

Posted: Tue Jul 30, 2013 1:23 pm
by cvirus
Thanks, it looks complicated, but i will try it.

Thanks