Solved

Detecting A Pop-Up Error Message

Posted on 2003-11-23
4
367 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This story has been written with permission from the scammed victim, a valued client of mine – identity protected by request.
Read about why website design really matters in today's demanding market.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

744 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

11 Experts available now in Live!

Get 1:1 Help Now