Ideas:
Use Windows API functions to traverse the window, find the specified window title, then look OK from the window, sending a message to simulate a mouse click on this button. Since IE8 by the title of the page Alert pop-up dialog box is the "message from the web page", while the title IE6 Alert dialog pop-up pages is "Microsoft Internet Explorer", so this does not get the window handle to press the Find window title method. It notes that the class name which version, IE window is "IEFrame", while the parent window of the dialog page regardless of IE is the IE window, so this is a class name of the parent window is not a window is not to judge IEFrame Web Page dialog box, the following code click on the page pop-up Alert dialog box and Confirm "OK" button, and displays a message box with the content of the page Label1 control:
achieve:
TForm1.Button1Click Procedure (Sender: TObject);
var
HIE, hDlg, hBtn, hStatic: the HWND;
the Text: Array [0..255] of char;
the begin
hDlg: = the GetWindow (the Handle, GW_HWNDFIRST);
the While hDlg <> 0 do
the begin
HIE: = GetParent (hDlg);
IF the GetClassName (HIE, the Text, 255)> 0 the then // Get the parent window class name
if Text = 'IEFrame' then // IE window parent window is
the begin
hBtn: = hDlg the FindWindowEx (, 0, nil, 'OK'); // Check OK button
IF hBtn <> 0 the then
the begin
hStatic: = the FindWindowEx (hDlg, 0, 'the Static', nil);
hStatic: = the FindWindowEx (hDlg, hStatic, 'the Static', nil);
IF the GetWindowText (hStatic, the Text,255) > 0 then
Label1.Caption: = the Text;
Sleep (100);
the SendMessage (hBtn, $ 00F5, 0, 0); // first focus acquisition Click OK
Sleep (100);
the SendMessage (hBtn, $ 00F5, 0, 0 ); // second click to hit the OK button
End;
End;
hDlg: = GetWindow (hDlg, GW_HWNDNEXT);
End;
End;
Bowen link: https://blog.csdn.net/diligentcat/article/details/17242739