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
LVL 2
rrbeckerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
fostejoConnect With a Mentor Commented:
rrbecker,

It sounds like the MsgBox is being shown in 'Application' modal as opposed to 'System' modal - therefore, if any other application pinches focus your application (and therefore the MsgBox) will loose focus..

The easiest solution would be to ensure that the MsgBox is System Modal..

cheers,
0
 
rrbeckerAuthor Commented:
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
0
 
fostejoCommented:
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..
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rrbeckerAuthor Commented:
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
0
 
rrbeckerAuthor Commented:
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
0
 
rrbeckerAuthor Commented:
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
0
 
fostejoCommented:
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
0
 
rrbeckerAuthor Commented:
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
0
 
rrbeckerAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.