Solved

showing a dialog by using FindWindowEX

Posted on 2006-06-11
3
852 Views
Last Modified: 2012-05-07
First of all... srry about the points. This is all I have :(

2 apps

the first app have:

Form Title: "my 1st app"
dialog name: "my dialog 1" (dialogEx)

the second app have a button "call the dialog from app 1"

now...

In app 2 I want to find the app1 handle and its dialog handle and then open the dialog from the app2.

is that possible ?

wnd := FindWindow(nil, 'my 1st app');
wnd := FindWindowEx(wnd, 0, '????????',nil); < -- I really don't know how it works
...


ty in advance

0
Comment
Question by:furmiga
  • 2
3 Comments
 
LVL 4

Expert Comment

by:LMuadDIb
ID: 16882915
procedure TForm1.Button1Click(Sender: TObject);
var
  h,openDialog:hwnd;
begin
  h := FindWindow(nil,'my 1st app');
  if h <> 0 then begin// if we found notepad
    openDialog := FindWindowEx(h, 0, 'TButton', nil);
    sendmessage(openDialog,WM_LButtonDown,0,0);
    sendmessage(openDialog,WM_LButtonUp,0,0);
  end else
    ShowMessage('not found.');
end;

If you had a button on your first app that would open a dialog than you can simulate the buttonclick, shown above.
I dont know if its possible to open a dialog window without using a menuitem/button/action or similiar control.

Syntax:}

  FindWindowEx(Parent: HWND;  {a handle to a parent window}
               Child: HWND;  {a handle to a child window}
               ClassName: PChar;  {a pointer to a null-terminated class name string}
               WindowName: PChar  {a pointer to a null-terminated window name string}
               ): HWND;  {returns a handle to a window}
0
 
LVL 4

Accepted Solution

by:
LMuadDIb earned 50 total points
ID: 16882969
here is some code to find like the second tbutton and click that button:

function FindControlByNumber(hApp: HWND; ControlClassName: string; ControlNr: Word = 1): HWND;

....

procedure TForm1.Button1Click(Sender: TObject);
var
  h,openDialog:hwnd;
begin
  h := FindWindow(nil,'my 1st app');
  if h <> 0 then begin// if we found notepad
    openDialog := FindControlByNumber(h, 'tbutton', 2);
    sendmessage(openDialog,WM_LButtonDown,0,0);
    sendmessage(openDialog,WM_LButtonUp,0,0);
  end else
    ShowMessage('not found.');
end;

function FindControlByNumber(hApp: HWND; ControlClassName: string; ControlNr: Word = 1): HWND;
var
  i: Word;
  hControl: HWND;
begin
  Result := 0;
  if IsWindow(hApp) then
  begin
    Dec(ControlNr);
    hControl := 0;
    for i := 0 to ControlNr do
    begin
      hControl := FindWindowEx(hApp, hControl, PChar(ControlClassName), nil);
      if hControl = 0 then
        Exit;
    end;
  end;
  Result := hControl;
end;
0
 
LVL 7

Author Comment

by:furmiga
ID: 16882978
Thats why i gave the name of the dialog "my dialog 1" wich is a EX dialog

I really don't know if I have to use the FindWindowEX since the Dialog is hidden and there is nothing phisical to open it ( I mean, if i start the program with a param -menu then the MainMenu is visible wich allow me to open the "my dialog 1" ).


Now, if I start the program without the param, is there any chance to open the main menu or just call the dialog ?.


They exist so I was wondering if i can force them to show
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

Suggested Solutions

Title # Comments Views Activity
When I am typing into a TEdit last word repeats 7 159
Delphi 2 77
Drag & Drop... Data from one grid to another 2 47
scroll down TListBox component in Delphi 1 31
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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