CGridCtrl只点击规定行中的按钮才弹出对话框

在头文件中添加:

afx_msg void OnClick(NMHDR* pNMHDR, LRESULT* pResult);

添加映射:ON_NOTIFY(NM_CLICK, IDC_CUSTOM1, OnClick)

void CReportRecordDlg::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
    GV_DISPINFO *pgvDispInfo = (GV_DISPINFO *)pNMHDR;  
    GV_ITEM     *pgvItem = &pgvDispInfo->item;  

    NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNMHDR;
    if (pItem->iRow == 0){
        return;
    }

    CGridCellButton *pButton = (CGridCellButton*)m_HFlexGrid.GetCell(pItem->iRow, pItem->iColumn);  
    if (pButton == NULL) return;

    if (pItem->iColumn == 10){
        CPoint point;
        GetCursorPos(&point);
        ScreenToClient(&point);
        if ((point.x > pButton->m_rect.left && point.x < pButton->m_rect.right) && (point.y > pButton->m_rect.top && point.y < pButton->m_rect.bottom)){
            m_HFlexGrid.SetEditable(FALSE);
            C**Dlg dlg;
            dlg.DoModal();
        }
        else{
            m_HFlexGrid.SetEditable(FALSE);//点击按钮旁边一点就不会弹出对话框
        }
    }
    else{
        m_HFlexGrid.SetEditable(TRUE);
    }
}

图像参考链接:http://www.cnblogs.com/qq76211822/p/4930012.html

 CGridCellButton 类参考:http://www.cnblogs.com/qq76211822/p/4905689.html
CGridCellButton类的m_rect成员变量改成public
posted @ 2015-11-02 14:21  QQ76211822  阅读(675)  评论(0编辑  收藏  举报