以图片为透明界面,下面的方法只适用WINDOWS2000和XP系统:
在对话框初始化函数中加入: #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=RGB(0,255,0); HMODULE hUser32 = GetModuleHandle("user32.dll"); SetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes"); SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) │ WS_EX_LAYERED); ? ?SetLayeredWindowAttributes(GetSafeHwnd(), maskColor, 255, LWA_COLORKEY); FreeLibrary(hUser32);
其中maskcolor是透明颜色,也就是说把什么颜色区域设置成透明 |