?
Solved

How to make a window handle picker ?

Posted on 2000-02-16
7
Medium Priority
?
295 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 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 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