DoEvents() in VC++???
How can I do a DoEvents() -like in VB- in VC++ / MFC?
Thanks!
Mainebound
# 1 Re: DoEvents() in VC++???
what DoEvents() does?
Alin at 2007-11-11 3:46:36 >

# 2 Re: DoEvents() in VC++???
Basically like this:
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
# 3 Re: DoEvents() in VC++???
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:
# 4 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.
# 5 Re: DoEvents() in VC++???
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.
# 6 Re: DoEvents() in VC++???
Thanks a lot.
# 7 Re: DoEvents() in VC++???
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 (http://simplesamples.info/OnIdle.asp).
# 8 Re: DoEvents() in VC++???
Yes, I understand what you mean?
I guess using threads is what I really need.
anyway I have a question:
will
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
# 9 Re: DoEvents() in VC++???
Open a new dialog based MFC project. Place a button on the dialog and code this as a handler:
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.
# 10 Re: DoEvents() in VC++???
thanks, Gabriel!
it is what I needed!
Mainebound