Solved

Click a button in another program!!

Posted on 2000-02-19
4
229 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now