使用该种方法要注意几个问题:
1. 窗口属性必须是Top Window,子窗口(Win8之前的操作系统)不支持实现异形窗口
2. Layer Window没有WM_PAINT消息,需要自己调用OnPaint
3. 窗口属性可设置为
WS_POPUP | WS_VISIBLE, WS_EX_TOOLWINDOW | WS_EX_LAYERED
实现代码:
CDC hdc = GetDC(); // Get the display device context (DC)
CDC hdcSrc = CreateCompatibleDC(hdc); // creates a memory device context (DC) compatible with the display device context
CRect rc;
GetClientRect(&rc);
// 创建DIB
BITMAPINFO bmInfo;
ZeroMemory (&bmInfo, sizeof(bmInfo));
bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth = rc.Width();
bmInfo.bmiHeader.biHeight = rc.Height();
bmInfo.bmiHeader.biPlanes = 1;
bmInfo.bmiHeader.biBitCount = 32;
UINT* pBits = NULL;
CBitmap hBmp = Cre