首页 > 其他 > 详细

CGridCtrl添加右键菜单

时间:2015-11-02 12:09:37      阅读:425      评论:0      收藏:0      [点我收藏+]

头文件下添加:

afx_msg void OnMergeCell();
    afx_msg void OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/);

添加映射:

ON_COMMAND(IDM_MergeCell, OnMergeCell)//IDM_MergeCell在resource.h添加一下就可以了
ON_WM_CONTEXTMENU()

 

.cpp(合并单元格)

void CAttendance_Guest_Day_View::OnMergeCell()
{
    CCellRange cellRange = m_HFlexGrid.GetSelectedCellRange();
    m_HFlexGrid.MergeCells(cellRange);
    m_HFlexGrid.Refresh();
}

void CAttendance_Guest_Day_View::OnContextMenu(CWnd* pWnd, CPoint point)
{
    ClientToScreen(&point);
    CRect rectCustom;
    GetDlgItem(IDC_CUSTOM1)->GetWindowRect(&rectCustom);
    if ((point.x > rectCustom.left && point.x < rectCustom.right) && (point.y > rectCustom.top && point.y < rectCustom.bottom) ){
        POINT pointOfCustom;
        CMenu menu;
        GetCursorPos(&pointOfCustom);
        menu.CreatePopupMenu();
        menu.AppendMenu(MF_STRING, IDM_MergeCell, _T("合并单元格"));
        menu.TrackPopupMenu(0, pointOfCustom.x, pointOfCustom.y, this);
    }
}

 

CGridCtrl添加右键菜单

原文:http://www.cnblogs.com/qq76211822/p/4929625.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!