The window is a layered window. Note that this cannot be used for child windows. Also, this cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC. http://msdn.microsoft.com/en-us/library/ff700543(v=VS.85).aspx 子窗口不可以用WS_EX_LAYERED,再清楚不过了。
//加入WS_EX_LAYERED扩展属性
SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
BOOL SetLayeredWindowAttributes(HWND hwnd,COLORREF crKey,BYTE bAlpha,DWORD dwFlags);
hwnd是要改变的窗口,当dwFlags为LWA_ALPHA(0x2)时,crKey参数没用,bAlpha为透明度,取值在0~255之间。该函数要从User.dll中载入。
//更新窗口透明度的代码,其中iTransparent为透明度。
void CFloatWnd::OnUpdateTransparent(int iTransparent)
{
HINSTANCE hInst = LoadLibrary("User32.DLL");
if(hInst)
{
typedef BOOL (WINAPI *SLWA)(HWND,COLORREF,BYTE,DWORD);
SLWA pFun = NULL;
//取得SetLayeredWindowAttributes函数指针
pFun = (SLWA)GetProcAddress(hInst,"SetLayeredWindowAttributes");
if(pFun)
{
pFun(m_hWnd,0,iTransparent,2);
}
FreeLibrary(hInst);
}
}
详见:http://www.itwis.com/html/c/ctool/20080815/2168.html
http://msdn.microsoft.com/en-us/library/ff700543(v=VS.85).aspx
子窗口不可以用WS_EX_LAYERED,再清楚不过了。