Share via

Is there anything terrible would happen if I embed a message loop of a "child" window into the window procedure of a parent window?

Displame 21 Reputation points
2021-05-15T11:15:13.8+00:00

Hi All,

I'm new to Win32 GUI programming and have a question described following.

Things goes like this: I have successfully created and showed a window, FirstWnd, with a menu bar.
There's a button in the menu bar which creates another window ( Let's call it CildWnd for now. I set the hWndParent parameter of CreateWindow to be the handle of FirstWnd when create CildWnd ) in the window procedure of FirstWnd. At the same place, the message loop of CildWnd is entered.

My code runs well. When CildWnd is created and showed, FirstWnd is still able to process message. But shouldn't it be blocked? After all, the message loop of CildWnd in its window procedure is still looping!

It's possible that my program is so simple that nothing goes wrong with such coding style.

Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

0 comments No comments

Answer accepted by question author
  1. RLWA32 52,366 Reputation points
    2021-05-15T11:29:49.843+00:00

    I think you are confusing message loops with window procedures. In a simple example like yours, messages for all of the windows that are created by a thread are dispatched by a single message loop. The dispatched messages are routed by Windows to the window procedure for the related window.

    The parent and child windows have their own window procedures, and a single message loop dispatches messages to them.

    Read more at messages-and-message-queues

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.