function FindWindowByTitle(WindowTitle: string): THandle;
Function WindowClassName(H:THandle):String;
Var
aName:array [0..255] of char;
begin
GetClassName(H,aName, 256);
Result:=aName;
end;
var
NextHandle: THandle;
NextTitle: array[0..260] of char;
begin
NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
while NextHandle > 0 do
begin
GetWindowText(NextHandle, NextTitle, 255);
if (Pos(WindowTitle, StrPas(NextTitle)) <> 0)
And (WindowClassName(NextHandle)<>'CabinetWClass') then
begin
Result := NextHandle;
Exit;
end
else
NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
end;
Result := 0;
end;
procedure ClickXY(X,Y:Word;LeftButton:Boolean=True);
var
Pnt : TPoint;
begin
Application.ProcessMessages;
Pnt.x := Round(X * (65535 / Screen.Width)) ;
Pnt.y := Round(Y * (65535 / Screen.Height)) ;
Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE, Pnt.x, Pnt.y, 0, 0) ;
If LeftButton=True then
Begin
Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LeftDOWN, Pnt.x, Pnt.y, 0, 0) ;
Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LeftUP, Pnt.x, Pnt.y, 0, 0) ;
End
Else
Begin
Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_RightDOWN, Pnt.x, Pnt.y, 0, 0) ;
Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_RightUP, Pnt.x, Pnt.y, 0, 0) ;
End;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
WindowRect, WindowClientRect: TRect;
Origin: TPoint;
Ofs: TPoint;
Handle:THandle;
begin
Handle:= FindWindowByTitle('Paint');
If Handle=0 then
Begin
ShowMessage('MsPaint is not Running!')
Exit;
End;
ForceForegroundWindow(Handle);
GetWindowRect(Handle,WindowRect);
ClickXY(WindowRect.Left+10,WindowRect.Top+50,True) ;
end;
وقتی MsPaint باز بود میتونید اجرا کنید.
کد باز کردن برنامه هم نوشتم خوب کار نکرد