Solved

How to make a window handle picker ?

Posted on 2000-02-16
7
252 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 91
Pressing cancel button with C# UI Automation 3 51
Tab names are off by one 5 53
Message not shown 5 30
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 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

21 Experts available now in Live!

Get 1:1 Help Now