1 頁 (共 1 頁)

delphi scan win

發表於 : 2021年 6月 22日, 23:34
leeyc
procedure TForm1.Timer1Timer(Sender: TObject);
var p:tpoint;
c:array[0..254]of char;
s:array[0..254] of char;
hWindow, ButtonHandle:HWND;
lpRect: TRect;
pt: TPoint;
LParam : Integer;
begin
getcursorpos(p);
caption:=inttostr(windowfrompoint(P));
getclassname(strtoint(caption),c,255);
SendMessage(windowfrompoint(P), WM_GetText, 255, integer(@s[0]));
edit2.Text:=s;
edit1.Text:=c;
// PChar('Taiwan Legal Disclaimer') Taiwan Legal Disclaimer
//hWindow := FindWindow(nil, PChar('Diablo II'));
hWindow := FindWindow('Diablo II', nil);
SetForegroundWindow(hWindow);
hWindow := FindWindow(nil, 'Taiwan Legal Disclaimer');
SetForegroundWindow(hWindow);
ButtonHandle := FindWindowEx(hWindow, 0, 'Button', '是(&Y)');
SetForegroundWindow(ButtonHandle);
GetWindowRect(ButtonHandle, lpRect);
edit2.Text := Format('%d,%d',[lpRect.Left,lpRect.Top]);
GetCursorPos(pt);
edit1.Text:= floattostr(pt.X) + ' ' + floattostr(pt.Y);
SetCursorPos(lpRect.Left+30, lpRect.Top+30);
sleep(500);
GetCursorPos(pt);
edit1.Text:= floattostr(pt.X) + ' ' + floattostr(pt.Y);
LParam := MakeLong(lpRect.Left+30, lpRect.Top+30);
PostMessageA(ButtonHandle, WM_LBUTTONDOWN, MK_LBUTTON, LParam);
PostMessage(ButtonHandle, WM_LBUTTONUP, MK_LBUTTON, LParam);
// SendMessage(hButton, BM_CLICK, 0, 0);
//ShowWindow(hWindow,SW_SHOW);
end;