Solved

showing a dialog by using FindWindowEX

Posted on 2006-06-11
3
843 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

822 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