zoukankan      html  css  js  c++  java
  • Transparent 之 TransparentBlt

    • TransparentBlt函数
      BOOL TransparentBlt(
        HDC hdcDest,        // handle to destination DC
        int nXOriginDest,   // x-coord of destination upper-left corner
        int nYOriginDest,   // y-coord of destination upper-left corner
        int nWidthDest,     // width of destination rectangle
        int hHeightDest,    // height of destination rectangle
        HDC hdcSrc,         // handle to source DC
        int nXOriginSrc,    // x-coord of source upper-left corner
        int nYOriginSrc,    // y-coord of source upper-left corner
        int nWidthSrc,      // width of source rectangle
        int nHeightSrc,     // height of source rectangle
        UINT crTransparent  // color to make transparent
      
    • 示例
      static HBITMAP hBmp;
      static int cxBmp;
      static int cyBmp;
      
           case WM_CREATE:
      		{
      			//load bmp and get bmp info
      			hBmp = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BALL));
      			BITMAP bmpInfo;
      			GetObject(hBmp,sizeof(BITMAP),&bmpInfo);
      			cxBmp = bmpInfo.bmWidth;
      			cyBmp = bmpInfo.bmHeight;
      			//put window int the middle screen
      			int cxScr = GetSystemMetrics(SM_CXSCREEN);
      			int cyScr = GetSystemMetrics(SM_CYSCREEN);
      			int cxWnd = 400;
      			int cyWnd = 400;
      			MoveWindow(hWnd,(cxScr-cxWnd)/2,(cyScr-cyWnd)/2,cxWnd,cyWnd,TRUE);
      		}
      		break;
      
      	case WM_PAINT:
      		hdc = BeginPaint(hWnd, &ps);
      		{
      			//bg color
      			RECT rcWnd;
      			HBRUSH hBrush;
      			GetClientRect(hWnd,&rcWnd);
      			hBrush = CreateSolidBrush(RGB(0,128,128));
      			FillRect(hdc,&rcWnd,hBrush);
      			DeleteObject(hBrush);
      			//disp bmp
      			HDC hMemDC = CreateCompatibleDC(hdc);
      			HBITMAP hOldBmp = (HBITMAP)SelectObject(hMemDC,hBmp);
      			//BitBlt(hdc,73,58,cxBmp,cyBmp,hMemDC,0,0,SRCCOPY);
      			TransparentBlt(hdc,73,58,cxBmp,cyBmp,hMemDC,0,0,cxBmp,cyBmp,RGB(255,255,255));
      			SelectObject(hMemDC,hOldBmp);
      			DeleteDC(hMemDC);
      
      		}
      		EndPaint(hWnd, &ps);
      		break;
      
    • 结果
    • BitBlt:
    • TransparentBlt:
  • 相关阅读:
    git学习笔记
    angular自定义指令-1
    转 三范式
    CentOS 7 安装NVIDIA驱动实现修改分辨率和扩屏功能
    acm 2034
    acm 2031
    记票统计
    acm 2020 map 逆向输出
    acm 2014
    将输入的字符一个一个读入
  • 原文地址:https://www.cnblogs.com/dahai/p/2101645.html
Copyright © 2011-2022 走看看