Mark Achrin
Mark Achrin

Reputation: 367

Get Window Handle of Window Under Cursor

I'm wondering if getting the window handle of a window underneath the cursor's current position is possible in c++. I'm working on a screenshot program that can take partial screenshots and I think that a feature where you are able to take a screenshot of a window by pressing a hotkey when your cursor is over that window would be useful feature. Any ideas?

Upvotes: 6

Views: 13354

Answers (2)

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145429

The function you're looking for is WindowFromPoint.

Upvotes: 12

Ross Bush
Ross Bush

Reputation: 15185

The following works:

   POINT P;
   HWND Handle;

   GetCursorPos(&P);

   Handle=WindowFromPoint(P);

Upvotes: 19

Related Questions