-
Feb 19th, 2004, 10:32 AM
#1
Thread Starter
Not NoteMe
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.
-
Feb 19th, 2004, 03:05 PM
#2
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.
-
Feb 19th, 2004, 03:19 PM
#3
Thread Starter
Not NoteMe
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.
-
Feb 19th, 2004, 09:08 PM
#4
Thread Starter
Not NoteMe
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.
-
Feb 20th, 2004, 05:20 AM
#5
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.
-
Feb 20th, 2004, 07:08 AM
#6
Thread Starter
Not NoteMe
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|