码迷,mamicode.com
首页 > Windows程序 > 详细

C# [Win32] [API] Layered Window

时间:2019-04-06 09:51:03      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:win   stat   nes   ant   psi   cti   blend   size   end   

 

  1         static void* WndProc(void* hwnd, uint uMsg, void* wParam, void* lParam)
  2         {
  3             switch (uMsg)
  4             {
  5                 case WM_PAINT:
  6                 case WM_CTLCOLORMSGBOX:
  7                 case WM_CTLCOLOREDIT:
  8                 case WM_CTLCOLORLISTBOX:
  9                 case WM_CTLCOLORBTN:
 10                 case WM_CTLCOLORDLG:
 11                 case WM_CTLCOLORSCROLLBAR:
 12                 case WM_CTLCOLORSTATIC:
 13                 case WM_CAPTURECHANGED:
 14                     {
 15                         if (_pimg != null)
 16                         {
 17                             void* _hwnd = GetAncestor(hwnd, GA_ROOT);
 18 
 19                             uint uw, uh;
 20                             GdipGetImageWidth(_pimg, &uw); GdipGetImageHeight(_pimg, &uh);
 21 
 22                             RECT rcc, rcs;
 23                             GetClientRect(_hwnd, &rcc);
 24                             GetWindowRect(_hwnd, &rcs);
 25 
 26                             PAINTSTRUCT ps;
 27                             void* hdc = BeginPaint(_hwnd, &ps); //GetDC(hwnd);
 28                             void* hdcmem = CreateCompatibleDC(hdc);                            
 29 
 30 
 31                             BITMAPINFO bi;
 32                             bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 33                             bi.bmiHeader.biWidth = (int)uw;
 34                             bi.bmiHeader.biHeight = (int)uh;
 35                             bi.bmiHeader.biPlanes = 1;
 36                             bi.bmiHeader.biBitCount = 32;
 37                             bi.bmiHeader.biCompression = BI_RGB;
 38                             bi.bmiHeader.biClrUsed = 0;
 39                             bi.bmiHeader.biSizeImage = 0;
 40 
 41                             void* pvbits;
 42                             void* hbmpmem = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &pvbits, null, 0u);
 43 
 44                             if (hbmpmem != null)
 45                             {
 46                                 SelectObject(hdcmem, hbmpmem);
 47 
 48                                 GpGraphics* g;
 49                                 if (GdipCreateFromHDC(hdcmem, &g) == 0)
 50                                 {
 51                                     GdipDrawImageRectI(g, _pimg, 0, 0, (int)uw, (int)uh);
 52 
 53 #if true
 54                                     RECT rc;
 55                                     for (int i = 0; i < 3; i++)
 56                                     {
 57                                         void* h = GetDlgItem(_hwnd, i);
 58                                         if (IsWindowVisible(h) == 1)
 59                                         {
 60                                             GetWindowRect(h, &rc);
 61                                             MapWindowPoints(null, _hwnd, (POINT*)&rc, 2);
 62                                             GpBitmap* gpbmp;
 63                                             GdipCreateBitmapFromScan0(rc.right - rc.left, rc.bottom - rc.top, 0, PixelFormat32bppARGB, null, &gpbmp);
 64                                             GpGraphics* gpg;
 65                                             if (GdipGetImageGraphicsContext((GpImage*)gpbmp, &gpg) == 0)
 66                                             {
 67                                                 void* hdc2;
 68                                                 GdipGetDC(gpg, &hdc2);
 69                                                 SendMessageW(h, WM_PRINT, hdc2, (void*)(PRF_NONCLIENT | PRF_CLIENT | PRF_ERASEBKGND | PRF_CHILDREN));
 70                                                 GdipReleaseDC(gpg, hdc2);
 71                                                 GdipDeleteGraphics(gpg);
 72                                             }
 73                                             GdipDrawImageRectI(g, (GpImage*)gpbmp, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
 74                                             GdipDisposeImage((GpImage*)gpbmp);
 75                                         }
 76                                     }
 77 #endif
 78 
 79                                     POINT ptscr;
 80 
 81                                     POINT ptdst;
 82                                     ptdst.x = rcs.left;
 83                                     ptdst.y = rcs.top;
 84 
 85                                     SIZE szwnd;
 86                                     szwnd.cx = (int)uw;
 87                                     szwnd.cy = (int)uh;
 88 
 89                                     BLENDFUNCTION bf;
 90                                     bf.BlendOp = AC_SRC_OVER;
 91                                     bf.BlendFlags = 0x0;
 92                                     bf.SourceConstantAlpha = 0xff;
 93                                     bf.AlphaFormat = AC_SRC_ALPHA;
 94 
 95 
 96                                     UPDATELAYEREDWINDOWINFO ulwi;
 97                                     ulwi.cbSize = sizeof(UPDATELAYEREDWINDOWINFO);
 98                                     ulwi.hdcDst = hdc;
 99                                     ulwi.pptDst = &ptdst;
100                                     ulwi.psize = &szwnd;
101                                     ulwi.hdcSrc = hdcmem;
102                                     ulwi.pptSrc = &ptscr;
103                                     ulwi.crKey = (COLORREF)0u;
104                                     ulwi.pblend = &bf;
105                                     ulwi.dwFlags = ULW_ALPHA;
106                                     ulwi.prcDirty = null;
107 
108                                     //UpdateLayeredWindow(_hWnd, hdc, &ptdst, &szwnd, hdcmem, &ptscr, (COLORREF)0u, &bf, ULW_ALPHA);
109                                     UpdateLayeredWindowIndirect(_hwnd, &ulwi);
110 
111                                     GdipDeleteGraphics(g);
112                                 }
113                                 DeleteObject(hbmpmem);
114                             }
115 
116                             DeleteDC(hdcmem);
117                             //ReleaseDC(hwnd, hdc);
118                             EndPaint(_hwnd, &ps);
119                         }
120                     }
121                     break;
122             }
123             return DefWindowProcW(hwnd, uMsg, wParam, lParam);
124         }

 

 

技术图片

 

C# [Win32] [API] Layered Window

标签:win   stat   nes   ant   psi   cti   blend   size   end   

原文地址:https://www.cnblogs.com/shitekudasai/p/10660553.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!