Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Messagebox appearing at the back of form window. 2

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
i have a program that will show message after doing a task. I've used message box. The problem i am encountering is every time the messages box appears, its located at the back of my form window when timeout is put. How do i display messagebox with timeout to appear at forefront? thanks,,,,
 
Hi Mandy,

The VFP documentation on MESSAGEBOX is incomplete - MB_SYSTEMMODAL 4096 is missing:

Code:
*-- MessageBox parameters
#DEFINE MB_OK                      0    && OK button only
#DEFINE MB_OKCANCEL                1    && OK and Cancel buttons
#DEFINE MB_ABORTRETRYIGNORE        2    && Abort, Retry, and Ignore buttons
#DEFINE MB_YESNOCANCEL             3    && Yes, No, and Cancel buttons
#DEFINE MB_YESNO                   4    && Yes and No buttons
#DEFINE MB_RETRYCANCEL             5    && Retry and Cancel buttons

#DEFINE MB_ICONSTOP               16    && Critical message
#DEFINE MB_ICONQUESTION           32    && Warning query
#DEFINE MB_ICONEXCLAMATION        48    && Warning message
#DEFINE MB_ICONINFORMATION        64    && Information message

#DEFINE MB_DEFBUTTON1              0    && First button is default
#DEFINE MB_DEFBUTTON2            256    && Second button is default
#DEFINE MB_DEFBUTTON3            512    && Third button is default
[b]#DEFINE MB_SYSTEMMODAL          4096    && System Modal[/b]

*-- MsgBox return values
#DEFINE IDOK            1       && OK button pressed
#DEFINE IDCANCEL        2       && Cancel button pressed
#DEFINE IDABORT         3       && Abort button pressed
#DEFINE IDRETRY         4       && Retry button pressed
#DEFINE IDIGNORE        5       && Ignore button pressed
#DEFINE IDYES           6       && Yes button pressed
#DEFINE IDNO            7       && No button pressed

Therefore, you need to add it as in the example: MESSAGEBOX("Hello World", MB_YESNO + MB_SYSTEMMODAL, "My Message", 3000)
 
You shouldn't need SystemModal for a messagebox and, in fact, you shouldn't ever use SystemModal, since that puts the messagebox on top of every application, not just yours.

@Mandy_CRW, are you saying you only have this problem if you specify a timeout for your messagebox? This discussion may be helpful to you:
Tamar
 
Sorry Tamar, but I disagree. There are many cases where it is warranted (or even required). In critical cases, the LAST thing you want is a MESSAGEBOX displayed behind a form - you want to talk about angry and confused customers? VFP does not support MB_APPLMODAL which is the "Application" modal message box, so this is all we have got.
 
Vernspace,

Regardless of the rights and wrong of using the SystemModal setting (I happen to agree with Tamar on this point, but let's not go into that), I don't see how it would make any difference in this case. In fact, I can't see any way that the messagebox can appear behind other forms, regardless of the SystemModal setting.

I think a more problematical issue is the use of a timeout in a messagebox, which is something I would always discourage for several reasons.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
In fact, I think it is the timeout parameter that is causing this problem.

When a messagebox has a timeout parameter, the messagebox appears as a separate button on the taskbar. If the user then clicks anywhere else within the application, the application's main window will become activated. The messagebox will then appear behind the main window, which is probably the behaviour that the OP is seeing here.

Mandy, you can check this for yourself quite simply by removing the timeout. Let us know what happens.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

One more reason to make use of Cesar's Messagebox. A little gem.
I remeber years ago I had to make an application for referees in a billiards game. We all know that in the billiards room is absolute silence in order not to interfere with the players concentration.
It took me more than a day to find the messagebox functions without the 'beep', finaly I than wrote myMessagebox function.
Today, not only to avoid the annoying beep, we can use Cesar's messagebox function, allowing yoour own icons, an email option, etc. etc.

Stay healthy,

Koen
 
hi Mike.... yes mike, as i put the timeout, it displays the messagebox behind the form... but i really want the messagebox to have time out... so that's my problem really... how could i display the message box forefront even with timeout.... thanks everyone....
 
Mandy,

If you really want the timeout, you have several choices:

1. Create your own message box. This would be a simple modal form that contains the text, icons and buttons that you want. You can add a timer to make it time out after a given number of seconds. This will avoid the problem that you are seeing.

2. Use Cesar's message box, as recommended by Koen and others (see above).

3. Use a Wait Window instead of a message box. It is not so prominent, but it is easy to implement, and the timeout won't cause any additional problems.

Now having said that, I must ask if you really need a timeout. There are several reasons not to use a timeout with the built-in message box:

1. The fact that the message box has its own taskbar button, which could lead to the message appearing behind other parts of your application, giving the user the impression that the application is hanging. (I assume this is what you are seeing.)

2. This sort of message box prevents any timers elsewhere in your application from firing. If you don't have any timers, it won't be a problem. But, if you do, it could cause significant problems.

3. Most important: it is a lousy user interface feature. Just think about that. You are giving your users a message to read. They start reading the message, but suddenly and without any warning the message disappears from the screen, possibly before they have finished reading it or absorbing its meaning. Is that a friendly way to communicate with your users?

Just something for you to think about.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you so much Mike... it's now working... i've used system modal.... thanks vernpace... god bess everyone....
 
Hallo Mandy,

I run into such Problems years ago.

So I decided to use a form instead of the build in messagebox.

I give it the Parameters and a return variable.

Sometimes I use the build in messagebox but most of the time I use my own form because the user needs more information or more options to choose from.

It is not so complicated to write such a form with all controls you will need.

hth

harald
 
Thanks, vernspace, I didn't know this works and also tried MB_TASKMODAL:

Code:
#DEFINE MB_TASKMODAL 8192 && Task Modal

MESSAGEBOX("Hello World", MB_TASKMODAL , "My Message", 3000)

This only disables windows of your own task.

Chriss
 
Chris,

Please, I am not trying to be the wise guy, but what is the use of a #DEFINE in this case?
Code:
MESSAGEBOX("Hello World", 8192 , "My Message", 3000)
works just as fine.
In my opinion you are making simple things just a little bit more complicated.
Kindly give me a reason for this #DEFINE

Stay healthy,

Koen
 
See vernspaces post above, he also made several constant definitions.

"Magic Numbers" doing something are not documenting what the code means and does.

Chriss
 
Koen,

I fully agree with Chris and Vernspace. That said, using #DEFINE in this way is completely optional. There is a definite benefit in doing so, but I can also see your point about it adding complexity. Just do what you find comfortable.

If you do put 8192 rather than MB_TASKMODAL as the second parameter, I suggest you add a comment to indicate that the message box is task modal (or system modal, or whatever).

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top