我自己做好的界面,想给按钮添加颜色。在我的工程中使用CButtonST类,compile和build都没有错误。只是想改变我界面上按钮的颜色,但是加进去CButtonST类后,编译链接没有错误,但是运行的时候什么都不出现,也不提示任何错误。我单步调试的时候提示:Unhandled exception in XXX.exe:0xc0000005:Access Violation.有谁在自己的工程中使用过CButtonST类?给我指点指点。我按照孙鑫老师的视频教程中做的。

解决方案 »

  1.   

    你是动态创建的?建议下个断点看看button的句柄是否为NULL?
      

  2.   

    “Unhandled exception in XXX.exe:0xc0000005:Access Violation”报这个错误一般都是内存非法使用的问题,比如指针变量为空时而去使用->操作符!
      

  3.   

    不是有demo么demo中如下所示:
    先声明m_btnStandard;
    void CDlgBasic::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CDlgBasic)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP // Make our buttons a CButtonST buttons
    DDX_Control(pDX, IDC_BTNSTANDARD, m_btnStandard);
    }
    BOOL CDlgBasic::OnInitDialog() 
    {
        CDialog::OnInitDialog();    // Standard button
        m_btnStandard.SetIcon(IDI_EOAPP);
        m_btnStandard.SetFlat(FALSE);    return TRUE;
    }