Link to home
Start Free TrialLog in
Avatar of skin
skin

asked on

Closing while in DoEvents causes exception

I'm a VC programmer that used VB to create a control to embed in my MFC MDI Application.  I am getting an unhandled exception when I close my MFC application while my VB control is in a paint loop.  I have a DoEvents in the loop, which, if I remove, prevents the exception from occuring but then I can't process other messages.  
My question is:  Is there some way to do the equivalent of an ::AfxLockApp() in VB?  I think the rug is getting pulled out from underneath my control while it's in this paint loop.  I just want to lock things down while it's in this paint loop so it can't go away until it finishes.
Thanks in advance
 
ASKER CERTIFIED SOLUTION
Avatar of AllenC_Jr
AllenC_Jr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use this one.... LockWindowUpdate(HWND) to lock the update and after you've finished the painting use the LockWindowUpdate(0) to unlock it and allow updating of thw window..

Hope this helps

Cheers,
Viktor
Also if you want to close while in DoEvents you could do this...

//some loop is going one here....
//you want to close the window so you use this...
break 'breaks the loop
close 'close your window and so on,,,
//rest of code...

Regards,
Viktor Ivanov
Avatar of skin
skin

ASKER

As it turns out, it doesn't appear the exception is due to the DoEvents.  I have yet to figure out what is causing it.  Thanks for the suggestions AllenC and Viktornet