how to get handle of a control in a window?

Please discuss general Delphi programming topics here.

how to get handle of a control in a window?

Postby Sina » August 29th, 2005, 9:00 am

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
User avatar
Sina
Junior Member
Junior Member
 
Posts: 32
Joined: August 29th, 2005, 8:33 am
Location: United States

Postby Kambiz » August 29th, 2005, 4:56 pm

Did you try WindowFromPoint?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

It dosn't work

Postby Sina » September 2nd, 2005, 6:51 am

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
User avatar
Sina
Junior Member
Junior Member
 
Posts: 32
Joined: August 29th, 2005, 8:33 am
Location: United States

Postby Kambiz » September 2nd, 2005, 9:38 am

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!
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

NO NO!

Postby Sina » September 3rd, 2005, 7:32 am

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
Attachments
WindowHandlePicker_demo.zip
(55.2 KiB) Downloaded 132 times
User avatar
Sina
Junior Member
Junior Member
 
Posts: 32
Joined: August 29th, 2005, 8:33 am
Location: United States

Postby Kambiz » September 4th, 2005, 3:09 pm

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
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Thanks

Postby Sina » September 5th, 2005, 5:51 am

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
User avatar
Sina
Junior Member
Junior Member
 
Posts: 32
Joined: August 29th, 2005, 8:33 am
Location: United States


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron