Solved

Message box appears behind form !??

Posted on 2002-07-30
13
1,056 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

23 Experts available now in Live!

Get 1:1 Help Now