Reputation: 3891
I have been trying to get the handle to a window though a device context handle. I've tried WindowFromDC() and its constantly returning null results. How can I get the window handle from any device context?
Upvotes: 2
Views: 7661
Reputation: 71
All people know how get the handle of DC but nobody know how retrieve the handle of the corresponding windows ?
Try this :
HWnd = WindowFromDC(HDc)
Ref: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-windowfromdc
Upvotes: 6
Reputation: 330
HDC hdc; // display device context handle
// Retrieve a handle identifying the private DC.
hdc = GetDC(hwnd);
http://msdn.microsoft.com/en-us/library/dd162744(v=vs.85).aspx
Upvotes: -2
Reputation: 808
Maybe there is no window belonging to this DC.
If no window is associated with the specified DC, the return value is NULL.
You could for instance create an offscreen bitmap (without window) and get a DC for it. Then this DC would have no window.
Upvotes: 3