• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 936
  • Last Modified:

showing a dialog by using FindWindowEX

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
furmiga
Asked:
furmiga
  • 2
1 Solution
 
LMuadDIbCommented:
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
 
LMuadDIbCommented:
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
 
furmigaAuthor Commented:
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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now