2702

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;//


}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章