Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8575751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:45:54+00:00 2026-06-11T19:45:54+00:00

I am trying to make sense of ‘The Message Loop’. This is how it

  • 0

I am trying to make sense of ‘The Message Loop’.
This is how it looks:

MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

So far I am clear(at least I hope so) with the concept.When the user interacts with windows application using keyboard and mouse,those events are converted to appropriate messages by the respective device drivers and posted to system message queue.

The OS removes messages from the queue one by one and examines each of them to send them to respective application’s thread’s queue that is responsible for having created the destination window.

Now in my application

MSG msg;
GetMessage(&msg, NULL, 0, 0);

removes the message from thread specific message queue and fills the MSG structure.

But TranslateMessage is said to translate the virtual keystrokes to characters and post them back to the caller thread’s message queue.

DispatchMessage directs the OS to call the Windows Procedure of appropriate target window.

Two doubts:

1)What is the exact functionality of TranslateMessage;is it just to translate virtual keystrokes to character messages(I assume virtual keystrokes to be keystrokes other than alphabets and numbers),if character message is posted back to queue,isn’t the loop broken?

2)What about the mouse events?are they directly dispatched?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:45:55+00:00Added an answer on June 11, 2026 at 7:45 pm

    Yes, it doesn’t make sense that you would have to call TranslateMessage() when your message loop looks like that. But that’s not what the canonical Petzold message loop looks like:

    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    

    Accelerators are what matters here, otherwise known as “short-cut keys”. Your program wants to respond to them regardless of which window has the focus. Like F1 shows the program’s help file, regardless which control has the focus. You don’t want to have to write code that subclasses every control window to recognize F1.

    So if it is a short-cut key then you don’t want to call TranslateMessage. The key should not produce a WM_CHAR message if the key happens to match a typing key. Which is why it is a separate call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So for some reason this just doesn't make sense to me. What Im trying
So, I'm trying to make sense of WCF in general, and this MSDN chat
Pulling my hair out trying to make sense of this stuff. Situation: 1. User
I've been trying to make this work for a while and it never seems
After trying to make sense of the Metrics and Grids page of the (fairly
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to make a simple number clicker control for BlackBerry 6/7, like this: At
I'm trying to make sense of the CSS float property, and I understand the
I'm trying to make sense on the best way to do automatize a series
I'm trying to make sense of a situation I have using entity framework on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.