Solved

Click a button on another Delphi app

Posted on 2002-06-26
5
306 Views
Last Modified: 2010-08-05
I have one Delphi application that launches another at a specified time. The 2nd app has a 'Start' button that I wish to simulate pressing after the application has loaded. I have seen an example similar to this on EE (but i can't find it) where Outlook was launched with a message and the 'Send' button was pressed after a delay.

Any idea's ?.
Thanks
Paul.
0
Comment
Question by:pr_wainwright
[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
5 Comments
 
LVL 1

Expert Comment

by:VENKAT
ID: 7112617
Sorry, I couldn't understand what u mean. Can u please brief what u need exactly? Thank you.
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 7112749
Sorry,
      Two Delphi applications running (A & B). Delphi application 'A' wants to 'Press' a button on Delphi application 'B' main form (execute button1.click; handler).

Hope this is a bit clearer.
Paul.
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 7112874
Send the proper WM_KEYDOWN/WM_KEYUP messages for the button's shortcut. Directly executing code from another app is impossible.
0
 
LVL 2

Accepted Solution

by:
Tasomia earned 100 total points
ID: 7112992
Hi

Try this code:

function EnumChildProc(Wnd: hWnd; SL: TStrings): BOOL; stdcall;
var
  szFull: array[0..MAX_PATH] of Char; //Buffer for window caption
begin
  Result := Wnd <> 0;
  if Result then  
  begin
    GetWindowText(Wnd, szFull, SizeOf(szFull)); // put window text in buffer
    if (Pos(SL[0], StrPas(szFull)) > 0) // Test for text
      and (SL.IndexOfObject(TObject(Wnd)) < 0) // Test for duplicate handles
      then SL.AddObject(StrPas(szFull), TObject(Wnd)); // Add item to list
    EnumChildWindows(Wnd, @EnumChildProc, Longint(SL)); //Recurse into child windows
  end;
end;

function ClickButton(ParentWindow: Hwnd; ButtonCaption: string): Boolean;
var
  SL: TStringList;
  H:  hWnd;
begin
  SL := TStringList.Create;
  try
    SL.AddObject(ButtonCaption, nil); // First item in list is text to find
    EnumChildWindows(ParentWindow, @EnumChildProc, Longint(SL));
    H := 0;
    case SL.Count of
      1: ShowMessage('Window text not found.');
      2: H := hWnd(SL.Objects[1]);
      else  
        ShowMessage('Ambiguous text detected.');
    end;
  finally
    SL.Free;
  end;
  Result := H <> 0;
  if Result then PostMessage(H, BM_CLICK, 0, 0);
end;

tas
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 7113106
Tasomia,
        Just what i was looking for.

Thanks
Paul.
0

Featured Post

Technology Partners: 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!

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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