• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Send ButtonClick to another hidden/minimized app at a x/y location

hi, I would like to send a ButtonClick to another App which is hidden/minimized and will click at selected X/Y of the Apps window size.

could you please provide code examples.

Sal.
0
SaLz
Asked:
SaLz
  • 3
1 Solution
 
geobulCommented:
Hi,

Do you know the caption (text) of the button you want to click there? Or its name?

Regards, Geo
0
 
geobulCommented:
Hi,

The following works for minimized window and if there is a button at the specified coordinates:

function GetChildWindowAtPoint(MainHWND: HWND; X,Y: integer): HWND;
var
  h, h1: HWND;
  p: TPoint;
begin
  p.X := X;
  p.Y := Y;
  h := MainHWND;
  if IsWindow(h) then begin
    repeat
      h1 := ChildWindowFromPoint(h, p);
      if IsWindow(h1) then begin
        if h1 <> h then h := h1
        else break;
      end else break;
    until h1 <> 0;
  end;
  result := h;
end;

procedure TForm1.Button2Click(Sender: TObject);
var f,b: HWND;
begin
  f := FindWindow(nil, 'TargetForm'); // this is the title of the window
  if IsWindow(f) then begin
    b:= GetChildWindowAtPoint(f, 10, 10); // X and Y coordinates of the button to be clicked
    if IsWindow(b) then begin
      PostMessage(b, BM_CLICK, 0, 0);
    end else begin
      ShowMessage('Target button not found');
    end;
  end else begin
    ShowMessage('Target window not found');
  end;
end;

Regards, Geo
0
 
SaLzAuthor Commented:
sorry about that, had 2 go into hospital.
0
 
geobulCommented:
Sorry to hear that. I hope you're OK now? And thanks for the points :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now