现在的位置: 首页 > 综合 > 正文

界面(3):CListCtrl

2013年09月17日 ⁄ 综合 ⁄ 共 18025字 ⁄ 字号 评论关闭
Q    a question about CListCtrl - waiting on line ...  
T 怎样将 CListCtrl 中的一行( one item)的背景或 Text Color 设为其它 color ?
A Using Custom Draw
The following code fragment is a portion of a WM_NOTIFY handler that illustrates how to handle custom draw notifications sent to a list-view control:

Hide Example

 
LPNMLISTVIEW  pnm    = (LPNMLISTVIEW)lParam;

switch (pnm->hdr.code){
...
case NM_CUSTOMDRAW:

    LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;

    switch(lplvcd->nmcd.dwDrawStage) {

    case CDDS_PREPAINT :
        return CDRF_NOTIFYITEMDRAW;

    case CDDS_ITEMPREPAINT:
        SelectObject(lplvcd->nmcd.hdc,
                     GetFontForItem(lplvcd->nmcd.dwItemSpec,
                                    lplvcd->nmcd.lItemlParam) );
        lplvcd->clrText = GetColorForItem(lplvcd->nmcd.dwItemSpec,
                                          lplvcd->nmcd.lItemlParam);
        lplvcd->clrTextBk = GetBkColorForItem(lplvcd->nmcd.dwItemSpec,
                                              lplvcd->nmcd.lItemlParam);

/* At this point, you can change the background colors for the item
and any subitems and return CDRF_NEWFONT. If the list-view control
is in report mode, you can simply return CDRF_NOTIFYSUBITEMREDRAW
to customize the item's subitems individually */
        ...

        return CDRF_NEWFONT;
 //  or return CDRF_NOTIFYSUBITEMREDRAW;

    case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
        SelectObject(lplvcd->nmcd.hdc,
                     GetFontForSubItem(lplvcd->nmcd.dwItemSpec,
                                       lplvcd->nmcd.lItemlParam,
                                       lplvcd->iSubItem));
        lplvcd->clrText = GetColorForSubItem(lplvcd->nmcd.dwItemSpec,
                                             lplvcd->nmcd.lItemlParam,
                                             lplvcd->iSubItem));
        lplvcd->clrTextBk = GetBkColorForSubItem(lplvcd->nmcd.dwItemSpec,
                                                 lplvcd->nmcd.lItemlParam,
                                                 lplvcd->iSubItem));

/* This notification is received only if you are in report mode and
returned CDRF_NOTIFYSUBITEMREDRAW in the previous step. At
this point, you can change the background colors for the
subitem and return CDRF_NEWFONT.*/
        ...
        return CDRF_NEWFONT;   
    }
...
}

Q 请问怎样在clistctrl里显示jpeg图片的缩略图呢 
T 谢谢
A BEGIN_MESSAGE_MAP(CImagePage, CPropertyPage)
 //{{AFX_MSG_MAP(CImagePage)
 ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST_PREVIEW, OnCustomDraw)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CImagePage::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
 // TODO: Add your control notification handler code here
 LPNMLVCUSTOMDRAW pnmCustDraw = (LPNMLVCUSTOMDRAW)pNMHDR;
 switch(pnmCustDraw->nmcd.dwDrawStage){
 case CDDS_PREPAINT:
  *pResult = CDRF_NOTIFYITEMDRAW ;break;
 case CDDS_ITEMPREPAINT:
  *pResult = CDRF_NOTIFYPOSTPAINT ;break;
 case CDDS_ITEMPOSTPAINT:{
  int iItem=pnmCustDraw->nmcd.dwItemSpec;
  CDC dc;
  dc.Attach(pnmCustDraw->nmcd.hdc);
  HICON hi=GetIconFromFile(m_strImageFile,iItem);
  m_pic.CreateFromIcon(hi);DestroyIcon(hi);
  CRect rectDest;
//call CListCtrl::GetItemRect to get target rect
  m_wndImgPrvwList.GetItemRect(iItem,rectDest,LVIR_ICON);
  dc.DPtoLP(rectDest);
  m_pic.Render(&dc,&rectDest);
  dc.Detach();
  *pResult = CDRF_DODEFAULT;
  break;
  }
 default:
  *pResult = CDRF_DODEFAULT;
  break;
 }
}
显示图标的……改改就行……
Q 有兴趣者请进:如何改变CListCtrl或其它控件的滚动条的颜色?
T 哪位大侠知道:在程序中如何改变CListCtrl或其它控件的滚动条的颜色(前景、背景)?
A 按理来说在窗口过程中处理WM_CTLCOLORSCROLLBAR就可以了……滚动条会往父窗口发这个消息……
Subclass滚动条,在派生类里面自画/处理WM_CTLCOLORSCROLLBAR也应该可以……
_AfxGrayBackgroundWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
 // handle standard gray backgrounds if enabled
 _AFX_WIN_STATE* pWinState = _afxWinState;
 if (pWinState->m_hDlgBkBrush != NULL &&
  (nMsg == WM_CTLCOLORBTN || nMsg == WM_CTLCOLORDLG ||
   nMsg == WM_CTLCOLORSTATIC || nMsg == WM_CTLCOLORSCROLLBAR ||
   nMsg == WM_CTLCOLORLISTBOX) &&
  CWnd::GrayCtlColor((HDC)wParam, (HWND)lParam,
   (UINT)(nMsg - WM_CTLCOLORMSGBOX),
   pWinState->m_hDlgBkBrush, pWinState->m_crDlgTextClr))
 {
  return (LRESULT)pWinState->m_hDlgBkBrush;
 }

 // do standard activation related things as well
 return _AfxActivationWndProc(hWnd, nMsg, wParam, lParam);
}

Q 如何设置ListCtrl高亮(选中)时的颜色? 
T 如题.
A 捕获NM_CUSTOMDRAW,在自画的时候判断ItemState
http://www.codeproject.com/listctrl/lvcustomdraw.asp

LRESULT DoNotify (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam;

  switch (pnm->hdr.code)
  {
    case NM_CUSTOMDRAW:
    {
      LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;

      if (lplvcd->nmcd.dwDrawStage == CDDS_PREPAINT)
        return CDRF_NOTIFYITEMDRAW;

      if (lplvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
      {
        if (!(lplvcd->nmcd.dwItemSpec % 3))
          SelectObject (lplvcd->nmcd.hdc, g_hNewFont);
        else
          return CDRF_DODEFAULT;

        lplvcd->clrText = RGB(150, 75, 150);
        lplvcd->clrTextBk = RGB(255,255,255);

        return CDRF_NEWFONT;
      }
    }

    default:
      break;
  }

  return 0;
}

Q 怎么做不同行用不同文字颜色的clistctrl(REPORT型),请赐教!
T  
A Custom Draw With List View and Tree View Controls
Most common controls can be handled in essentially the same way. However, the list view and tree view controls have some features that require a somewhat different approach to custom draw.

For Version 5.0 of the common controls, these two controls may display clipped text if you change the font by returning CDRF_NEWFONT. This behavior is necessary for backward compatibility with earlier versions of the common controls. If you want to change the font of a list view or tree view control, you will get better results if you send a CCM_SETVERSION message with the wParam value set to 5 before adding any items to the control.

Custom Draw With List View Controls
Because list view controls have subitems and multiple display modes, you will need to handle the NM_CUSTOMDRAW notification somewhat differently than for the other common controls.

For report mode:

The first NM_CUSTOMDRAW notification will have the dwDrawStage member of the associated NMCUSTOMDRAW structure set to CDDS_PREPAINT. Return CDRF_NOTIFYITEMDRAW.
You will then receive an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_ITEMPREPAINT. If you specify new fonts or colors and return CDRF_NEWFONT, all subitems of the item will be changed. If you want instead to handle each subitem separately, return CDRF_NOTIFYSUBITEMDRAW.
If you returned CDRF_NOTIFYITEMDRAW in the previous step, you will then receive an NM_CUSTOMDRAW notification for each subitem with dwDrawStage set to CDDS_SUBITEM | CDDS_PREPAINT. To change the font or color for that subitem, specify a new font or color and return CDRF_NEWFONT.
For the large icon, small icon, and list modes:

The first NM_CUSTOMDRAW notification will have the dwDrawStage member of the associated NMCUSTOMDRAW structure set to CDDS_PREPAINT. Return CDRF_NOTIFYITEMDRAW.
You will then receive an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_ITEMPREPAINT. You can change the fonts or colors of an item by specifying new fonts and colors and returning CDRF_NEWFONT. Because these modes do not have subitems, you will not receive any additional NM_CUSTOMDRAW notifications.
An example of a list view NM_CUSTOMDRAW notification handler is given in the next section.

Using Custom Draw
The following code fragment is a portion of a WM_NOTIFY handler that illustrates how to handle custom draw notifications sent to a list view control:

LPNMLISTVIEW  pnm    = (LPNMLISTVIEW)lParam;

switch (pnm->hdr.code){
...
case NM_CUSTOMDRAW:

    LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;

    switch(lplvcd->nmcd.dwDrawStage) {
    case CDDS_PREPAINT :
        return CDRF_NOTIFYITEMDRAW;
  
    case CDDS_ITEMPREPAINT:
        SelectObject(lplvcd->nmcd.hdc,
                     GetFontForItem(lplvcd->nmcd.dwItemSpec,
                                    lplvcd->nmcd.lItemlParam) );
        lplvcd->clrText = GetColorForItem(lplvcd->nmcd.dwItemSpec,
                                          lplvcd->nmcd.lItemlParam);
        lplvcd->clrTextBk = GetBkColorForItem(lplvcd->nmcd.dwItemSpec,
                                              lplvcd->nmcd.lItemlParam);

/* At this point, you can change the background colors for the item
and any subitems and return CDRF_NEWFONT. If the list view control
is in report mode, you can simply return CDRF_NOTIFYSUBITEMREDRAW
to customize the item's subitems individually */

        ...
        return CDRF_NEWFONT;
 //  or return CDRF_NOTIFYSUBITEMREDRAW;
 
    case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
        SelectObject(lplvcd->nmcd.hdc,
                     GetFontForSubItem(lplvcd->nmcd.dwItemSpec,
                                       lplvcd->nmcd.lItemlParam,
                                       lplvcd->iSubItem));
        lplvcd->clrText = GetColorForSubItem(lplvcd->nmcd.dwItemSpec,
                                             lplvcd->nmcd.lItemlParam,
                                             lplvcd->iSubItem));
        lplvcd->clrTextBk = GetBkColorForSubItem(lplvcd->nmcd.dwItemSpec,
                                                 lplvcd->nmcd.lItemlParam,
                                                 lplvcd->iSubItem));

/* This notification is received only if you are in report mode and
returned CDRF_NOTIFYSUBITEMREDRAW in the previous step. At
this point, you can change the background colors for the
subitem and return CDRF_NEWFONT.*/

        ...
        return CDRF_NEWFONT;   
    }
...
}

The first NM_CUSTOMDRAW notification has the dwDrawStage member of the NMCUSTOMDRAW structure set to CDDS_PREPAINT. The handler returns CDRF_NOTIFYITEMDRAW to indicate that it wishes to modify one or more items individually. The control then sends an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_PREPAINT for each item. The handler returns CDRF_NOTIFYITEMDRAW to indicate that it wishes to modify the item.

If CDRF_NOTIFYITEMDRAW was returned in the previous step, the next NM_CUSTOMDRAW notification has dwDrawStage set to CDDS_ITEMPREPAINT. The handler gets the current color and font values. At this point, you can specify new values for small icon, large icon, and list modes. If the control is in report mode, you can also specify new values that will apply to all subitems of the item. If you have changed anything, return CDRF_NEWFONT. If the control is in report mode and you want to handle the subitems individually, return CDRF_NOTIFYSUBITEMREDRAW.

The final notification is only sent if the control is in report mode and you returned CDRF_NOTIFYSUBITEMREDRAW in the previous step. The procedure for changing fonts and colors is the same as that step, but it only applies to a single subitem. Return CDRF_NEWFONT to notify the control if the color or font was changed.

Q 请教:CListCtrl不能显示中文???? 
T 我在ListCtrl中加入了一些英文的字符串(使用InsertColumn、InsertItem、SetItemText)一切显示正常,可是我把其中的串换成中文时显示出来的都是乱码,注:我用AppWizard建的是一个英文的工程,里面的资源也都设的是中文的。

请问这是怎么回事?难道CListCtrl不支持中文??应该如何解决?谢谢!

A When an MFC application is run under a DBCS (Double-byte Character Set, including Japanese, Chinese and Korean) in Windows NT or Windows 95, the default font specified for the dialog boxes within that application will be changed to the system font if they were originally set as "MS Sans Serif" or "Helv" in the RC file.
Knowledge Base 
Q152099
MFC Dialog Font Substitution Under DBCS System

sure,but u'd better use the font named "system"

Q CListCtrl的使用
T 请问,我用CListCtrl显示数据,用Report风格,有3个列。我设置了Owner Data风格。在OnGetdispinfoList()函数中更新数据,可以成功。但是我想在每一行前加一个单选框,我用ListView_SetExtendedListViewStyle(hwnd,LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES);设置,并用SetItemStatus函数更改状态,总是不成功,但是,在我不用Owner Data风格,用函数加数据时,就可以。

请问,我想保留Owner Data风格,怎么加一个checkbox并设置其状态?
谢谢,急。

A BOOL CSpecifyDeptPage::SetCheckState(HTREEITEM hItem, BOOL fCheck,BOOL bDelay /* FALSE */)
{
    static TVITEM tvItem;

    tvItem.mask = TVIF_HANDLE | TVIF_STATE;
    tvItem.hItem = hItem;
    tvItem.stateMask = TVIS_STATEIMAGEMASK;

    /*
    Since state images are one-based, 1 in this macro turns the check off, and
    2 turns it on.
    */
    tvItem.state = INDEXTOSTATEIMAGEMASK((fCheck ? 2 : 1));

 if (bDelay)
  ::PostMessage(m_deptTree.m_hWnd,TVM_SETITEM , 0L, (LPARAM)(&tvItem));
 else
  ::SendMessage(m_deptTree.m_hWnd,TVM_SETITEM , 0L, (LPARAM)(&tvItem));
 return TRUE;

// return TreeView_SetItem(m_deptTree.m_hWnd, &tvItem);
}

BOOL CSpecifyDeptPage::GetCheckState(HTREEITEM hItem)
{
    TVITEM tvItem;

    // Prepare to receive the desired information.
    tvItem.mask = TVIF_HANDLE | TVIF_STATE;
    tvItem.hItem = hItem;
    tvItem.stateMask = TVIS_STATEIMAGEMASK;

    // Request the information.
    TreeView_GetItem(m_deptTree.m_hWnd, &tvItem);

    // Return zero if it's not checked, or nonzero otherwise.
    return ((BOOL)(tvItem.state >> 12) -1);
}

void CSpecifyDeptPage::OnClickDeptTree(NMHDR* pNMHDR, LRESULT* pResult)
{
 // TODO: Add your control notification handler code here
 //NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
 UNREFERENCED_PARAMETER(pNMHDR);
 HTREEITEM itemTree;

 UINT nFlags;
 CPoint curPoint;
 GetCursorPos(&curPoint);
 m_deptTree.ScreenToClient(&curPoint);
 itemTree= m_deptTree.HitTest(curPoint, &nFlags);
 if (itemTree!=NULL)
  m_deptTree.Select(itemTree,TVGN_CARET);
 if (m_bEditable == FALSE) {
  // avoid to change the check state
  SetCheckState(itemTree,GetCheckState(itemTree),TRUE);
 }
 *pResult = 0;
}

Command what is yours
Conquer what is not

Q 如何在CListCtrl的ICON上显示ToolTips?
T CListCtrl为ICON风格,怎样实现把鼠标移动到CListCtrl中的ICON上后会出现ToolTips?

我自己写了一个过程,能出现这种ToolTips,但是,当我的ICON项目很多,需要将滚动条向下移动时,ToolTips所对应的信息仍然是原来在这个位置上的ICON的信息,而不是当前ICON的信息,请问该怎么办?

A handle LVN_INFOTIPO
DONOT use AddTool

www.codeproject.com/listctrl/listctrldemo.asp

Q CLisrCtrl的新问题。
T 现在我遇到一个奇怪的问题,我使用报表方式的CListCtrl,单选,前面带复选框,我想实现在点击复选框的时候勾掉其他选中的复选框,并且设置本项的状态为选中,以下是我的CListCtrl的风格设置和实现我想要的功能的代码,但在SetCheck(m,false)处出错。
m_caller_list.SetExtendedStyle(m_caller_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES|LVS_EX_TRACKSELECT); 

void CMainView::OnItemchangedListCaller(NMHDR* pNMHDR, LRESULT* pResult)
{
 HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
//在对话框启动的时候会6次触发本事件,忽略这6次
 static int sk=0;
 if (sk<6) {
  sk++;
  return;
 }
 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
 int m=pNMListView->iItem;//事件发生项的索引
 UINT newstate=pNMListView->uNewState;//事件掩码
//当newstate=4096时表示复选框被勾掉,为8192时被选中,0时某项失去选中,失去焦点,3时某项被选中,获得焦点
//m_current_user为当前选中项的索引值,
 if (m==m_current_user&&newstate==4096) {
  m_caller_list.SetCheck(m);
  return;
 }
 else
 {
  if (newstate==8192) {
   UINT oldstate=m_caller_list.GetItemState(m_current_user,0xff);//得到原来选中的项的状态

  m_caller_list.SetItemState(m_current_user,oldstate^LVIS_FOCUSED^LVIS_SELECTED,oldstate^LVIS_FOCUSED^LVIS_SELECTED);
   !m_caller_list.SetCheck(m_current_user,false);
//程序在此处出错。
   m_current_user=m;
  }
 }

 *pResult = 0;
}
请各位高手指教!如果能实现我要的功能也可以,就是要同步前面复选框的选中状态和该项的选中状态,只能有一项被选中。谢谢
分数不够可以加

A void g_listSelectItem(CListCtrl& rList,int iItem,BOOL bExclusive/*=TRUE*/)
{
 int  i;
 UINT state,StateMask;

 state=StateMask=0;
 SET_BIT(StateMask,LVIS_SELECTED | LVIS_FOCUSED);
 if (bExclusive) { // dis-select the current selected items
  RESET_BIT(state,LVIS_SELECTED | LVIS_FOCUSED);
  i=-1; // deselect or kill focus the current selected items
  ListView_SetItemState(rList.m_hWnd,i,state,StateMask);
 }
 // select the new item
 SET_BIT(state,LVIS_SELECTED | LVIS_FOCUSED);
 ListView_SetItemState(rList.m_hWnd,iItem,state,StateMask);
 if(iItem!=-1)
  rList.EnsureVisible(iItem,FALSE);
} // end of SelectListItem()

你的列表是否使用了回调项目状态?

#define FIND_BIT(bits,OneBit) (((bits) & (OneBit)) ? TRUE : FALSE) // see if the OneBit is set in bits
#define SET_BIT(bits,OneBit) ((bits) |= (OneBit)) // set the OneBit into bits as 1
#define RESET_BIT(bits,OneBit) ((bits) &=~(OneBit)) // set the OneBit into bits as 0

Q 如何不让鼠标选中加亮ListCtrl中的某一行?
T 我用程序实现了加亮ListCtrl中的某一行,但鼠标一点击其它行,那一行随即被加亮了,请问如何不让鼠标加亮某一行?谢谢!
A 捕获LVN_ITEMCHANGING消息,并且判断,如果是选择改变,则return TRUE。
用ClassWizard增加处理函数,如果符合条件((uNewState~uOldState)&LVIS_SELECTED)),则*pResult=TRUE。

Remarks
If the list view control has the LVS_OWNERDATA style, LVN_ITEMCHANGING notifications are not sent.

void CLeftView::OnItemChanging(NMHDR* pNMHDR, LRESULT* plr)
{
    NMLISTVIEW *pLV = (NMLISTVIEW *) pNMHDR;

   if ((pLV ->uChanged & LVIF_STATE) &&
       ((pLV->uNewState~pLV->uOldState)&LVIS_SELECTED)) {
       *plr=TRUE;
   }
 
}

Q 怎样才能够使CListCtrl中只显示图标而没有文本?
T 有下面的一段程序:
loadbmp(const int &index)
{
    CString filename="image//";
    CString temp;
    temp.Format("%d",index);
    HBITMAP hBitmap;
    CBitmap *pBitmap;
    pBitmap=new CBitmap;
    temp+=".bmp";
    filename+= temp;
  hBitmap=(HBITMAP)LoadImag 
             (NULL,filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    pBitmap->Attach (hBitmap);
    m_pImageList->Add (pBitmap,RGB(0,0,0));
    m_PictureList.InsertItem (index,temp,index);
    delete pBitmap;
}
但我只要显示图标,不要显示文字,怎么办呢,我开始将
m_PictureList.InsertItem (index,temp,index);
改为:m_PictureList.InsertItem (index,“”,index);
但图标之间的距离又太大了
有什么办法能够实现只显示图标又不使每个图标之间的距离过大呢

A 自己画列表项

BEGIN_MESSAGE_MAP(CImagePage, CPropertyPage)
 //{{AFX_MSG_MAP(CImagePage)
ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST_PREVIEW, OnCustomDraw)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CImagePage::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
 // TODO: Add your control notification handler code here
 LPNMLVCUSTOMDRAW pnmCustDraw = (LPNMLVCUSTOMDRAW)pNMHDR;
 switch(pnmCustDraw->nmcd.dwDrawStage){
 case CDDS_PREPAINT:
  *pResult = CDRF_NOTIFYITEMDRAW ;break;
 case CDDS_ITEMPREPAINT:
  *pResult = CDRF_NOTIFYPOSTPAINT ;break;
 case CDDS_ITEMPOSTPAINT:{
  int iItem=pnmCustDraw->nmcd.dwItemSpec;
  CDC dc;
  dc.Attach(pnmCustDraw->nmcd.hdc);
  HICON hi=GetIconFromFile(m_strImageFile,iItem);
  m_pic.CreateFromIcon(hi);DestroyIcon(hi);
  CRect rectDest;
  m_wndImgPrvwList.GetItemRect(iItem,rectDest,LVIR_BOUNDS);
  g_RectSwapTopBottom(rectDest);
  m_pic.Render(&dc,&rectDest);
  dc.Detach();
  *pResult = CDRF_DODEFAULT;
  break;
  }
 default:
  *pResult = CDRF_DODEFAULT;
  break;
 }
}

Q *************CListCtrl的送分题,UP有分***************
T 用鼠标右键单击CListCtrl中的标题拦时,如何得到当前位置的字符串或者当前是第几列,在线等候
A BOOL CEnhancedListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
 // TODO: Add your specialized code here and/or call the base class
 // wParam is zero for Header ctrl
 LPNMHDR pNH = (LPNMHDR) lParam;
 if( wParam == 0 && pNH->code == NM_RCLICK )
 {
  // Right button was clicked on header
  CHeaderCtrl* pHeader = CListCtrl::GetHeaderCtrl();
  if(pHeader){
   CPoint pt(GetMessagePos());
   CPoint posMouse=pt;
   pHeader->ScreenToClient(&pt);
   // Determine the column index
   int index=-1;
   CRect rcCol;
   for( int i=0; pHeader->GetItemRect(i, &rcCol); i++ )
   {
    if( rcCol.PtInRect( pt ) )
    {
     index = i;
     break;
    }
   }
   *pResult=TRUE;
   OnHeaderRClick(posMouse,i);
   return TRUE;
  }
 }
 return CListCtrl::OnNotify(wParam, lParam, pResult);
}

Q listctrl如何使ITEM不可选?
T 使用DISABLE属性可以使ITEM不可选,但是使用该属性将变灰,影响效果,如何处理能屏蔽掉鼠标单击ITEM或者键盘切换焦点?
想在PRESTRANSLATEMESSAGE里面截获LISTCTRL的NMCLICK消息,但是不成功,请大家指教。 switch (pMsg->message)
 {
 case WM_NOTIFY:
  if ( pMsg->wParam == NM_CLICK )
   return TRUE;
  break;
 } 
A

LVN_ITEMCHANGING

Notifies a list-view control's parent window that an item is changing. This notification message is sent in the form of a WM_NOTIFY message.

LVN_ITEMCHANGING
    pnmv = (LPNMLISTVIEW) lParam;

Parameters
pnmv
Address of an NMLISTVIEW structure that identifies the item and specifies which of its attributes are changing.
Return Values
Returns FALSE to prevent the change, or TRUE to allow the change.

你在PRESTRANSLATEMESSAGE里面截获,这样LVN_ITEMCHANGING 没有被处理,系统执行默认动作
你应该在LVN_ITEMCHANGING 中设置返回值为FALSE

Q 用过这个例子的兄弟们请帮个忙~~~关于LISTCTRL
T 例子:
http://www.vckbase.com/code/downcode.asp?id=336
1、谁有这个例子中关于CThumbListCtrl类的ThumbListCtrl.cpp文件???
2、能不能让缩略图更大一些???
3、当图片文件的文件名太长的时候,不能自动换行,该怎么解决???
4、怎么给图片加上边框???

每问25分!!!

A 刚好用ShellAPI和OLEAPI写了一个文件夹缩略图的程序……准备发在专栏的……

http://www.csdn.net/Develop/read_article.asp?id=22243
http://www.csdn.net/develop/author/netauthor/jiangsheng/files/picview.zip

抱歉!评论已关闭.