Page 1 of 1

how to get handle of a control in a window?

PostPosted: August 29th, 2005, 9:00 am
by Sina
HI
does anyone know how to get handle of a control in a window by hovering mouse on it?
I can get some of them but for e.g i cannot get handle of edit boxes of yahoo messenger login box using mouse!
But i have gotten their handles using findwindowex
thnk you
bye

PostPosted: August 29th, 2005, 4:56 pm
by Kambiz
Did you try WindowFromPoint?

It dosn't work

PostPosted: September 2nd, 2005, 6:51 am
by Sina
Hi
thanks for your codes
I try windowfrompoint and also ChildWindowFromPoint but I
can't get the handle of text boxes of yahoo messenger yet
Please help me
Thank you
Goodbye

PostPosted: September 2nd, 2005, 9:38 am
by Kambiz
Yahoo Messenger doesn't use the Windows controls, and the edit boxes and check boxes in the Login dialog box of Yahoo messenger don't have a hanlde. Also, the two group like controls in this dialog are actually button control not a group box!

NO NO!

PostPosted: September 3rd, 2005, 7:32 am
by Sina
Hi
but mr kambiz I have VC++ code that does it
The code attached to this message
I want to know how does it work?
thank you
bye

PostPosted: September 4th, 2005, 3:09 pm
by Kambiz
My spy gave me wrong information, and because of that I gave you incorrect information, sorry! :oops:

Here is the code for getting the proper window at the specified screen point:

Code: Select all
function WindowAtPt(const Pt: TPoint): HWND;
type
  TChildInfo = record
    ChildWnd: HWND;
    ChildRect: TRect;
  end;
var
  WndPoint: HWND;
  WndChild: HWND;
  NextChildWnd: HWND;
  Rect: TRect;
  CPt: TPoint;
  ChildList: array of TChildInfo;
  MinNbrPixel: Integer;
  NbrPixel: Integer;
  I: Integer;
begin
  WndPoint := WindowFromPoint(Pt);
  CPt := Pt;
  ScreenToClient(WndPoint, CPt);
  WndChild := ChildWindowFromPointEx(WndPoint, CPt, CWP_ALL);
  if WndChild = 0 then
    Result := WndPoint
  else if not IsChild(GetParent(WndChild), WndChild) then
    Result := WndChild
  else
  begin
    NextChildWnd  := GetWindow(WndChild, GW_HWNDFIRST);
    while NextChildWnd <> 0 do
    begin
      GetWindowRect(NextChildWnd, Rect);
      if PtInRect(Rect, Pt) then
      begin
        SetLength(ChildList, Length(ChildList) + 1);
        with ChildList[Length(ChildList) - 1] do
        begin
          ChildWnd := NextChildWnd;
          ChildRect := Rect;
        end;
      end;
      NextChildWnd := GetWindow(NextChildWnd, GW_HWNDNEXT);
    end;
    if Length(ChildList) > 0 then
    begin
      WndChild := ChildList[0].ChildWnd;
      MinNbrPixel := GetSystemMetrics(SM_CXFULLSCREEN) * GetSystemMetrics(SM_CYFULLSCREEN);
      for I := 0 to Length(ChildList) - 1 do
      begin
        with ChildList[I].ChildRect do
          NbrPixel := (Right - Left) * (Bottom - Top);
        if NbrPixel < MinNbrPixel then
        begin
          MinNbrPixel := NbrPixel;
          WndChild := ChildList[I].ChildWnd;
        end;
      end;
      SetLength(ChildList, 0);
      Result := WndChild;
    end
    else
      Result := 0;
  end;
end;

By the way, the code is from the application you've attached in your last post, which I translated it to Delphi.

Greetings

Thanks

PostPosted: September 5th, 2005, 5:51 am
by Sina
Thank you Dear MR.Kambiz .
I'm realy pleased!
I tryed to translate the code myself but I couldn't.
Thanks a lot.
Bye
===================================
Sina FK