[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1157
  • Last Modified:

Message box appears behind form !??

Hi Experts,

In my application a range of invoices can be printed. After the invoices are printed a message box (MessageDlg) pops up which indicates that the printing is ready.

Strange thing that sometimes happens on some pc's is that the message box won't be displayed on top of the form, but seems to be BEHIND the form.
I can see the printing is ready and that the program must have launched the message box; code before the message box is executed, code after the message box is not. The form of my program (an MDI-Child) however has focus instead of the message box. The form cannot be closed or moved; the whole program can't even be closed. The user can only quit the program using the Windows NT task manager.

I tried to change the MessageDlg message box to a ShowMessage message box, but the problem persists. The problem is difficult to trace because it doesn't occur always.

Can anyone tell me what could cause this behaviour? And is there a way to solve this?

Thanks,
JDN
0
JDN
Asked:
JDN
  • 4
  • 2
  • 2
  • +4
2 Solutions
 
kretzschmarCommented:
please show, how you show it
0
 
JDNAuthor Commented:
What? The message box?
I use this code:

MessageDlg('Invoices are printed.',mtInformation,[mbOK],0);

I changed the code to:

ShowMessage('Invoices are printed.');

But on some pc's the message box is sometimes not visible when launched. As I said, you can only quit the program with the Windows task manager.

JDN


0
 
geobulCommented:
Hi,

Try:
 
Windows.MessageBox(0,'Invoices are printed.', PChar(Application.Title), MB_OK or MB_ICONINFORMATION or MB_TASKMODAL);

Perhaps something is wrong with the window handles.

Regards, Geo
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
swift99Commented:
I have seen the same thing with some shrink wrapped packages (non-Delphi) on Windows NT 4 Service packs 3 and 6.  The problem is not endemic to Delphi, it appears to be a bug in Windows handling of modal dialogs.

I have found that I can normally use alt+tab to eventually bring the modal dialog to the foreground.
0
 
JDNAuthor Commented:
Swift99,

You may be right, because on the pc's with that problem the Microsoft Outlook message "You have new mail" also appears behind other screens. Normally this message box should appear on top of another screen.

I will try the Alt-Tab solution as soon as the problem occurs.

There's no other solution or bug-fix for this problem?
0
 
jswebyCommented:
I think geobul's suggestion is the right one, it's the one I use. The Windows MessageBox allows you to define the handle which will be the owner of the message box; I usually set this to either the current form's handle (Self.Handle) or the application's main form (Application.MainForm.Handle).

J.
0
 
jswebyCommented:
Oh yeah, and use the MB_TASKMODAL flag.

J.
0
 
geobulCommented:
Thanks, jsweby. You are right about the handles. I've left the handle zero because I suppose that it's the problem actually. Both MessageDlg and ShowMessage functions create a new form using Application as the owner and show that form in modal state.

JDN, you may also add 'or MB_SETFOREGROUND' to the flags, which should internally call SetForegroundWindow API for this message box.

Regards, Geo
0
 
CleanupPingCommented:
JDN:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
geobulCommented:
I do care :-)
There was no complaint of my proposal, so I presume it solved the problem.
0
 
snehanshuCommented:
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

Split between geobul and swift99

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer
0
 
swift99Commented:
I say give the points to geobul.  I only had an observation, not a solution.
0
 
geobulCommented:
swift99, I'm not sure whether JDN has tried my way at all :-)

My proposal: Split the points
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 4
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now