Solved

Closing while in DoEvents causes exception

Posted on 1998-10-29
4
214 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
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change the path of the data source in my Excel pivot table with macro 4 43
using web browser with BING 40 120
MsgBox 4 61
Publisher:   Unknown     VB.exe Application 1 21
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

773 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