Solved

Detecting A Pop-Up Error Message

Posted on 2003-11-23
4
368 Views
Last Modified: 2013-11-28
I don't think what I want to do is possible, but I'll ask anyway.

If your Delphi program ShellExecutes another exe file and the ShellExecuted file generates a messagebox with an error in it, (something it only does if there is an error), is there any way *your* program can detect this happening and access the message text in the messagebox.

The messagebox window that appears has the title 'Error', a short text message and a single OK button on it.

Thanks...

TDK_Man
0
Comment
Question by:tdk_man
  • 2
  • 2
4 Comments
 
LVL 1

Author Comment

by:tdk_man
ID: 9807030
I have now managed to detect the error pop-up box and have the handle of that window.

Is there any way now for me to be able to access the message text in the window currently on screen?

TDK_Man
0
 
LVL 1

Accepted Solution

by:
hacibumbala earned 300 total points
ID: 9807133
Below is not a very reliable solution but it may help:

function GetMsgText: String;
var
  hwndParent, hwndChild: HWND;
  nSize: Integer;
begin
  hwndParent := FindWindow(nil, 'Error');
  if hwndParent = 0 then Exit;
  hwndChild := FindWindowEx(hwndParent, 0, nil, nil); // OK Button
  hwndChild := FindWindowEx(hwndParent, hwndChild, nil, nil); // Label we want.
  nSize := GetWindowTextLength(hwndChild);
  SetLength(Result, nSize);
  GetWindowText(hwndChild, PChar(Result), nSize + 1);
end;
0
 
LVL 1

Author Comment

by:tdk_man
ID: 9807380
Thank you so much - that seems to work beautifully. :)

I'd managed to get as far getting the OK from the OK button, but the rest would have taken me forever!

Have some points...

TDK_Man
0
 
LVL 1

Expert Comment

by:hacibumbala
ID: 9807532
No problem! Thank you for the points.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
Learn about the eCommerce marketing trends for the year ahead.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

867 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

20 Experts available now in Live!

Get 1:1 Help Now