Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Closing while in DoEvents causes exception

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 59
HOW D I CLEAR PICTURES IN IMAGE CONTROL AND COMMENTS IN CELLS WHEN WORKBOOK IS OPENED 18 103
MsgBox 4 68
Export Data to Different .csv Files 26 114
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
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…

808 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