Solved

showing a dialog by using FindWindowEX

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now