DoEvents() in VC++???

How can I do a DoEvents() -like in VB- in VC++ / MFC?
Thanks!
Mainebound
[90 byte] By [mainebound] at [2007-11-18 3:12:42]
# 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);
}
Gabriel Fleseriu at 2007-11-11 3:47:41 >
# 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:
maheshperumal at 2007-11-11 3:48:39 >
# 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.
CBasicNet at 2007-11-11 3:49:45 >
# 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.
Gabriel Fleseriu at 2007-11-11 3:50:41 >
# 6 Re: DoEvents() in VC++???
Thanks a lot.
mainebound at 2007-11-11 3:51:51 >
# 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).
Sam Hobbs at 2007-11-11 3:52:44 >
# 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
mainebound at 2007-11-11 3:53:48 >
# 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.
Gabriel Fleseriu at 2007-11-11 3:54:46 >
# 10 Re: DoEvents() in VC++???
thanks, Gabriel!
it is what I needed!

Mainebound
mainebound at 2007-11-11 3:55:51 >