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
Solved

Click a button on another Delphi app

Posted on 2002-06-26
5
304 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 Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 84
Delphi inherited method 6 75
Dynamically Created Query 3 62
Graphics32 under Delphi 10.1 Berlin 2 96
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

791 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