Solved

How to make a window handle picker ?

Posted on 2000-02-16
7
243 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now