代碼示例:#define LWA_COLORKEY 0x00000001 //方式
#define WS_EX_LAYERED 0x00080000
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes;
//設置成邊緣透明
COLORREF maskColor=#000000;
HMODULE hUser32 = GetModuleHandle("user32.dll"); //加載動態鏈接庫
SetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes");
//取得SetLayeredWindowAttributes函數指針
//為窗口加入WS_EX_LAYERED擴展屬性
SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE)^WS_EX_LAYERED);
//調用SetLayeredWinowAttributes函數
SetLayeredWindowAttributes(this->GetSafeHwnd(), maskColor, 192, LWA_COLORKEY);
FreeLibrary(hUser32); //釋放動態鏈接庫
以上代碼加入OnInitDialog()中,其中 SetLayeredWindowAttributes(this->GetSafeHwnd(), maskColor, 192, LWA_COLORKEY); 里,maskColor為將進行透明處理的顏色, 192為透明度, LWA_COLORKEY為透明方式。
若要透明整個對話框,則LWA_COLORKEY=2;
若要對選定顏色透明,則LWA_COLORKEY=1; 本文轉自:http://chenjiuliang.blog.163.com/blog/static/36572155201151735735374/
posted on 2013-05-29 11:18
王海光 閱讀(1760)
評論(0) 編輯 收藏 引用 所屬分類:
MFC