How does ::MessageBox(...) work??
-
Hey all. I'm not a newbie to Windows programming or multi-threading, but I've been wondering: how exactly does the implementation of ::MessageBox(...) work? I have a simple single-threaded application. I call ::MessageBox(...) somewhere in the code. The message box APPEARS to be blocking the code execution, since the line after the "::MessageBox(...)" will only be executed after the message box is dismissed. However, my single-threaded application is still processing messages! How is this magic performed behind the scenes? Thanks!
-
Hey all. I'm not a newbie to Windows programming or multi-threading, but I've been wondering: how exactly does the implementation of ::MessageBox(...) work? I have a simple single-threaded application. I call ::MessageBox(...) somewhere in the code. The message box APPEARS to be blocking the code execution, since the line after the "::MessageBox(...)" will only be executed after the message box is dismissed. However, my single-threaded application is still processing messages! How is this magic performed behind the scenes? Thanks!
Probably because your message loop continues to process messages such as WM_PAINT. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
-
Hey all. I'm not a newbie to Windows programming or multi-threading, but I've been wondering: how exactly does the implementation of ::MessageBox(...) work? I have a simple single-threaded application. I call ::MessageBox(...) somewhere in the code. The message box APPEARS to be blocking the code execution, since the line after the "::MessageBox(...)" will only be executed after the message box is dismissed. However, my single-threaded application is still processing messages! How is this magic performed behind the scenes? Thanks!
-
Hey all. I'm not a newbie to Windows programming or multi-threading, but I've been wondering: how exactly does the implementation of ::MessageBox(...) work? I have a simple single-threaded application. I call ::MessageBox(...) somewhere in the code. The message box APPEARS to be blocking the code execution, since the line after the "::MessageBox(...)" will only be executed after the message box is dismissed. However, my single-threaded application is still processing messages! How is this magic performed behind the scenes? Thanks!
When a MessageBox is invoked, the parent window is disabled. Thus it cannot take mouse clicks or keyboard hits, BUT it can handle all messages sent or posted to it directly like the paint messages. When the MessageBox is dismissed the parent window is re-enabled! Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
-
Probably because your message loop continues to process messages such as WM_PAINT. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Actually, Cristian (and correct me if im wrong) but i dont see how yr message loop can be working if yr appliaction has called message box... I think this is VERY good question for beginners like us. Im sure that messagebox domodal, etc. call a hoorrible nasty "PeekAndPump" type MS fudge. Any corrections? Dave Carkeet.
-
Actually, Cristian (and correct me if im wrong) but i dont see how yr message loop can be working if yr appliaction has called message box... I think this is VERY good question for beginners like us. Im sure that messagebox domodal, etc. call a hoorrible nasty "PeekAndPump" type MS fudge. Any corrections? Dave Carkeet.
David Carkeet wrote: Im sure that messagebox domodal, etc. call a hoorrible nasty "PeekAndPump" type MS fudge. Actually, from memory it sets a flag for the app so that the window stops responding, but the message pump keeps right on pumping. I think Nish said something similar, he may know more about it than I do. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
-
David Carkeet wrote: Im sure that messagebox domodal, etc. call a hoorrible nasty "PeekAndPump" type MS fudge. Actually, from memory it sets a flag for the app so that the window stops responding, but the message pump keeps right on pumping. I think Nish said something similar, he may know more about it than I do. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
MessageBox is just a function which displays a particular dialog box, which a few bells and whistles. From the documentation of ::DialogBox () in the Platform SDK: "The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style), disables the owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box." So, the function has its own message loop. It will also retrieve messages for the rest of your application (e.g. WM_PAINT) and dispatch them to the appropriate handler. The MFC glue routes it eventually to your routine (such as CView::OnDraw (...)). Enlightened? Iain.