CListCtrl控件 可编辑的设置方法
1,新建一mfc类CListCtrlEx,其父类为CListCtrl
2,在该类中添加成员变量:
CEdit m_EditItem; int hitRow,hitCol;
3,在该类中 添加消息响应函数,一为鼠标双击控件内容,一为单击控件内容:
ON_NOTIFY_REFLECT(NM_DBLCLK, &CListCtrlEx::OnNMDblclk)
ON_NOTIFY_REFLECT(NM_CLICK, &CListCtrlEx::OnNMClick)
4,具体实现:
void CListCtrlEx::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
{
//LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<NMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
LVHITTESTINFO info;
info.pt = pNMItemActivate->ptAction;
if(this->SubItemHitTest(&info) != -1 )
{
hitRow = info.iItem;
hitCol = info.iSubItem;
if(m_EditItem.m_hWnd == NULL)
{
RECT rect;
rect.left = 0;
rect.top = 0;
rect.bottom = 15;
rect.right = 200;
//这里需要注意,要设置m_EditItem的父窗口为该控件 ,网上多数介绍此处时未强调
m_EditItem.Create(WS_CHILD | ES_LEFT | WS_BORDER | ES_AUTOHSCROLL | ES_WANTRETURN | ES_MULTILINE, rect, this, 101);
m_EditItem.SetFont(this->GetFont(), FALSE);
}
CRect rect;
this->GetSubItemRect(info.iItem, info.iSubItem, LVIR_LABEL, rect);
//rect.top += 12;
//rect.left += 13;
//rect.right += 13;
//rect.bottom += 12;
m_EditItem.SetWindowText(this->GetItemText(info.iItem, info.iSubItem));
m_EditItem.ShowWindow(1);
m_EditItem.MoveWindow(&rect, TRUE);
m_EditItem.SetFocus();
m_EditItem.SetSel(-1);
}
*pResult = 0;
}
void CListCtrlEx::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
if(m_EditItem.m_hWnd != NULL)
{
m_EditItem.ShowWindow(0);
if(hitRow != -1)
{
CString text;
m_EditItem.GetWindowText(text);
this->SetItemText(hitRow, hitCol, text);
}
m_EditItem.DestroyWindow();
}
hitCol = hitRow = -1;
*pResult = 0;
}
5,注意事项:
两函数也可以在CListCtrl控件的父窗口上实现,但实现时CEdit类实例化时其父窗口必须与CListCtrl绑定,而不是与CListCtrl的父窗口绑定。
否则,CEdit文本框不能正确显示在所双击的位置。
If you've played your justifiable share of video slots already, then right here is every thing you want to know in regards to the high new video slots of 2020. Then learn alongside and luxuriate in, as we now have put collectively a listing of the most effective new video slots that you simply can} play in 2020. Chests are collected whereas spinning in any sport, when leveling-up or by buying coin packs. You're additionally given two free chests every single day to play slots for enjoyable. This casino operator additionally has a computer scoring program that automatically determines the casino’s efficiency primarily based on the lively participation of players in a day, and 1xbet rewards them with a share.
回复删除