CGridCtrl 添加button (CGridCellButton类)

#ifndef __GRID_CELL_BUTTON__
#define __GRID_CELL_BUTTON__
#include "../GridCtrl_src/GridCell.h"  
class CGridCellButton : public CGridCell
{
    friend class CGridCtrl;
    DECLARE_DYNCREATE(CGridCellButton)
public:
    CGridCellButton(void);
    ~CGridCellButton(void);
public:
    virtual BOOL Draw(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBkgnd = TRUE);
protected:
    virtual void OnClick(CPoint PointCellRelative);
protected:
    CRect m_rect;
    BOOL m_bPushing;
};
#endif

 

.cpp:

#include "stdafx.h"  
#include "../GridCtrl_src/GridCell.h"  
#include "../GridCtrl_src/GridCtrl.h"  
#include "GridCellButton.h"  


#ifdef _DEBUG  
#define new DEBUG_NEW  
#undef THIS_FILE  
static char THIS_FILE[] = __FILE__;
#endif  

IMPLEMENT_DYNCREATE(CGridCellButton, CGridCell)
CGridCellButton::CGridCellButton(void)
{
    m_bPushing = FALSE;
}
CGridCellButton::~CGridCellButton(void)
{
}
BOOL CGridCellButton::Draw(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBkgnd /* = TRUE */)
{
    m_rect = rect;
    pDC->SetBkMode(TRANSPARENT);
    rect.DeflateRect(GetMargin(), 0);
    CFont* pOldFont = pDC->SelectObject(GetFontObject());
    pDC->DrawFrameControl(rect, DFC_BUTTON, m_bPushing ? DFCS_BUTTONPUSH | DFCS_PUSHED : DFCS_BUTTONPUSH);
    COLORREF ColorCurrent = pDC->GetTextColor();
    pDC->SetTextColor(::GetSysColor(COLOR_BTNTEXT));
    pDC->DrawText(GetText(), -1, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
    pDC->SetTextColor(ColorCurrent);
    return TRUE;
}
void CGridCellButton::OnClick(CPoint PointCellRelative)
{
    m_bPushing = !m_bPushing;
    GetGrid()->InvalidateRect(m_rect);
}

 

编译环境:vs2013  CGridCtrl版本:2.27

转载于:https://www.cnblogs.com/qq76211822/p/4905689.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值