C# [Win32] [API] Layered Windows

         static void* WndProc(void* hwnd, uint uMsg, void* wParam, void* lParam)
{
switch (uMsg)
{
case WM_PAINT:
case WM_CTLCOLORMSGBOX:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORBTN:
case WM_CTLCOLORDLG:
case WM_CTLCOLORSCROLLBAR:
case WM_CTLCOLORSTATIC:
case WM_CAPTURECHANGED:
{
if (_pimg != null)
{
void* _hwnd = GetAncestor(hwnd, GA_ROOT); uint uw, uh;
GdipGetImageWidth(_pimg, &uw); GdipGetImageHeight(_pimg, &uh); RECT rcc, rcs;
GetClientRect(_hwnd, &rcc);
GetWindowRect(_hwnd, &rcs); PAINTSTRUCT ps;
void* hdc = BeginPaint(_hwnd, &ps); //GetDC(hwnd);
void* hdcmem = CreateCompatibleDC(hdc); BITMAPINFO bi;
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = (int)uw;
bi.bmiHeader.biHeight = (int)uh;
bi.bmiHeader.biPlanes = ;
bi.bmiHeader.biBitCount = ;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biClrUsed = ;
bi.bmiHeader.biSizeImage = ; void* pvbits;
void* hbmpmem = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &pvbits, null, 0u); if (hbmpmem != null)
{
SelectObject(hdcmem, hbmpmem); GpGraphics* g;
if (GdipCreateFromHDC(hdcmem, &g) == )
{
GdipDrawImageRectI(g, _pimg, , , (int)uw, (int)uh); #if true
RECT rc;
for (int i = ; i < ; i++)
{
void* h = GetDlgItem(_hwnd, i);
if (IsWindowVisible(h) == )
{
GetWindowRect(h, &rc);
MapWindowPoints(null, _hwnd, (POINT*)&rc, );
GpBitmap* gpbmp;
GdipCreateBitmapFromScan0(rc.right - rc.left, rc.bottom - rc.top, , PixelFormat32bppARGB, null, &gpbmp);
GpGraphics* gpg;
if (GdipGetImageGraphicsContext((GpImage*)gpbmp, &gpg) == )
{
void* hdc2;
GdipGetDC(gpg, &hdc2);
SendMessageW(h, WM_PRINT, hdc2, (void*)(PRF_NONCLIENT | PRF_CLIENT | PRF_ERASEBKGND | PRF_CHILDREN));
GdipReleaseDC(gpg, hdc2);
GdipDeleteGraphics(gpg);
}
GdipDrawImageRectI(g, (GpImage*)gpbmp, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
GdipDisposeImage((GpImage*)gpbmp);
}
}
#endif POINT ptscr; POINT ptdst;
ptdst.x = rcs.left;
ptdst.y = rcs.top; SIZE szwnd;
szwnd.cx = (int)uw;
szwnd.cy = (int)uh; BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0x0;
bf.SourceConstantAlpha = 0xff;
bf.AlphaFormat = AC_SRC_ALPHA; UPDATELAYEREDWINDOWINFO ulwi;
ulwi.cbSize = sizeof(UPDATELAYEREDWINDOWINFO);
ulwi.hdcDst = hdc;
ulwi.pptDst = &ptdst;
ulwi.psize = &szwnd;
ulwi.hdcSrc = hdcmem;
ulwi.pptSrc = &ptscr;
ulwi.crKey = (COLORREF)0u;
ulwi.pblend = &bf;
ulwi.dwFlags = ULW_ALPHA;
ulwi.prcDirty = null; //UpdateLayeredWindow(_hWnd, hdc, &ptdst, &szwnd, hdcmem, &ptscr, (COLORREF)0u, &bf, ULW_ALPHA);
UpdateLayeredWindowIndirect(_hwnd, &ulwi); GdipDeleteGraphics(g);
}
DeleteObject(hbmpmem);
} DeleteDC(hdcmem);
//ReleaseDC(hwnd, hdc);
EndPaint(_hwnd, &ps);
}
}
break;
}
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}

C# [Win32] [API] Layered Windows

C# [Win32] [API] Layered Windows

上一篇:Java基础知识强化44:StringBuffer类之把数组拼接成指定格式的字符串的案例


下一篇:D5 F