Calling (Afx)MessageBox in OnDraw

Viewed 83

Let's say OnDraw calls a drawing function that calls AfxMessageBox:

void CmyprojectView::OnDraw(CDC* pDC) 
{
    myDraw(pDC);
}

myDraw(CDC* pDC)
{
    // some code...

    AfxMessageBox(_T("First MessageBox"));

    // some code after the first AfxMessageBox...



    AfxMessageBox(_T("Second MessageBox"));

    // some code after the second AfxMessageBox...

}

As far as I know, OnDraw is called whenever AfxMessageBox is called.

Then what happens after the first AfxMessageBox gets called? The myDraw runs again, and calls the first AfxMessageBox again? But if we run the above code, it executes as if a normal sequential flow (I think actually it's not, but it "looks like" that) - the first message box pops up, and if I hit 'ok', then the second message box pops up.

As mentioned in this answer by Ajay, when MessageBox is called, it's sent to the message loop, and the thread (that was running myDraw) processes other stuff. So, is the code after the first message box not executed before I click the 'ok' button in the message box?

Also, I'm confused about what happens when the second AfxMessageBox is called. OnDraw gets called again...? Then, when is the code after the second message box executed?

Please enlighten me with this message loop stuff :)

EDIT) Some context: I used AfxMessageBox in a function which is called by OnDraw just for debugging purpose (showing some values). But then I found that it triggers some strange behaviour and I noticed the execution flow is not simple. So I wondered what's going on. (This is just for learning, not for real application)

0 Answers
Related