我使用ListCtrl做了一个可编辑的表格,其他都好了,就是调整不了编辑框的坐标位置,求高手指点:
核心代码如下:
void CListDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
nItem = temp->iItem;//获得行号
nSubItem = temp->iSubItem;//获得列号
//////////////////////////////////////////////////////////////////////////
//输出行列号
/* CString str;
str.Format("行号为%d列号为%d",nItem,nSubItem);
MessageBox(str);*/
/////////////////////////////////////////////////////////////////////////// if(nSubItem == -1 || nItem == -1)
{
return ;
}
else
{
CString str;
str.Format("行号为%d列号为%d",nItem,nSubItem);
//MessageBox(str);
} CRect rect; m_List.GetSubItemRect(nItem,nSubItem,LVIR_LABEL,rect); m_edit.MoveWindow(&rect);
m_edit.SetFocus();
::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1),SW_SHOW); ::Rectangle(::GetDC(temp->hdr.hwndFrom),
rect.left,rect.top-1,rect.right,rect.bottom);
*pResult = 0;
}BOOL CListDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
CWnd* pwndCtrl = GetFocus();
// get the control ID which is
// presently having the focus
//MessageBox("123");
if(pwndCtrl == NULL)
{
return CDialog::PreTranslateMessage(pMsg);
}
int ctrl_ID = pwndCtrl->GetDlgCtrlID();
if(pMsg-> message==WM_KEYDOWN && pMsg->wParam==VK_RETURN
&&ctrl_ID ==IDC_EDIT1)
{
//AfxMessageBox(".....");
Invalidate();
CString str;
GetDlgItemText(IDC_EDIT1,str);
m_List.SetItemText(nItem,nSubItem,str);
::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1),SW_HIDE);
::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT1),"");
return TRUE;
} return CDialog::PreTranslateMessage(pMsg);}
核心代码如下:
void CListDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
nItem = temp->iItem;//获得行号
nSubItem = temp->iSubItem;//获得列号
//////////////////////////////////////////////////////////////////////////
//输出行列号
/* CString str;
str.Format("行号为%d列号为%d",nItem,nSubItem);
MessageBox(str);*/
/////////////////////////////////////////////////////////////////////////// if(nSubItem == -1 || nItem == -1)
{
return ;
}
else
{
CString str;
str.Format("行号为%d列号为%d",nItem,nSubItem);
//MessageBox(str);
} CRect rect; m_List.GetSubItemRect(nItem,nSubItem,LVIR_LABEL,rect); m_edit.MoveWindow(&rect);
m_edit.SetFocus();
::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1),SW_SHOW); ::Rectangle(::GetDC(temp->hdr.hwndFrom),
rect.left,rect.top-1,rect.right,rect.bottom);
*pResult = 0;
}BOOL CListDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
CWnd* pwndCtrl = GetFocus();
// get the control ID which is
// presently having the focus
//MessageBox("123");
if(pwndCtrl == NULL)
{
return CDialog::PreTranslateMessage(pMsg);
}
int ctrl_ID = pwndCtrl->GetDlgCtrlID();
if(pMsg-> message==WM_KEYDOWN && pMsg->wParam==VK_RETURN
&&ctrl_ID ==IDC_EDIT1)
{
//AfxMessageBox(".....");
Invalidate();
CString str;
GetDlgItemText(IDC_EDIT1,str);
m_List.SetItemText(nItem,nSubItem,str);
::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1),SW_HIDE);
::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT1),"");
return TRUE;
} return CDialog::PreTranslateMessage(pMsg);}
解决方案 »
- MFC 有没WinMain?message handler Windows Procedure 是2个什么概念
- 了解CCamand 协议的请进.
- 救命呀,我都快崩溃了,为什么我的ListCtrl中的HeaderCtrl始终显示的是乱码呢?
- VC++ 中的ToolTip显示难题?
- CBitmap类成员函数CreateCompatibleBitmap(CDC* pDC,int nWidth,int nHeight)的后两个参数如何取值?
- 请教如何将DWORD类型的数据转换成LPCTSTR类型?
- 为什么在类向导里丢了类
- 兄弟们过来看一下
- 有介绍音频方面的书吗?
- 在VC中如何使用XML文档?回复上分!
- 『疑』waveOutSetVolume的问题
- 怎么样实现根据输入的字符而显示出匹配的结果
1、GetWindowRect
2、GetSubItemRect
3、movewindow
SetWindowPos 看上去好难呀 哈哈 我刚学的 实在看不明白塌怎么用