EnumWindows, EnumChildWindows를 이용해서 단추를 찾고 Click하는 방법을 사용하고
있네요... ^^
function EnumChildProc( phWnd : hWnd; poCaptions : TStrings ) : Boolean; stdcall;
var
szFull : array[ 0..MAX_PATH ] of Char;
begin
Result := phWnd <> 0;
if Result = TRUE then
begin
GetWindowText( phWnd, szFull, SizeOf( szFull ) );
if ( Pos( poCaptions[ 0 ], String( szFull ) ) > 0 ) AND
( poCaptions.IndexOfObject( TOBject( phWnd ) ) < 0 ) then
poCaptions.AddObject( String( szFull ), TObject( phWnd ) );
EnumChildWindows( phWnd, @EnumChildProc, LongInt( poCaptions ) );
end;
end;
function ClickButton( ParentWindow : Hwnd; ButtonCaption : String ) : Boolean;
var
lhWnd : hWnd;
loCaptions : TStringList;
begin
loCaptions := TStringList.Create;
try
loCaptions.AddObject( ButtonCaption, nil );
EnumChildWindows( ParentWindow, @EnumChildProc, LongInt( loCaptions ) );
lhWnd := 0;
case loCaptions.Count of
1 : ShowMessage( 'Window text not found.' );
2 : lhWnd := hWnd( loCaptions.Objects[ 1 ] );
else
ShowMessage( 'Ambiguous text detected.' );
end;
finally
loCaptions.Free;
end;
Result := lhWnd <> 0;
if Result then
PostMessage( lhWnd, BM_CLICK, 0, 0 );
end;
|