Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Handler of a mdi child window 1

Status
Not open for further replies.

tolemac

Programmer
May 4, 2003
8
RO
Hi !
Here is my problem...
I want to send some messages to a child window from a MDI application. To do this I need the handler of that child window. I've tried to use FindWindow, but FindWindow is searching only through top level windows. I have the name of the MDI application and the name of the child window from that application. What I need is the handler of the child window to send it some messages.

Can anyone help me with some ideas and maybe some code examples?

Thanks.
 
Hi Tolemac
You can scan all open child forms like

var
Loop : integer;

begin
for Loop := 0 to ChildCount - 1 do begin
if Children[Loop] is TMessageForm then begin
PostMessage(Children[Loop].Handle, ..)
or TMessageForm(Children[Loop]).AProperty := NewValue;

end;
end;
end;
 
Hi,

use Findwindow to find top level window of the MDI app and use that handle in the FindwindowEx API function to search it's child windows. Just to give you a small example how to do this :

hwnd_TOP:=Findwindow(PChar(Appname),nil); // look for APP
if hwndTOP <> 0 then
begin
hwnd_MDI:=FindWindowEx(hwnd_TOP,0,PChar(STR_MDICLIENT),nil); // get mdiclient window area
if hwnd_MDI <> 0 then
begin
hwnd_CH:=FindWindowEx(hwnd_MDI,0,PChar(STR_WFCHANNEL),nil); // find a channel window
if hwnd_CH <> 0 then
begin
SendMessage(hwnd_CH,WM_SYSCOMMAND,SC_MAXIMIZE,0); // send maximize system command , this will maximize all channel windows
end;
end;

I use this code in a to maximize a certain MDI window in a certain app. Just use Winsight or Spy++ to find the names of the windows you want to manipulate.

greetings,

 
Hi,
For what I need to do, whosrdaddy's solution is the best one. Thanks whosrdaddy.
Anyway mikca thanks for trying to help me.

I have one more question. Now that I have the child window handle, how can I get its position on the screen? I want to send a mouse click event somewhere in that window and I need the window's coordinates.
 
Hi again!
I have found a solution to my problem. I've used GetWindowPlacement API function to get the location of the window.

I've did something like this:

var appPl,chPl:TWindowPlacement;
appRect,chRect:TRect;
winX, winY:Integer;
...

appPl.length:=SizeOf(TWindowPlacement);
GetWindowPlacement(hwnd_TOP,@appPl);
appRect:=appPl.rcNormalPosition;

chPl.length:=SizeOf(TWindowPlacement);
GetWindowPlacement(hwnd_CH,@chPl);
chRect:=chPl.rcNormalPosition;

winX:=appRect.Left+chRect.Left;
winY:=appRect.Top+chRect.Top;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top