如何设置按钮控件的透明度???
对窗口控件设置透明度时可以通过SetLayeredWindowAttributes()函数设置,我编了段代码能够设置dialog的透明度,但是同样的代码却不能设置button的透明度,为什么呢?button和dialog都继承自CWnd,而SetLayeredWindowAttributes()是CWnd的函数。我编的那段代码如下:
void COoDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
LONG lWindowLong;
HWND hWnd ,hWnd2;
HMODULE hUser32;
typedef BOOL (WINAPI *lpfn) (HWND hWnd, COLORREF cr, BYTE bAlpha, DWORD dwFlags);
lpfn g_pSetLayeredWindowAttributes;
hUser32 = GetModuleHandle(_T("USER32.DLL"));
g_pSetLayeredWindowAttributes = (lpfn)GetProcAddress(hUser32, "SetLayeredWindowAttributes");
//hWnd =GetDlgItem(IDOK)->GetSafeHwnd();//获取“确定”按钮的句柄
//hWnd =GetSafeHwnd();//获取dialog的句柄
lWindowLong = GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED;
::SetWindowLong(hWnd, GWL_EXSTYLE, lWindowLong);
g_pSetLayeredWindowAttributes(hWnd, 0, 100, 2);
::RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
if (hUser32 != NULL)
FreeLibrary(hUser32);
CDialog::OnLButtonDown(nFlags, point);
}
当hWnd =GetSafeHwnd();获取dialog的句柄时,程序能正常改变dialog的透明度
当hWnd =GetDlgItem(IDOK)->GetSafeHwnd();获取“确定”按钮的句柄时,程序却不能改变“确定”按钮的透明度。为什么???期待各位的解答,谢谢。