使窗口透明

使窗口透明

#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("载入系统dll失败,程序即将退出!");
 exit(0);
}

::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) ^ WS_EX_LAYERED);
MySetLayeredWindowAttributes(GetSafeHwnd(), 0,
 130, //这个参数是控制窗口透明的层度, 为0时窗口全透明,包括标题栏. 为255时,不透明
 LWA_ALPHA);//LWA_COLORKEY
FreeLibrary(hUser32);


使对话框窗口的客户区全透明
COLORREF maskColor= 14215660; 这是颜色掩码,与这个颜色相同的将不被显示出来
SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) | WS_EX_LAYERED);
MySetLayeredWindowAttributes(GetSafeHwnd(), maskColor, 10, LWA_COLORKEY);


 

你可能感兴趣的:(使窗口透明)