GetDlgItem 有两种形式, 1.GetDlgItem(int nID) ; 2. GetDlgItem(int nID, HWND* phWnd) 。
winocc.cpp 文件里, GetDlgItem 的原型为:
CWnd* CWnd::GetDlgItem(int nID) const
{
ASSERT(::IsWindow(m_hWnd));
if (m_pCtrlCont == NULL)
return CWnd::FromHandle(::GetDlgItem(m_hWnd, nID));// 这里的 m_hWnd 和 nID 位置是不是反了的?
else
return m_pCtrlCont->GetDlgItem(nID);
}
GetDlgItem(int nID, HWND* phWnd) 的原型为:
void CWnd::GetDlgItem(int nID, HWND* phWnd) const
{
ASSERT(::IsWindow(m_hWnd));
ASSERT(phWnd != NULL);
if (m_pCtrlCont == NULL)
*phWnd = ::GetDlgItem(m_hWnd, nID);
else
m_pCtrlCont->GetDlgItem(nID, phWnd);
}
这里有一个疑问, GetDlgItem(int nID) 里调用 GetDlgItem(m_hWnd, nID) ,这里的 m_hWnd 和 nID 位置是不是反了的?
::GetDlgItem(m_hWnd, nID);
前面有 :: 全局域作用符,表示调用的是 API
GetDlgItem(int nID, HWND* phWnd) 是 CWnd 类封装的类函数
CListCtrl::GetItemPosition
BOOL GetItemPosition(int nItem,LPPOINT lpPoint) const
返回值:如果成功,则返回非零值,否则为 0 。
参数: nItem 要获取位置的项的索引值。
lpPoint 在视图坐标中接受项左上角位置 POINT 结构的地址,按视图坐标。
说明:获取列表视图项的位置。
//
CListCtrl::GetItemRect
BOOL GetItemRect(int nItem,LPRECT lpRect,UNIT nCode) const
返回值:如果成功,则返回非零值,否则为 0 。
参数: nItem 要获取位置的项的索引值。
lpRect 接受绑定矩形的 RECT 结构的地址。
nCode 要获取绑定矩形的列表视图项的部分。它可为下列值之一: · LVIR_BOUNDS 返回整个项的绑定矩形,包括图标和标签。
· LVIR_ICON 返回图标或小图标的绑定矩形。
· LVIR_LABEL 返回项文本的绑定矩形。
说明:
在当前视图中获取某项的全部或部分的绑定矩形。
POSITION pos = m_clistctrl .GetFirstSelectedItemPosition();
if(pos!=NULL)
{
int Item = m_clistctrl .GetNextSelectedItem(pos);
CString listval= m_clistctrl .GetItemText(Item,1);
}
注意GetItemText
()的用法,获取第几列,在后面输入数字是几
POSITION pos = pList->GetFirstSelectedItemPosition();
if (pos == NULL)
TRACE0("No items were selected!/n");
else
{
while (pos)
{
int nItem = pList->GetNextSelectedItem(pos);
TRACE1("Item %d was selected!/n", nItem);
// you could do your own processing on nItem here
}
}
m_list.GetSafeHwnd()
有效???
POSITION pos = pList-> GetFirstSelectedItemPosition();
if (pos == NULL)
TRACE0( "No items were selected!/n ");
else
{
while (pos)
{
int nItem = pList-> GetNextSelectedItem(pos);
TRACE1( "Item %d was selected!/n ", nItem);
// you could do your own processing on nItem here
}
}
用GetNextItem(-1,LVNI_SELECTED)
获得当前选择的行
int iItem = -1;
CString cCurStr;
iItem = m_ctlList.GetSelectionMark();
cCurStr = m_ctlList.GetItemText(iItem,0);
……
调用 GetItemText 得到所有列的数据,然后作为参数传递给函数
// 获取选中的行号 .
int i=m_list.GetNextItem(-1,LVNI_SELECTED);
if(-1==i)
{
return;
}
else
{
// 根据列表控件被选中的行号来获取并操作该行的信息。
}
响应列表控件控件的单击函数
LVHITTESTINFO info;
info.pt=point; //point 鼠标所在点的坐标
info.flags=LVHT_ONITEMLABEL;
//SubItemHitTest(&info) 用来取得鼠标点击的所在行列
if(listctrl.SubItemHitTest(&info)>=0){
row=info.iItem;// 行
col=info.iSubItem;// 列
}