Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • 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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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