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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
mcriderCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
quicdocAuthor Commented:
Thanks
0
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.