Thread: Forcing MessageBox to be non-concurrent?

  1. #16
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    This is quite bizarre.

    My (total) guess is that the MessageBox is failing the first time the errror is triggered. If the exit call is present that's it. If the exit call is not present the error is retriggered and the message box comes up on the second attempt.

    If that is the case, the question remains why MessageBox is failing.

    I hope we get an answer for this thread as it is rather bewildering.

    Calling MessageBox in WM_PAINT may mean you are running out of gdi object as assumably each MessageBox would trigger more WM_PAINT messages and so on. Maybe it could also be a stack overflow as each message box would trigger another.

    Just guessing!

  2. #17
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I like the stack overflow theory. That could hold water if he uses a lot of local variables. One way that could be tested is to change a few large declarations to dynamic memory for the moment.

    Although a stack overflow is more likely to throw up an exception dialog than to just quit.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #18
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I have solved the problem.

    Stupid me. After my last post, I made the program purposely NOT quit within the fatal error function, so I could see what is happening (I tried this before, but not what I did next:) Then, I placed a static variable to count the number of times the if statement that checks for the fatal error is triggered. I call the fatal error message only if this count is 1. If it is not 1, it displays another message box with the count. When I ran the program, I see a SINGLE message box with a count of 40. I close this, and see one with a count of 39. Then close that, I see 38... and so on. Each time, I see ONLY ONE message box. They are NOT covering each other, since subsequent message boxes are displayed lower and to the right of the previous. The rest are apparently not shown until the ones made after it are uncovered. If I close them all but the first, I can see my properly displayed fatal error message in the middle of the screen. Because of each subsequent message box being displayed lower/to the right, the 40th one is pushed as far low and to the right as it can get. This was always the case right from the start - the (ONLY) message box I could ever see was always in this peculiar position - in the bottom-right corner of the screen. I should have known what was causing this. But, I just never guessed the rest were being hidden.

    In any case, I removed the code that displays the count, and I only call the fatal error function if the count = 1, and I placed the exit function back in within this function. The function properly waits for a key to be pressed.

    I can only assume that the tons of message boxes being created are the cause of some of them NOT having any title text, and also the cause of the program just crashing outright, without waiting for the user to close any of them. I still do not like that this happened, but I am not about to attempt to make a program create 100's of message boxes just to see what Windows does with them. This is obviously abnormal behaviour.

    As a final excuse for my stupidity, this code is not actually in the WM_PAINT message, but rather in a user created message. WM_PAINT can trigger this user created message when the client area size does not match the current drawn bitmap size (meaning the user changed the window size, and the bitmap needs to be re-drawn to match this size. Yes, this can happen even without a WM_MOVE - when you maximize/restore, I believe - so I need to check this within WM_PAINT, not just WM_MOVE), and thus requires the bitmap to be re-drawn, thus calling my own message to do so. WM_PAINT merely draws the bitmap to the screen. I should have realized the continuous error trapping while the message box is being displayed before the program finally terminates.

    Thank you all for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MessageBox, changing text.
    By XunTric in forum Windows Programming
    Replies: 8
    Last Post: 01-16-2006, 09:09 AM
  2. Delete files that are used
    By Yuri in forum C++ Programming
    Replies: 8
    Last Post: 10-18-2005, 01:48 PM
  3. problem with A simple modeless messagebox
    By hanhao in forum C++ Programming
    Replies: 8
    Last Post: 07-05-2005, 11:18 PM
  4. EnterCriticalSection and MessageBox
    By novacain in forum Windows Programming
    Replies: 13
    Last Post: 01-30-2003, 08:48 AM
  5. double in a MessageBox
    By Robert602 in forum Windows Programming
    Replies: 3
    Last Post: 12-17-2001, 03:10 PM