Solved

Click a button on another Delphi app

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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