Click here to Skip to main content
15,896,154 members

MFC and modal message boxes.

dlavrantonis asked:

Open original thread
Hello to everyone,

This thing is driving me crazy for the past days, so i would appreciate any insight.

Im writing an MFC dialogue application in VS2008.

In simple words im doing the following.

I have a function that is a member of the *dlg class (lets call it MyAppDlg::PostMessageToDB()).

I have created a timer and an MyAppDlg::onTimer() handler method that gets called whenever the timer ticks.

I have also created an MSMQ COM object and have registered its "Arrived" event with the MyAppDlg::newMessage() function. This function gets called when a new message arrives in the MSMQ queue.

Both these functions call the PostMessageToDB() function.

If theres an error (e.g. no connectivity with the DB) the PostMessageToDB() function pops an error message by calling the AfxMessageBox( errorMsg, MB_RETRYCANCEL |MB_ICONERROR| MB_SYSTEMMODAL); method.

This method is modal. The execution of the PostMessageToDB() function freezes and my application does not continue until the user hits the retry (or cancel) button.

So far so good.

BUT while waiting for a user response, if the timer ticks again or a new message arrives, my application gets woken up! The corresponding functions are called and it seems like a new "instance" of my program starts its execution flow. The result is to reach again at the same error and pop another error message.

How can this ever be possible?
Is anywhere there a hidden thread involved?
What will happen if i press the retry button while another "instance" of the above flow is on its way?

To what i know, the new event (timer tick or new message in the queue) shouldn't be dispatched before my application completes the processing of the previous message and returns. That's how the windows message loop works right?

I guess i miss the basics of the MFC architecture. If you know a link to a tutorial/article that can help me understand the above behavior i would be grateful!
Tags: C++, MFC, MessageBox

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900