loop problem

Started by
4 comments, last by Doc 19 years, 7 months ago
I know this is the 3rd post about loop problems but this one is different from the others , I was given examples of how to run a loop even when there arent any messages being sent to a window , but I have a small problem, I wanted the loop to show how many times it was being run but in this code it only shows that the loop runs thru once , I'm trying to make it continuously run until the application has finished


    BOOL isRunning = true;    
    int timer = 0;
    char lc[21];


    while(isRunning)
    {
    
    timer++;    
    itoa(timer,lc,20);
    SetWindowText(hEdit,lc);    
    
    if(messages.message == WM_QUIT)
      {
       MessageBox(NULL,"isRunning set to false","Info",MB_OK);
       isRunning = false;
       PostQuitMessage(0);
      }
    
    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);

    }    
    }

Advertisement
Because the loop loops around in the inner while.

while (GetMessage (&messages, NULL, 0, 0))


"Follow the white rabbit."
I changed it to an "if" loop , but now my controls arent being displayed until i touch the window , damn
Try writing out a pseudo code translation of your code, carefully working through it and see whats happening.

If you are more the hands on type, print it out and use a pencil.

If that still is not for you, try setting a break point and stepping through the code.

What better way to learn these skills then with a snippet such as this?

- Jacob
"1 is equal to 2 for significantly large quantities of 1" - Anonymous
thanks , I figured it out , well i didnt , I juss made a WM_PAINT and painted some other stuff , and now it works right , thanks for the advice
Perhaps you should lookup PeekMessage (IIRC). It'll check to see if a message is waiting or not, and will tell you right away, unlike GetMessage which waits for a message before returning.

I think. HTH
My stuff.Shameless promotion: FreePop: The GPL god-sim.

This topic is closed to new replies.

Advertisement