forked from duilib/duilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.cpp
66 lines (58 loc) · 1.68 KB
/
Util.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "StdAfx.h"
#include "Util.h"
HBITMAP CreateDesktopBitmap(HWND hWnd)
{
HWND hWndDesktop = ::GetDesktopWindow();
RECT rect;
GetWindowRect(hWndDesktop, &rect);
rect.right -= rect.left;
rect.bottom -= rect.top;
rect.left = rect.top = 0;
HDC hDcDesktop = GetDC(hWndDesktop);
HDC hDcMem = CreateCompatibleDC(hDcDesktop);
HBITMAP hBmp = CreateCompatibleBitmap(hDcDesktop, rect.right, rect.bottom);
HGDIOBJ hOld = SelectObject(hDcMem, hBmp);
::BitBlt(hDcMem, 0, 0, rect.right, rect.bottom, hDcDesktop, 0, 0, SRCCOPY|CAPTUREBLT);
::ReleaseDC(hWndDesktop, hDcDesktop);
::DeleteDC(hDcMem);
return hBmp;
}
HBITMAP CreateDesktopMaskBitmap(HWND hWnd)
{
HDC hDCMem = CreateCompatibleDC(NULL);
RECT rect;
GetWindowRect(::GetDesktopWindow(), &rect);
rect.right -= rect.left;
rect.bottom -= rect.top;
rect.left = rect.top = 0;
HBITMAP hBmp = NULL;
HDC hDC = GetDC(hWnd);
hBmp = CreateCompatibleBitmap(hDC, rect.right, rect.bottom);
ReleaseDC(hWnd, hDC);
HGDIOBJ hOld = SelectObject(hDCMem, hBmp);
CRenderEngine::DrawColor(hDCMem, rect, 0x4F000000);
SelectObject(hDCMem, hOld);
DeleteObject(hDCMem);
return hBmp;
}
HWND SmallestWindowFromCursor(RECT& rcWindow)
{
HWND hWnd, hTemp;
POINT pt;
::GetCursorPos(&pt);
hWnd = ::ChildWindowFromPointEx(::GetDesktopWindow(), pt, CWP_SKIPDISABLED|CWP_SKIPINVISIBLE);
if( hWnd != NULL )
{
hTemp = hWnd;
while (true) {
::GetCursorPos(&pt);
::ScreenToClient(hTemp, &pt);
hTemp = ::ChildWindowFromPointEx(hTemp, pt, CWP_SKIPINVISIBLE);
if (hTemp == NULL || hTemp == hWnd)
break;
hWnd = hTemp;
}
::GetWindowRect(hWnd, &rcWindow);
}
return hWnd;
}