zoukankan      html  css  js  c++  java
  • 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;
        
    • 结果
  • 相关阅读:
    SQL所有者更改问题
    人生路上对我影响最大的三位老师
    自我介绍
    Ural_1146. Maximum Sum (DP)
    Ural_1654. Cipher Message(栈)
    Ural_1333. Genie Bomber 2
    POJ_2112 Optimal Milking(网络流)
    Ural_1031.Railway Ticket (DP)
    Ural_1030. Titanic
    Ural_1207. Median on the Plane(计算几何)
  • 原文地址:https://www.cnblogs.com/dahai/p/2103095.html
Copyright © 2011-2022 走看看