Solved

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

Posted on 2006-11-16
9
251 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:rrbecker
  • 6
  • 3
9 Comments
 
LVL 10

Accepted Solution

by:
fostejo earned 500 total points
Comment Utility
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
 
LVL 2

Author Comment

by:rrbecker
Comment Utility
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
 
LVL 10

Expert Comment

by:fostejo
Comment Utility
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
 
LVL 2

Author Comment

by:rrbecker
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 2

Author Comment

by:rrbecker
Comment Utility
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
 
LVL 2

Author Comment

by:rrbecker
Comment Utility
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
 
LVL 10

Expert Comment

by:fostejo
Comment Utility
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
 
LVL 2

Author Comment

by:rrbecker
Comment Utility
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
 
LVL 2

Author Comment

by:rrbecker
Comment Utility
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now