[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Click a button in another program!!

I've got a working exe that runs ok. What i want to do is to click a button in the exe via my own program. How do i do that ?
0
drnadeem
Asked:
drnadeem
1 Solution
 
MadshiCommented:
Find the button window handle (e.g. with FindWindow(Ex)), then use PostMessage(WM_KEYDOWN, ...) and PostMessage(WM_KEYUP, ...) to simulate key presses.

Regards, Madshi.
0
 
ZifNabCommented:
look at the source on this component how to do it exactly (or just use the component) :-)

http://www.delphipages.com/edit/count.cfm?comID=453&Link=uploads%2FMiscellaneous%2FMUMacro1%2Ezip 

Regards, Zif
0
 
drnadeemAuthor Commented:
Wasn't able to download/visit to your page by double clicking it.
0
 
ahalyaCommented:
Here is an example form an answer I preovided earlier.  This code starts the "Network" control panel applet and clicks the "Add" button.



uses ShellAPI:

var hIns : THandle;

begin;
hIns := ShellExecute(0, nil,
            'rundll32.exe',
            'shell32.dll,Control_RunDLL netcpl.cpl',
             nil,
             SW_SHOW);
WaitForSingleObject(hIns, 10 *1000);

repeat
    h := FindWindow('#32770', 'Network');
    if h = 0 then sleep(10);
until h <> 0;

DlgID := 209; //for Add button
PostMessage(h, wm_Command, DlgID, MakeLong(h, BN_Clicked));

=============

You can write a similar routine. You'll need to know the className & WindowTitle of the parent application, and the button. In pseudo-code your procedure will look like.

var h, hc : HWND;
      DlgID : integer;

begin;
h := FindWindow('ClassName', 'WindowTitle');
hc := FindWindowEx(h, 0, 'TButton', 'Button Title');
DlgID := GetDlgCtrlID(hc);
PostMessage(h, wm_Command, DlgID, MakeLong(h, BN_Clicked));
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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