hi,
Say I have a singlethreaded application, & after i use the Messageloop (& close the associated window) i want to stop the loop but keep my .exe still running.Is this possible to do ( correctly) . below are some questions related to the topic
- Usually to stop the Messageloop I'd use PostQuitMessage on a WM_DESTROY msg & then just return control to my app on exiting the message loop. Does the os on its side do anything when i use this function ?(because this function is a request from the thread, to terminate.) - in other words is it safe to keep my app functioning after using this function ? - maybe create another window & start the Mssageloop again etc.
app_code:
some code
...
jmp Messageloop
; call Messageloop
Messageloop:
. . .
jmp Messageloop
ExitMsgLoop:
mov eax, msg.wParam
jmp app_code
; ret
thankyou
-
[edit] - trying some stuff again & in the above type of code it appears that the 2nd time i call the Messageloop after destroying the old window etc & creating a new window,... GetMessage returns 0 - any idea why ? (the windows am using in this case are modeless dialogs)
I can't help but wonder why you would want to do this. For a single-window app when the user closes the window they would normally expect the underlying app to terminate, not to stay in memory and then at some later time open another window. If an app did this on my system I would assume that it was some sort of malware.
hi, MIchael
I was trying this to display a succession of diff dialogs.(the next opening when the previous one closes) & then started thinking of it & got more interested in this topic itself (the Messageloop thing etc) .. like as i mentioned in my last post- It seems like a usefull thing.
It would just be interesting to know the answers to those questions.
I just kinda managed to do what i was originally after(displaying a succession of diiff dialogs). & it seems to work proper(so far), & more like i want it to - but I don't know how correct it is coding wise & the way it deals with the OS
thankyou.
[edit] Think i'll end posting.. since the topic seems to be a bit on the fringe
-
Without PostQuitMessage:Messageloop proc hwnd:DWORD
innerloop:
getmessage/translate/dispatch
invoke IsWindow, hwnd
and eax,eax
jnz innerloop
Rainstorm,
The attachment is a nested modeless dialog demo that uses the MASM32 v10 in-memory dialog macros. Perhaps it will give you some idea of how to do what you are trying to do without any monkey motion.
[attachment deleted by admin]
thanks for the replies guys.
Michael, just dloaded the .sip & looking at it.
Rainstorm,
A Windows message loop ALREADY does what you require, the GetMessage API does not return until there is a new message in the message que so its processor usage on idle is ZERO.
hutch, that's right.. but i meant if i needed to destroy the window, in that case the hwnd supplied in GetMessage function would be invalid, & i'd have to exit the msg loop.. maybe create the next window & jmp back to the loop again.
Anyhow i've figured, it out & got it working.
Thanks!
Rainstorm,
just very draft demo
(main DlgMsgLoop + servo PostThreadMsg)
with folowing variant of message loop:
DialogMessageLoop proc
local msg:MSG
.while TRUE
invoke GetMessage,addr msg,0,0,0
.break .if (!eax)
.if msg.message==WM_CREATEDIALOG
invoke GetModuleHandle,0
invoke CreateDialogParam,eax,id,0,offset DlgProc,0
.endif
invoke GetActiveWindow
; invoke GetAncestor,msg.hwnd,GA_ROOT
.if eax!=0
mov ecx,eax
invoke IsDialogMessage,ecx,addr msg
.if eax==TRUE
.continue
.endif
.endif
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
.endw
mov eax,msg.wParam
ret
DialogMessageLoop endp
Run PostThreadMsg.exe before DlgMsgLoop.exe.
(+ Process Explorer for control).
[attachment deleted by admin]