Solved

Click a button in another program!!

Posted on 2000-02-19
4
239 Views
Last Modified: 2011-09-20
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
Comment
Question by:drnadeem
4 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 2537793
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 2538180
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
 
LVL 1

Author Comment

by:drnadeem
ID: 2539201
Wasn't able to download/visit to your page by double clicking it.
0
 
LVL 7

Accepted Solution

by:
ahalya earned 30 total points
ID: 2563800
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question