Hello, how can i trap the red x button on the form to break a loop?
thanks
:D
Close btn
Close btn
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
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
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
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