Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Closing while in DoEvents causes exception

Posted on 1998-10-29
4
Medium Priority
?
221 Views
Last Modified: 2010-04-30
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
 
0
Comment
Question by:skin
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
AllenC_Jr earned 600 total points
ID: 1442430
Add A property to the Active-X Control that would inform the Form that it is in a Paint Loop.

'Convert the VB-Code to VC-Code
Put this In the Form_Unload Event of the form
Private Sub Form_Unload()
Do While ActiveX.InLoop
DoEvents
Loop
End Sub

This is A Possibility...

If this doesn't work then Reject the Answer
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1442431
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
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1442432
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
0
 

Author Comment

by:skin
ID: 1442433
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question