查了相关资料,通过SetLayeredWindowAttributesAPI来实现,参见如下函数代码
void CPopUI::SetTransparent(void)
{
SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE,
GetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE) | WS_EX_LAYERED);
HINSTANCE hInst = LoadLibrary(L"User32.DLL");
if(hInst)
{
typedef BOOL (WINAPI * MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun=NULL;
//取得SetLayeredWindowAttributes函数指针
fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if(fun)
fun(this->GetSafeHwnd(), 0, 128, 2);
FreeLibrary(hInst);
}
SetLayeredWindowAttributes(RGB(0, 0, 0), 20, LWA_ALPHA);
}