Solved

How to make a window handle picker ?

Posted on 2000-02-16
7
285 Views
Last Modified: 2013-11-20
How must I proceed to make a window handle picker like the window handle picker in Spy++ (CTRL-F). The window were you can drag a symbole to the window you want to get the handle from.

Thanks for answer.
Mike

P.S. : Sample code will be very nice.
0
Comment
Question by:mike_marquet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
ScottyDawg earned 50 total points
ID: 2526363
Use the function WindowFromPoint(...) which given a CPoint object will return the CWnd* at that position - but remember the returned CWnd* may be tempory so call GetSafeHwnd() on it.

Also, because you want to recieve mouse input from outside of your own window (during the drag bit), use the SetCapture() and ReleaseCapture() functions. Hope this helps :)
0
 

Author Comment

by:mike_marquet
ID: 2526665
Thanks. But did you have a sample ?

No need of windows hooks ?
0
 

Author Comment

by:mike_marquet
ID: 2527091
I have try it and the Capture works but when I call WindowFromPoint(...)
in my mouse move message, it doesn't work fine.
The handle received is not correct.

Here's some sample (CWindowHandlePickerDlg is derived from CDialog) :

void CWindowHandlePickerDlg::OnLButtonDown(UINT nFlags, CPoint point)
 {
  CDialog::OnLButtonDown(nFlags, point);

  m_bLeftMouseButtonDown = TRUE;

  SetCapture();
 }

void CWindowHandlePickerDlg::OnLButtonUp(UINT nFlags, CPoint point)
 {
  CDialog::OnLButtonUp(nFlags, point);

  m_bLeftMouseButtonDown = FALSE;

  ReleaseCapture();
 }

void CWindowHandlePickerDlg::OnMouseMove(UINT nFlags, CPoint point)
 {
  CDialog::OnMouseMove(nFlags, point);

  if (!m_bLeftMouseButtonDown) return;

  CWnd *pWnd = WindowFromPoint(point);

  if (pWnd)
   {
    CString  str;

    str.Format("HEX : %X", pWnd->GetSafeHwnd());
   
    SetDlgItemText(IDST_WINDOWHANDLE, str);
   }
  else SetDlgItemText(IDST_WINDOWHANDLE, "");
 }
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2527147
What exactly isn't working?
0
 

Author Comment

by:mike_marquet
ID: 2527262
Sorry, I have found.

Forgotten to call ClientToScreen before calling WindowsFromPoint.
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2527272
ah good. Also you if the window is hidden or diabled you will need to use ChildWindowFromPoint().
0
 

Author Comment

by:mike_marquet
ID: 2527615
Ok, thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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