Sign in to follow this  

loop problem

This topic is 4843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

    }    
    }

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this