Solved

Message box appears behind form !??

Posted on 2002-07-30
13
1,049 Views
Last Modified: 2007-12-19
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
Comment
Question by:JDN
  • 4
  • 2
  • 2
  • +4
13 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7187605
please show, how you show it
0
 
LVL 1

Author Comment

by:JDN
ID: 7187636
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
 
LVL 17

Assisted Solution

by:geobul
geobul earned 25 total points
ID: 7187915
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
 
LVL 6

Accepted Solution

by:
swift99 earned 25 total points
ID: 7189057
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
 
LVL 1

Author Comment

by:JDN
ID: 7189806
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
 
LVL 4

Expert Comment

by:jsweby
ID: 7190200
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:jsweby
ID: 7190201
Oh yeah, and use the MB_TASKMODAL flag.

J.
0
 
LVL 17

Expert Comment

by:geobul
ID: 7190277
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
 

Expert Comment

by:CleanupPing
ID: 9342971
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
 
LVL 17

Expert Comment

by:geobul
ID: 9361522
I do care :-)
There was no complaint of my proposal, so I presume it solved the problem.
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9966114
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
 
LVL 6

Expert Comment

by:swift99
ID: 9966461
I say give the points to geobul.  I only had an observation, not a solution.
0
 
LVL 17

Expert Comment

by:geobul
ID: 9970531
swift99, I'm not sure whether JDN has tried my way at all :-)

My proposal: Split the points
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

17 Experts available now in Live!

Get 1:1 Help Now