Mark Achrin
Mark Achrin

Reputation: 357

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: 5

Views: 13300

Answers (2)

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

Reputation: 145204

The function you're looking for is WindowFromPoint.

Upvotes: 11

Ross Bush
Ross Bush

Reputation: 15155

The following works:

   POINT P;
   HWND Handle;

   GetCursorPos(&P);

   Handle=WindowFromPoint(P);

Upvotes: 18

Related Questions