zoukankan      html  css  js  c++  java
  • MFC

    原文地址:http://blog.csdn.net/zw0558/article/details/4308202
    
    1.定义成员变量: 
    CComboBox m_Cmb;  、、将它与组合框控件关联,
    CEdit m_Edit;、、将它与编辑框控件关联, 
    int m_row,m_col;  //记录用户点击的那个单元格所在的行与列号 
    2.添加listctrl的单击响应消息主要是完成了单击后将控件显示出来。添加代码如下
    void CControllerDialogAdd::OnClickListDoor(NMHDR* pNMHDR, LRESULT* pResult) 
    {
     // TODO: Add your control notification handler code here
        LPNMLISTVIEW pNMTreeView = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
        // TODO: 在此添加控件通知处理程序代码
     
        POINT PT;
        GetCursorPos(&PT);
     m_DoorList.ScreenToClient(&PT);
        LVHITTESTINFO hitInfo;
        hitInfo.pt=PT;
        //hitem=m_Tree.GetSelectedItem();
     m_DoorList.SubItemHitTest(&hitInfo);
     if(hitInfo.flags & LVHT_ONITEMLABEL)//判断是否单击在文本上
        {
            CRect rect;
           // m_DoorList.GetSubItemRect(hitInfo.iItem,hitInfo.iSubItem,LVIR_BOUNDS,rect);
       m_DoorList.GetSubItemRect(hitInfo.iItem,hitInfo.iSubItem,LVIR_BOUNDS,rect);
            if (hitInfo.iSubItem==0)
            {
                rect.right=rect.left+m_DoorList.GetColumnWidth(0);
            }
      else if(hitInfo.iSubItem==1)//对列进行判断在这里我是1,2为edit,3,4为combo box
      {
        CString mes=m_DoorList.GetItemText(hitInfo.iItem,hitInfo.iSubItem);
           // rect.InflateRect(0,0,0,0);//增大组合框的高度使其可以容纳整行文本。
            m_col=hitInfo.iSubItem;
            m_row=hitInfo.iItem;
      
            m_Edit.MoveWindow(&rect,TRUE);
      m_Edit.ShowWindow(SW_NORMAL);
            m_Edit.SetWindowText(mes);
      m_Edit.BringWindowToTop();
            m_Edit.SetFocus();//使组合框聚焦
      }
      else if(hitInfo.iSubItem==2)
      {
        CString mes=m_DoorList.GetItemText(hitInfo.iItem,hitInfo.iSubItem);
           // rect.InflateRect(0,0,0,0);//增大组合框的高度使其可以容纳整行文本。
            m_col=hitInfo.iSubItem;
            m_row=hitInfo.iItem;
    m_Edit.MoveWindow(&rect,TRUE);
      m_Edit.ShowWindow(SW_NORMAL);
            m_Edit.SetWindowText(mes);
      m_Edit.BringWindowToTop();
            m_Edit.SetFocus();//使组合框聚焦
      }
      else if(hitInfo.iSubItem==3)
      
            {
       CString mes=m_DoorList.GetItemText(hitInfo.iItem,hitInfo.iSubItem);
           // rect.InflateRect(0,0,0,0);//增大组合框的高度使其可以容纳整行文本。
            m_col=hitInfo.iSubItem;
            m_row=hitInfo.iItem;
      
            m_ComAct.MoveWindow(&rect,TRUE);
      m_ComAct.ShowWindow(SW_NORMAL);
            m_ComAct.SetWindowText(mes);
      m_ComAct.BringWindowToTop();
            m_ComAct.SetFocus();//使组合框聚焦
      
      }
      else if  (hitInfo.iSubItem==4)
      {
      CString mes=m_DoorList.GetItemText(hitInfo.iItem,hitInfo.iSubItem);
           // rect.InflateRect(0,0,0,0);//增大组合框的高度使其可以容纳整行文本。
            m_col=hitInfo.iSubItem;
            m_row=hitInfo.iItem;
     m_ControlType.MoveWindow(&rect,TRUE);
      m_ControlType.ShowWindow(SW_NORMAL);
            m_ControlType.SetWindowText(mes);
         m_ControlType.BringWindowToTop();
            m_ControlType.SetFocus();//使组合框聚焦
      }
      
      *pResult = 0;
     }
     
    }
     
    3.对话框初始化时,添加如下代码: 
    m_Cmb.SetParent(&m_List); //确保CComboBox的坐标是相对于列表控件而言的。
    m_Edit.SetParent(&m_List);//确保Edit控件的坐标是相对于列表控件而言的。
    4.当用户鼠标离开CComboBox控件时,设置单元格文本,并隐藏CComboBox控件
    当用户鼠标离开Edit控件时,设置单元格文本,并隐藏Edit控件
    首先我们要添加CComboBox控件的CBN_KILLFOCUS消息和Edit控件的EN_KILLFOCUS消息
    添加代码如下:
    
    void CControllerDialogAdd::OnKillfocusComboActive() 
    {
       // TODO: 在此添加控件通知处理程序代码
        POINT pt;
       // int i,j;
     GetCursorPos(&pt);
        m_DoorList.ScreenToClient(&pt);
        CRect rect;
        m_DoorList.GetSubItemRect(m_row,m_col,LVIR_BOUNDS,rect);
     
        if(!rect.PtInRect(pt))//如果单击在一个节点文本区域内
        {
     
     CString text;
            m_ComAct.GetWindowText(text);
            m_DoorList.SetItemText(m_row,m_col,text);
            m_ComAct.ShowWindow(SW_HIDE);//将组合框隐藏
     
    
        }
    }
     
     
    void CControllerDialogAdd::OnKillfocusEdit1() 
    {
       POINT pt;
      
        GetCursorPos(&pt);
        m_DoorList.ScreenToClient(&pt);
        CRect rect;
        m_DoorList.GetSubItemRect(m_row,m_col,LVIR_BOUNDS,rect);
     if(!rect.PtInRect(pt))//如果单击在一个节点文本区域内
        {
         CString text;
            m_Edit.GetWindowText(text);
            m_DoorList.SetItemText(m_row,m_col,text);
            m_Edit.ShowWindow(SW_HIDE);//将组合框隐藏
        }
    }
     
    5.当用户在CCombobox中按下[Enter]键时,设置单元格文本,并隐藏CComboBox控件
    
    BOOL CListDlg1Dlg::PreTranslateMessage(MSG *pMsg)
    {
            if(pMsg->wParam==VK_RETURN)
            {        
                    int i,j;
                    CString text;
                    m_Cmb.GetWindowText(text);
    
                    m_List.SetItemText(m_row,m_col,text);
             m_Cmb.ShowWindow(SW_HIDE);//隐藏组合框
                    return TRUE;//阻止了父类对消息的处理,使得按下回车键时,不会关闭对话框
                
            }
        return CDialog::PreTranslateMessage(pMsg);
    }
  • 相关阅读:
    Servlet Class4
    Servlet Class3
    Servlet Class2
    Servlet Class1
    HTTP基础知识
    XML基础知识
    JAVA Class25
    JAVA Class24
    JAVA Class23
    JAVA Class22
  • 原文地址:https://www.cnblogs.com/DuanLaoYe/p/6071518.html
Copyright © 2011-2022 走看看