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;
        
    • 结果
  • 相关阅读:
    matlab colormap
    张量的基本概念
    河南省测绘资质单位大全
    Meanshift算法
    图形图像的绘制 GandyDraw
    leetcode
    Java 实现装饰(Decorator)模式
    Python
    Asp.Net+Easyui实现重大CRUD
    Scriptcase演示程序,现在,他们使用SC多么简单的开发系统
  • 原文地址:https://www.cnblogs.com/dahai/p/2103095.html
Copyright © 2011-2022 走看看