#define LWA_COLORKEY?0x00000001??// Use color as the transparency color.
#define WS_EX_LAYERED?0x00080000
#define LWA_ALPHA?2???// Use bAlpha to determine the opacity of the layer
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
lpfnSetLayeredWindowAttributes MySetLayeredWindowAttributes;
窗口半透明
HMODULE hUser32 = GetModuleHandle("user32.dll");
MySetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes");
if(MySetLayeredWindowAttributes == NULL)
{
?AfxMessageBox("載入系統(tǒng)dll失敗,程序即將退出!");
?exit(0);
}
::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) ^ WS_EX_LAYERED);
MySetLayeredWindowAttributes(GetSafeHwnd(), 0,
?130,?//這個(gè)參數(shù)是控制窗口透明的層度, 為0時(shí)窗口全透明,包括標(biāo)題欄. 為255時(shí),不透明
?LWA_ALPHA);//LWA_COLORKEY
FreeLibrary(hUser32);
使對(duì)話框窗口的客戶區(qū)全透明
COLORREF maskColor= 14215660; 這是顏色掩碼,與這個(gè)顏色相同的將不被顯示出來(lái)
SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) | WS_EX_LAYERED);
MySetLayeredWindowAttributes(GetSafeHwnd(), maskColor, 10, LWA_COLORKEY);
?