Solved

Message box appears behind form !??

Posted on 2002-07-30
13
1,063 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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