I spent a lot of time trying to find out why "Message Box'
made my program act like it crashed. Originally I had to
bring up the Task Manager every time I allowed "Message
Box' to run to shut down the program. After much
experimentation I found that if I hit the "Alt" key,
the MB would show on the screen. "OK"ing the MB allowed
my program to proceed normally. All along I suspected
a focus problem but since MB is a black box, I had no
idea what was happening. By pure chance, I put a little
TextOut code snippet into the function. I do this to
see what's going on inside functions quite a bit. With
these four lines of code, MB started working normally.
This is exactly the same solution to the SetTimer
problem I had posted a thread about in this site a week
or so back. It bothers me that I need a BeginPaint and
EndPaint entry to prevent strange things from happening
in my programs. I can force things to work right with
a fudge but that's not right. I'd sure like one of you
experts to tell me why this is occurring. I'm
running AMD with SP1. Compiling with either "cl" or
BCC55 gives me the same results. I'll include a small
program with the code in it so you can compile and
test to see what I'm talking about.

Well I thought I made it fairly clear in your previous thread TBH.

The timer doesn't work without the paint code in MyTimerFunc() because you don't handle WM_PAINT, so the window is not validated and the high frequency (and priority) of WM_PAINT messages blocks the low priority WM_TIMER message.
Just handle WM_PAINT as suggested and your timer will work without the misplaced painting.
I don't understand why you were getting crashes when calling MessageBox() however.

I do now understand why you were getting crashes with MessageBox() though - you weren't! It wasn't crashing at all, just unable to display the box due to app spending all it's time servicing WM_PAINT.
You must service WM_PAINT to validate the window, if you don't you will get little else done. Just do yourself a favour and add this to MainWndProc():

case WM_PAINT:
      {
         PAINTSTRUCT ps;
         HDC hdc;
         hdc = BeginPaint(hwndMainFrame, &ps);
         // Do your painting
         EndPaint(hwndMainFrame, &ps);
         return 0L;
      }

OK, I'll try that. When you explained it to me in the timer thread, I thought you were suggesting that I leave the paint code right at the timer code. I'll try your suggestion now and put it in the paint case.

Just to let everyone know. The suggestion works great. That was my problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.