Link to home
Start Free TrialLog in
Avatar of Rick Becker
Rick BeckerFlag for United States of America

asked on

Problem With Custom MsgBox - Looses Focus even though it is displayed as Modal

Hi All,

I have created a custom MsgBox (OCX) with help from articles found here on EE. It seems to work ok except that it seems to loose focus at times which forces me to click the 'OK' button twice to get it to respond. Please note that this does NOT happen in all cases.

If someone is willing to help I will be more that happy to post my code. Please reply if you can help.

Thanks in advance

rrbecker
ASKER CERTIFIED SOLUTION
Avatar of fostejo
fostejo

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 Rick Becker

ASKER

Hi fostejo

Thanks for the quick reply. Your answer sounds reasonable, however I quess I am not familiar with the difference so I'll do some additional research on 'Application' vs 'System' modal.

Thanks, I'll get back after I find out how to implement 'System' modal.

rrbecker

P.S. If you could offer advice I would be greatful
Avatar of fostejo
fostejo

rrbecker,

You don't mention which language or custom MsgBox you're using... but.. whether to display a standard MsgBox in System Modal mode or not is generally controlled by the flags specified on Msgbox line.  In VB6 for instance, a standard Msgbox with 'critical error' icon and just an 'OK' button would look something like this:

MsgBox "An error has occurred!", vbOkOnly+vbCritical, "Error!"

By default, this would produce an Application modal dialog, to make it a System modal dialog you'd need:

MsgBox "An error has occurred!", vbOkOnly+vbCritical+VbSystemModal, "Error!"

Hope that helps..
Hi fostejo

Seems I am not having much luck finding information on how to make a form 'System Modal'. All I have found is information on the 16bit SystemMakeModal API.

Can you help with how to do this with VB6 (32bit)?

Thanks

rrbecker
Hi fostejo

...."By default, this would produce an Application modal dialog, to make it a System modal dialog you'd need:

MsgBox "An error has occurred!", vbOkOnly+vbCritical+VbSystemModal, "Error!"...."


Sorry, I was digging for information and did not refresh my screen.

The MsgBox is one that I created from sample code provided by other here on EE. I wanted one that I could customize to maintain the 'Look and Feel' of my main application. The custom message box implements some but not all of the features of the Miscrosoft MsgBox. The VbSystemModal parameter is one that has not been implemented.

How do I go about adding VbSystemModal to my application?

rrbecker

BTW the OCX and my main application are all done in VB6
Hi fostejo

I don't think there is a 'Good' solution to my problem unless I am willing to throw out my custom Message Box. The System Modal would be the solution in a 16bit environment but not for Win32.

The Next best thing would be to try to set up my Message Box so that it 'Always Has Focus' but so far I am unsuccessful in that attempt as well.

I am going to award you the points but if you could help me with the 'Always Has Focus' solution I would appreciate it.

Thanks for your help

rrbecker
rrbecker,

Thanks - as you allude to, the whole 'system modal' behaviour really goes against the concept of a 'proper' multi-tasking environment; the following TID gives some background to this: http://support.microsoft.com/?kbid=147817

As far as your dialog 'always having focus', I'd image a very simplistic (and therefore no doubt potentially troublesome!) way would be simply use SetFocus to grab back focus to the dialog/form that's loosing it..  this could potentially be done via a controls 'validate' or 'lostfocus' events.

Another way could be to use a timer to keep activating the appropriate form/dialog frequently until the user 'answers' it.

However, both are crude and are likely to introduce unexpected issues, so if you do choose to investigate them further please tread carefully   ;)

cheers
Hi fostejo

Thanks for your Tips.

I really don't like Timers, although there are places where I have used them. (They really 'burn up' CPU cycles.)

As for the SetFocus trick, I've tried it in 'LostFocus' but have not tried 'Validate' so I guess I'll try that.

For the most part my Custom Message Box works well except when I generate a message for a DBGrid control that I am using. I have a dropdown box of numbers accociated with a 'Cell' in the grid and whenever and 'Error' is generated due to an error in the dropdown, Focus is pulled away from my message box causing me to click twice. Once to regain focus and once to 'close' (OK) the message box.

Anyway thanks for all your help

rrbecker
Hey fostejo

I JUST FIXED IT.......

There is an option in the 'User Control' call ForwardFocus. It was set to False, I set it to True and now It is working as expected. (oh silly me...)


Again Thanks for all your help

rrbecker