Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner's q

Status
Not open for further replies.

sandup

Technical User
Jun 7, 2003
24
0
0
RO
Hi,

I'm trying to understand this code. This is the message loop in WinMain, it keeps asking for messages.

.WHILE TRUE
invoke GetMessage, ADDR msg,0,0,0
.BREAK .IF (!eax) ; break if no message
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW

I have a few questions:

1. Is GetMessage an API call? Is there one big global message queue, managed by Windows, where all messages are stored, with the handles of the windows they are sent to? Or many message queues, one for every application?

2. Why does it "break if no message" (eax == 0)? If there is no message waiting the window is supposed to just stay there, not close!

3. What does TranslateMessage do?

4. What does DispatchMessage do?
 
Hi sandup.

I have some answers for your questions...

1. GetMessage is a Win API call. There are many message queues, one used for each application. It is the operating system that processes the messages and puts them in the relevent applications message queue, as each message is relevent to either a specific thread or process. The OS will decide which process/thread the message should be posted to. This is where GetMessage is used - GetMessage should hang in a loop until (a) message(s) are in the process/thread message queue, if there is then it should process them.

2. I'm not sure about the macros you are using, but I think it might need to be in this format instead:
Code:
  .IF (!eax)  ; if no message...
    .BREAK    ; ...then break

3. TranslateMessage is used to turn VK (virtual key) messages into a character message by combining two close VK messages (KeyUp and KeyDown) into one Character message.
WM_KEYDOWN and WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message. WM_SYSKEYDOWN and WM_SYSKEYUP combinations produce a WM_SYSCHAR or WM_SYSDEADCHAR message. These messages make keyboard input more managable, but if you do not need to use this then TranslateMessage can be left out of the message loop. It is traditional in most applications to have this here, though.

4. DispatchMessage is probably the most important message function here. It *dispatches* or sends the message to the appropriate procedure, normally a window procedure, which will then process the message and take the appropriate action. (An exception is WM_TIMER which could go to a Window procedure, but is more likely to go to a Timer procedure - itdepends on the message parameters).

Hope that helps you. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top