Transparent 之 SetLayeredWindowAttributes


  • 函数
    • The SetLayeredWindowAttributes function sets the opacity and transparency color key of a layered window.
    • BOOL SetLayeredWindowAttributes(          
          HWND hwnd,//Handle to the layered window
          COLORREF crKey,//specifies the transparency color key
          BYTE bAlpha,//describe the opacity of the layered window
          DWORD dwFlags//LWA_ALPHA | LWA_COLORKEY
      );
  • 代码
    • 	static HBITMAP hBmp1;
      	static int cxBmp;
      	static int cyBmp;
      
      	case WM_CREATE:
      		{
      			//Set Window Attributes
      			SetWindowLong(hWnd,GWL_EXSTYLE,GetWindowLong(hWnd,GWL_EXSTYLE) | WS_EX_LAYERED);
      			SetLayeredWindowAttributes(hWnd,RGB(255,255,255),160,LWA_ALPHA);
      			//load bmp
      			hBmp1 = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP1));
      			if (hBmp1 == NULL)
      			{
      				MessageBox(hWnd,L"failed to load bmp1!",NULL,MB_OK);
      			}
      			//get bmp info
      			BITMAP bmpInfo;
      			GetObject(hBmp1,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 = cxBmp + 2 * GetSystemMetrics(SM_CXFRAME);
      			int cyWnd = cyBmp + 2 * GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CYCAPTION);
      			MoveWindow(hWnd,(cxScr-cxWnd)/2,(cyScr-cyWnd)/2,cxWnd,cyWnd,TRUE);
      		}
      		break;
      
      	case WM_PAINT:
      		hdc = BeginPaint(hWnd, &ps);
      		{
      			//disp bmp
      			HDC hMemDC1 = CreateCompatibleDC(hdc);
      			SelectObject(hMemDC1, hBmp1);
      			BitBlt(hdc, 0, 0,cxBmp, cyBmp, hMemDC1, 0, 0, SRCCOPY);	
      			DeleteDC(hMemDC1);
      		}
      		EndPaint(hWnd, &ps);
      		break;
      
  • 结果
优质内容筛选与推荐>>
1、操作系统 庞丽萍 第四版 第二章学习
2、29输出图形:习题三角形输出
3、centos7.4下搭建LNMP
4、JavaScript for C#Developers Study(3)
5、如何更改MS SQL Server 2000/MSDE2000的端口号?


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号