Solved

Click a button on another Delphi app

Posted on 2002-06-26
5
297 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
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

18 Experts available now in Live!

Get 1:1 Help Now