今天突然要用到透明对话框,所以搜索了一下找到了实现的办法如下:
创建一个对话框并在其对话框的OnInitDialog消息响应中进行初始化
所需要包含的库是User32.DLL头文件是Winuser.h
其中如果要设置透明对话框要用到的函数是SetLayeredWindowAttributes()
且必须将窗口样式中添加WS_EX_LAYERED类型其值为0x80000
LWA_COLORKEY 0x01
LWA_ALPHA值为0x02
BOOL CTooldlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE,
GetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE) | 0x80000);
HINSTANCE hInst = LoadLibrary("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, 180, 2);
FreeLibrary(hInst);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}