如题:
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_)
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_)
简单的加载图片可以使用内置的功能.加入风格BS_BITMAP.然后SetBitmap()即可.
CRect(10,10,60,50), pParentWnd, 1);
要加上BS_BITMAP风格
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
只加BS_OWNERDRAW