How can I do a DoEvents() -like in VB- in VC++ / MFC?
Thanks!
Mainebound
Printable View
How can I do a DoEvents() -like in VB- in VC++ / MFC?
Thanks!
Mainebound
what DoEvents() does?
Basically like this:
Code:MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
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:rolleyes:
MFC or VC programs doesn't need to have DoEvents() as in VB. So there is no equivalent for VC.Quote:
Originally posted by mainebound
How can I do a DoEvents() -like in VB- in VC++ / MFC?
Thanks!
Mainebound
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.
Thanks a lot.
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.
Yes, I understand what you mean?
I guess using threads is what I really need.
anyway I have a question:
will
ensure UI responsivity, as Gabriel has pointed?Code:
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
I thank you all veru much.
Mainebound
Open a new dialog based MFC project. Place a button on the dialog and code this as a handler:
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.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);
}
thanks, Gabriel!
it is what I needed!
Mainebound