flat assembler
Message board for the users of flat assembler.

Index > Windows > need help with "using messages and message queues"

Thread Post new topic Reply to topic

Joined: 09 Jul 2009
Posts: 9
Location: tenerife/spain
hi all,
if have some questions about "using messages and message queues"

on microsoft web page "http://msdn.microsoft.com/en-us/library/ms644928(VS.85).aspx" i have found this:
"this message loop retrieves messages from the thread's message queue and dispatches them to the appropriate window procedures."

thats my messageloop:

invoke GetMessage ,sys_windowmessage ,NULL ,0 ,0
or eax,eax ;If the function retrieves the WM_QUIT message, the return value is zero.
jz ReturnToWindow
cmp eax,-1 ;If there is an error, the return value is -1
je ReturnToWindow

invoke TranslateMessage,sys_windowmessage
invoke DispatchMessage,sys_windowmessage
jmp getmessageloop

below on that page i have found in the section "Examining a Message Queue" this one:
"Occasionally, an application needs to examine the contents of a thread's message queue from outside the thread's message loop. For example, if

an application's window procedure performs a lengthy drawing operation, you may want the user to be able to interrupt the operation. Unless your

application periodically examines the message queue during the operation for mouse and keyboard messages, it will not respond to user input until

after the operation has completed. The reason for this is that the DispatchMessage function in the thread's message loop does not return until the

window procedure finishes processing a message.
if i have understood it well does it mean that dispatchmessage will ever wait until the window procedure finishes processing its actually message AND

cannot continue with "jmp getmessageloop"?

the section "Sending a Message" explain this:
The SendMessage function is used to send a message "DIRECTLY" to a window procedure. SendMessage calls a window procedure and waits for

that procedure to process the message and return a result.

is it true that "sendmessage" jumps directly to
proc MainWindowProc, msg_hwnd, msg_wmsg, msg_wparam, msg_lparam
and NOT PASS by "getmessageloop:" with "getmessage, translatemessage, dispatchmessage" ?

the other questions is (from section "Posting a Message"):
is it true that "PostMessage places a message at the end of a thread's message queue and returns immediately, without waiting for the thread to

process the message"?
and does it mean that "postmessage" passes by "getmessageloop" with "getmessage, translatemessage, dispatchmessage" ?

maybe these questions are a little bit strange for you, but i have some problems with "postmessage" and the message loop, please have a look to

the following:

i have a data base with nearly 100 url which the program has to download, after a click on the menu-item (ID=102) "start download" the download

begins, during the download the processor will never pass by "getmessageloop:" so microsoft recommends to use "peekmessage" (see above), but

"peekmessage" will NOT REMOVE from the message queue e.g. "WM_PAINT" and some other messages and moreover i have many import

functions in the
proc MainWindowProc, msg_hwnd, msg_wmsg, msg_wparam, msg_lparam
so that i will execute the download (step by step/url by url) and the other functions TOO, and i will not write all the function which i have already in the

"proc MainWindowProc" anonther time in a "proc xxxx" with "peekmessage" and when i have finished the download, that there are still waiting some

message which i have already proceeded, therefore i have writen the following code:

proc MainWindowProc, msg_hwnd, msg_wmsg, msg_wparam, msg_lparam


cmp eax,WM_CLOSE
je mwp_wmclose
cmp eax,WM_DESTROY
je mwp_wmdestroy
cmp eax,WM_SIZE
je .wm_size003
cmp eax,WM_PAINT
je .wm_paint004

jne .wm_subscription103

invoke EnableMenuItem ,[newsreader_menuhandle] ,IDM_SUBSCRIPTION101 ,MF_GRAYED
invoke EnableMenuItem ,[newsreader_menuhandle] ,IDM_SUBSCRIPTION102 ,MF_GRAYED
mov eax,[newsreader_subscriptionmemoadr] ;start subscription list
mov [newsreader_subscriptionnextpointer],eax
invoke PostMessage, [newsreader_mainwindowhandle] ,WM_USER+102 ,0 ,0 ; passing by getmessageloop
jmp .wm_end


cmp eax,WM_USER+102
jne .wmuser103
call newsreadersubscription102downloadrssfeeds
or eax,eax
jz .wm_end ; = ERROR
; continue next URL
invoke PostMessage, [newsreader_mainwindowhandle] ,WM_USER+102 ,0 ,0 ; passing by getmessageloop
jmp .wm_end




this "LOOP" is goeing quite well and does download all url - BUT
a) the menu bar is blocked completly, so that i cannot open/click/choose the menu-item "STOP/BREAK",
b) i cannot close the window with a click on "X"

so - does have somebody an idea where is the stupid mistake - smile,
or maybe in which way i could write a better code
or maybe somebody does know other threats here where i can find some more helps

thanks and regards
Post 22 Jul 2009, 12:36
View user's profile Send private message Reply with quote

Joined: 27 Dec 2004
Posts: 805
Your issue is a threading/process issue.

If you have 1 thread doing a task it will complete this task in LINEAR order.
PROCESS MESSAGE (will hang until its down) ->

What you probably want to do is have your WND PROC spawn another thread that does the long task (downloading URLs) this way the WORKER THREAD will be processing separately from your GUI/MAIN THREAD.

Look at the CreateThread api
Post 22 Jul 2009, 13:58
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.