App loses focus in MDI when going to modal form

I am using VB5 and have created an MDI app. There are some instances where I call a form modally, and then call another modal form from the first modal form. When I close the second form and then the first, the app loses focus. Or if the modal form is loaded and then a MessageBox is invoked, when closing the modal form, the app also loses focus. This doesnt occur when only the first modal form is loaded and then closed.
Please advise.

Arnie
quicdocAsked:
Who is Participating?
 
mcriderConnect With a Mentor Commented:
As mentioned in the microsoft article, "Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Basic 6.0."

You can lock the screen before you set focus and unlock it after you set focus.  This will eliminate some of the flicker...
 
Declare the following in a MODULE:

   Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
   Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Long) As Long


Then in your program, before you setfocus, do this:

   LockWindowUpdate GetDesktopWindow

and after you setfocus, do this:

   DoEvents
   LockWindowUpdate 0&

This will reduce the flicker...


Cheers!
0
 
mcriderCommented:
See this:

FIX: Focus Doesn't Return to MDI Form After Modal Form Is Closed
http://support.microsoft.com/support/kb/articles/Q177/1/63.ASP?LNG=ENG&SA=MSDN 
 

Cheers!
0
 
quicdocAuthor Commented:
Sorry, but I didnt mention that I have tried doing a SetFocus after the Form.Show Modal line. But this results in a lot of flicker and if another app is opened, seeing it flash up before focus is set to my app. Is there a better work-around that reduces this flickering behavior.

Arnie
0
 
quicdocAuthor Commented:
Thanks
0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
All Courses

From novice to tech pro — start learning today.