为了做成三角形的按钮,我写了一个继承于CButton的类,主要街口如下:
class CTriangleButton : public CButton
{public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTriangleButton)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUALprotected:
//{{AFX_MSG(CTriangleButton)
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
事实上确实达到了三角形效果,可是没有实现透明效果,结果看起来像是在正方形按钮上再挂了一个三角形按钮,我通过在如下代码希望实现透明效果,结果没成功:
HBRUSH CTriangleButton::CtlColor(CDC* pDC, UINT nCtlColor) 
{
// TODO: Change any attributes of the DC here
pDC->SetBkMode(TRANSPARENT);
    return (HBRUSH)GetStockObject(NULL_BRUSH);
}问题是:我用以方法成功的实现了catatic的透明效果,为什么在这里就不行了????
是不是和 DrawItem---PreSubclassWindow这两个函数的重载有关???请问大家还有什么好方法实现指挥控件的透明效果吗???

解决方案 »

  1.   

    button.ModifyStyleEx(0,WS_EX_TRANSPARENT);
      

  2.   

    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;
    fun=(MYFUNC)GetProcAddress(hinst,"SetLayeredWindowAttributes");
    if(fun)fun(this->GetSafeHwnd(),0,128,2);
    FreeLibrary(hinst);
    }
      

  3.   

    to: happyness44(风雨人生) 我在vckbase上看到类似代码,好像是使用了一个未公开的API函数,结果是实现了整个对话框相对于桌面的透明,这和我的要是不同的。