Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Click a button in another program!!

Posted on 2000-02-19
4
Medium Priority
?
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 90 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

650 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