Send to WND

Top  Previous  Next

!**************************************

! Name: My SendToWnd Function

! Description:This will speed up your project if you use a lot of API, This function will send any message to the window you specify in the paremeters.

! By: Andrew Downing

!

! Inputs:window classnames "Depth" message wideparam loparam.

!

! Returns:Boolean

!

! Assumes:this speeds up and simplifies finding a window that has a window of the same classname on the same level by using the "Depth" paramater.

!

!This code is copyrighted and has! limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=975&lngWId=7!for details.!**************************************

 

Function SendtoWnd(Parent,Child:pchar; ChildDepth:integer; SubChild:pchar; SubChildDepth:integer; Msg:Cardinal; wParam,lParam:integer):boolean;

var

parentwin,childwin,subchildwin: HWND;

i: integer;

begin

parentwin := 0;

childwin := 0;

subchildwin := 0;

if not ((subchild = '') and (child = '')) then begin

parentwin := FindWindow(parent,nil);

childwin := FindWindowEx(parentwin,0,child,nil);

for i := 1 to ChildDepth - 1 do begin

childwin := FindWindowEx(parentwin,childwin,child,nil);

end;

Subchildwin := FindWindowEx(childwin,0,subchild,nil);

for i := 1 to SubChildDepth -1 do begin

subchildwin := FindWindowEx(childwin,subchildwin,subchild,nil);

end;

if SendMessage(subchildwin,msg,wparam,lparam) > 0 then

result := true

else

result := false;

end;

if (subchild = '') and not(child = '') then begin

parentwin := FindWindow(parent,nil);

childwin := FindWindowEx(parentwin,0,child,nil);

for i := 1 to ChildDepth - 1 do begin

childwin := FindWindowEx(parentwin,childwin,child,nil);

end;

if SendMessage(childwin,msg,wparam,lparam) > 0 then

result := true

else

result := false;

end;

if (child = '') and (subchild = '') then begin

parentwin := FindWindow(parent,nil);

if SendMessage(parentwin,msg,wparam,lparam) > 0 then

result := true

else

result := false;

end;

end;

Here is an example where this could be useful, sending a message to an aim chatroom, the parent has 2 childwindows of the same class:

SendtoWnd('Aim_Chatwnd','Wndate32class',2,'ate32class',1,WM_SETTEXT,0,integer(Text));

SendtoWnd('Aim_Chatwnd','Wndate32class',2,'ate32class',1,WM_KEYDOWN,13,0);