Solved

Closing while in DoEvents causes exception

Posted on 1998-10-29
4
212 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 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now