Link to home
Start Free TrialLog in
Avatar of tlchavet
tlchavet

asked on

Msgbox Causes VB App to Lose Focus

I have a VB6 app that uses msgboxes to provide information to the user like "Process Complete".  For some users, these msgboxes cause the VB app to lose focus and they have to alt-tab back.  Is there a way to stop this from happening?
SOLUTION
Avatar of edwardiii
edwardiii

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tlchavet
tlchavet

ASKER

The code before and after varies and not every user experiences the problem.  Will a form1.setfocus trigger any events other than form_setfocus?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To be sure I am understanding both responses, whether I use the standard msgbox or the function MessageBox, to ensure the focus stays in my app I should use the form1.setfocus?
Setting focus just brings focus back to the application. Actually the msgbox itself should be doing that, yet
even doing a better job at it. Clicking the okay button on the msgbox should force your application back
in front of other windows too, which the setting focus will NOT.

The point of using MessageBox is just to allow your application to continue running. Instead of freezing
like the normal command button does.
The reason I do set focus with MessageBox is because I am giving it a false Hwnd, so it is not attached to my program.
That means that when you click okay it will not return to the program. Setting focus will force it to do that. I do not
know that setfocus will help in the case of "msgbox" but you can try it and see. Truthfully, I do not understand why the
msgbox you have currently is not returning focus to the application upon pressing okay.