Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How does ::MessageBox(...) work??

How does ::MessageBox(...) work??

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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!

    C L N 3 Replies Last reply
    0
    • L Lost User

      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!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • L Lost User

        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!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I think it creates a mode dialog,and show it by DoModal(),so only if you press OK or Cancel,the following codes will be executed. Cheers

        1 Reply Last reply
        0
        • L Lost User

          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!

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0
          • C Christian Graus

            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

            D Offline
            D Offline
            David Carkeet
            wrote on last edited by
            #5

            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.

            C 1 Reply Last reply
            0
            • D David 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.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              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

              I 1 Reply Last reply
              0
              • C Christian Graus

                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

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups