如题:
CExButton  m_btnup;CBitmapButton  m_btnbmp_up;m_btnup关联按钮控件IDC_BTNUP
在对话框初始化里:m_btnbmp_up.LoadBitmaps(IDB_UP,IDB_BITMAP1);
m_btnbmp_up.SubclassDlgItem(IDC_BTNUP,this);
m_btnbmp_up.SizeToContent();这样的话会出错,有中断错误!下面是CExButton类的头文件定义:
#if !defined(AFX_EXBUTTON_H__7F81B928_9773_46C2_BCC3_04D729A7A614__INCLUDED_)
#define AFX_EXBUTTON_H__7F81B928_9773_46C2_BCC3_04D729A7A614__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ExButton.h : header file
///////////////////////////////////////////////////////////////////////////////
// CExButton windowclass CExButton : public CButton
{
// Construction
public:
CExButton();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CExButton)
//}}AFX_VIRTUAL// Implementation
public:
//设置云台控制命令
void SetButtonCommand(DWORD dwPTZCommand);
virtual ~CExButton(); // Generated message map functions
protected:
//{{AFX_MSG(CExButton)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
private:
DWORD m_dwPTZCommand;
BOOL m_bIsMouseDown;
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_EXBUTTON_H__7F81B928_9773_46C2_BCC3_04D729A7A614__INCLUDED_)

解决方案 »

  1.   

    自绘比较复杂.要自己去网上找代码.
    简单的加载图片可以使用内置的功能.加入风格BS_BITMAP.然后SetBitmap()即可.
      

  2.   

    SetBitmap()后按钮的功能失效了呀
      

  3.   

    myButton.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_BITMAP
       CRect(10,10,60,50), pParentWnd, 1);
    要加上BS_BITMAP风格
      

  4.   

    CButton::GetButtonStyle,CButton::SetButtonStyle,可以看看ButtonST
    void CButtonST::PreSubclassWindow() 
    {
    UINT nBS; nBS = GetButtonStyle(); // Set initial control type
    m_nTypeStyle = nBS & BS_TYPEMASK; // Check if this is a checkbox
    if (nBS & BS_CHECKBOX) m_bIsCheckBox = TRUE; // Set initial default state flag
    if (m_nTypeStyle == BS_DEFPUSHBUTTON)
    {
    // Set default state for a default button
    m_bIsDefault = TRUE; // Adjust style for default button
    m_nTypeStyle = BS_PUSHBUTTON;
    } // If // You should not set the Owner Draw before this call
    // (don't use the resource editor "Owner Draw" or
    // ModifyStyle(0, BS_OWNERDRAW) before calling PreSubclassWindow() )
    ASSERT(m_nTypeStyle != BS_OWNERDRAW); // Switch to owner-draw
    ModifyStyle(BS_TYPEMASK, BS_OWNERDRAW, SWP_FRAMECHANGED); CButton::PreSubclassWindow();
    } // End of PreSubclassWindow
      

  5.   

    不加BS_BITMAP
    只加BS_OWNERDRAW
      

  6.   

    在资源编辑器里,IDC_BTNUP选上Owner draw
      

  7.   

    如果你的按钮是在资源哪里添加的,你可以在资源编辑器里 Stlyes 中勾上 Bitmap 如果是动态Create出来的按钮,就用我上面5楼的那个方法