为什么不显示位图?(150分)
自由唐衡 2001-04-06 05:18:00 代码段如下:
class CHoverButton : public CButton
{
// Construction
public:
CHoverButton();
// Attributes
public:
// Operations
public:
void InitHoverButton(HWND hParentWnd, UINT nNormalBmpID, UINT nGetFocusBmpID);
private:
HWND m_hParentWnd;
CBitmap m_bmpNormal;
CBitmap m_bmpGetFocus;
BITMAP m_BitNormal;
BITMAP m_BitGetFocus;
CDC m_MemNormalDC;
CDC m_MemGetFocusDC;
CDC m_MemDC;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CHoverButton)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CHoverButton();
// Generated message map functions
protected:
//{{AFX_MSG(CHoverButton)
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
afx_msg void OnPaint();
//}}AFX_MSG
afx_msg void OnMouseLeave(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
void CHoverButton::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CButton::PreSubclassWindow();
}
void CHoverButton::InitHoverButton(HWND hParentWnd, UINT nNormalBmpID, UINT nGetFocusBmpID,UINT nDepressBmpID,UINT nKillFocusBmpID)
{
CClientDC dc(this);
m_hParentWnd = hParentWnd;
m_bmpNormal.LoadBitmap(nNormalBmpID); //导入通常状态下的位图
m_bmpGetFocus.LoadBitmap(nGetFocusBmpID);
//导入获得焦点时的位图
m_bmpNormal.GetBitmap(&m_BitNormal);
m_bmpGetFocus.GetBitmap(&m_BitGetFocus);
}
void CHoverButton::OnPaint()
{
CPaintDC dc(this); // device context for painting
RECT rect;
GetWindowRect(&rect);
rect.right = rect.left + m_BitNormal.bmWidth;
rect.bottom = rect.top + m_BitNormal.bmHeight;
MoveWindow(&rect);
m_MemNormalDC.CreateCompatibleDC(&dc);
m_MemGetFocusDC.CreateCompatibleDC(&dc);
m_MemDC.CreateCompatibleDC(&dc);
m_MemNormalDC.SelectObject(&m_bmpNormal);
m_MemGetFocusDC.SelectObject(&m_bmpGetFocus);
m_MemDC.SelectObject(&m_bmpNormal);
dc.BitBlt(0, 0, m_BitNormal.bmWidth, m_BitNormal.bmHeight, &m_MemDC, 0, 0, SRCCOPY);
//为什么,为什么?不能显示位图???属性我已经设置成:OwnerDraw拉
// Do not call CButton::OnPaint() for painting messages
}