|
-
March 5th, 2003, 09:05 AM
#1
DoEvents() in VC++?????
How can I do a DoEvents() -like in VB- in VC++ / MFC?
Thanks!
Mainebound
-
March 5th, 2003, 09:07 AM
#2
-
March 5th, 2003, 09:22 AM
#3
Basically like this:
Code:
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
-
March 5th, 2003, 09:45 AM
#4
It allows the OS to process the messages waiting in the messg queue
I think there is no function or MFC for this in VC++ 6.0 (I suppose it is there in VC++ 7 as DoEvents())... You can use AfxBeginThread to do your work as a separate thread allowing the os to process other messages....
Mahesh
-
March 5th, 2003, 10:01 AM
#5
Re: DoEvents() in VC++?????
Originally posted by mainebound
How can I do a DoEvents() -like in VB- in VC++ / MFC?
Thanks!
Mainebound
MFC or VC programs doesn't need to have DoEvents() as in VB. So there is no equivalent for VC.
-
March 5th, 2003, 10:08 AM
#6
You can place a message pump in lengthy operations to ensure the UI responsivity. That is what DoEvents() is for in VB. I gave a basic example in my previous post. An alternative is to start a worker thread.
-
March 5th, 2003, 11:22 AM
#7
-
March 6th, 2003, 04:12 AM
#8
Probably you don't need a DoEvents equivalent; probably there is a better solution but wince you don't ask how to solve the problem you are trying to solve using DoEvents we can't provide a better answer. However the MFC documentation of idle-time processing has a sample loop that is an official version of the one that Gabriel provided. I think the link I have in my web site will get you there so see my Idle-time Processing.
-
March 6th, 2003, 07:13 AM
#9
Yes, I understand what you mean?
I guess using threads is what I really need.
anyway I have a question:
will
Code:
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
ensure UI responsivity, as Gabriel has pointed?
I thank you all veru much.
Mainebound
-
March 6th, 2003, 07:36 AM
#10
Open a new dialog based MFC project. Place a button on the dialog and code this as a handler:
Code:
void CYourDlg::OnButton1()
{
for(int i=0; i<0x100; ++i){
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
for(int j=0; j<10; ++j){
Sleep(10);
}
}
AfxMessageBox("Ready", MB_OK, 0);
}
Run the program and push the button. You will notice that you will be able to drag the dialog around, to push other buttons and so on. After about 16 seconds the message box "Ready" will appear.
-
March 6th, 2003, 07:39 AM
#11
thanks, Gabriel!
it is what I needed!
Mainebound
Last edited by mainebound; March 6th, 2003 at 07:45 AM.
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
|