×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Beginner's q

Beginner's q

Beginner's q

(OP)
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?

RE: Beginner's q

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:

  .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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close