Results 1 to 6 of 6

Thread: Ignoreing queued messages

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Ignoreing queued messages

    In my program i have a function that takes a couple of seconds to finish. In this time the user can click on my window. My code for the user's click gets excecuted immediatly after my function is finished.
    Is there a way of getting the MsgProc function to ignore any messages sent when my other function was being excecuted?
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    At the end of your function, you can use PeekMessage to clear the queue. But beware of falling into an infinite loop, not all messages really get removed, esp. not WM_PAINT (if the user covered up your app while the function was executing).


    A better solution would be to disable your window during the lengthy function. Call EnableWindow, passing FALSE.

    Yet better, if circumstances allow, would be to start another thread to do the lengthy operation and allow your main windows to be fully functional and responsive during that.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Originally posted by CornedBee
    Yet better, if circumstances allow, would be to start another thread to do the lengthy operation and allow your main windows to be fully functional and responsive during that.
    Thanks for the suggestions.

    [edit]
    As a temporary solution i used EnableWindow, but it still seems to recieve the messages (they get handled by my code once my function has finished). Any ideas why this is (do i have to use peekmessage)?
    [/edit]

    I did think about doing that, but i have no idea how to get started. I searched for examples of multithreading, but didn't get anything that wasn't over my head.

    Basically what i'd need to do is have the window responding to simple things like WM_MOVE and all the usuals so the user didn't think it'd crashed. Then when my function finished it'd return a value which i'd then use for my program to continue normally.
    Are there any web-pages or anything that can point me in the right direction?
    Last edited by SLH; Feb 19th, 2004 at 03:24 PM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  4. #4

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    I've tried using PeekMessage, but just can't get it to work, here's the code:
    Code:
    ZeroMemory(&tmpmsg,sizeof(tmpmsg));
            while(tmpmsg.message != WM_QUIT)
                if(!PeekMessage(&tmpmsg,NULL,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE))
                    break;
    The wierd thing is that it works when i put a breakpoint on 'break;'
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I told you, you have to be careful.
    Code:
    MSG tmpmsg;
    BOOL b = TRUE;
    ZeroMemory(&tmpmsg,sizeof(tmpmsg));
    while(b && tmpmsg.message != WM_QUIT && tmpmsg.message != WM_PAINT) {
        b = PeekMessage(&tmpmsg,NULL,0,0,PM_REMOVE);
    }
    This will completly clear the message queue, except for WM_PAINT messages, which cannot be cleared.


    And the EnableWindow thing is really weird. It shouldn't happen.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Thanks for the help i tried your solution and it works perfectly.

    By putting in WM_MOUSEFIRST/LAST i thought peekmessage would only get mouse-based messages + WM_QUIT (and so i wouldn't keep reading the WM_PRINT message, is this not the case?

    EDIT: I swapped WM_MOUSEFIRST and WM_MOUSELAST and it works now. Trust the min parameter of peekmessage to be the larger of the two....
    Last edited by SLH; Feb 20th, 2004 at 07:13 AM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width