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 switch (pnm->hdr.code){ LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam; switch(lplvcd->nmcd.dwDrawStage) { case CDDS_PREPAINT : case CDDS_ITEMPREPAINT: /* At this point, you can change the background colors for the item return CDRF_NEWFONT; case CDDS_SUBITEM | CDDS_ITEMPREPAINT: /* This notification is received only if you are in report mode and |
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 |
Q | 如何设置ListCtrl高亮(选中)时的颜色? |
T | 如题. |
A | 捕获NM_CUSTOMDRAW,在自画的时候判断ItemState http://www.codeproject.com/listctrl/lvcustomdraw.asp LRESULT DoNotify (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) switch (pnm->hdr.code) if (lplvcd->nmcd.dwDrawStage == CDDS_PREPAINT) if (lplvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT) lplvcd->clrText = RGB(150, 75, 150); return CDRF_NEWFONT; default: 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 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. The first NM_CUSTOMDRAW notification will have the dwDrawStage member of the associated NMCUSTOMDRAW structure set to CDDS_PREPAINT. Return CDRF_NOTIFYITEMDRAW. Using Custom Draw LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam; switch (pnm->hdr.code){ LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam; switch(lplvcd->nmcd.dwDrawStage) { /* At this point, you can change the background colors for the item ... /* This notification is received only if you are in report mode and ... 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; /* if (bDelay) // return TreeView_SetItem(m_deptTree.m_hWnd, &tvItem); BOOL CSpecifyDeptPage::GetCheckState(HTREEITEM hItem) // Prepare to receive the desired information. // Request the information. // Return zero if it's not checked, or nonzero otherwise. void CSpecifyDeptPage::OnClickDeptTree(NMHDR* pNMHDR, LRESULT* pResult) UINT nFlags; Command what is yours |
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) m_caller_list.SetItemState(m_current_user,oldstate^LVIS_FOCUSED^LVIS_SELECTED,oldstate^LVIS_FOCUSED^LVIS_SELECTED); *pResult = 0; |
A | void g_listSelectItem(CListCtrl& rList,int iItem,BOOL bExclusive/*=TRUE*/) { int i; UINT state,StateMask; state=StateMask=0; 你的列表是否使用了回调项目状态? #define FIND_BIT(bits,OneBit) (((bits) & (OneBit)) ? TRUE : FALSE) // see if the OneBit is set in bits |
Q | 如何不让鼠标选中加亮ListCtrl中的某一行? |
T | 我用程序实现了加亮ListCtrl中的某一行,但鼠标一点击其它行,那一行随即被加亮了,请问如何不让鼠标加亮某一行?谢谢! |
A | 捕获LVN_ITEMCHANGING消息,并且判断,如果是选择改变,则return TRUE。 用ClassWizard增加处理函数,如果符合条件((uNewState~uOldState)&LVIS_SELECTED)),则*pResult=TRUE。 Remarks void CLeftView::OnItemChanging(NMHDR* pNMHDR, LRESULT* plr) if ((pLV ->uChanged & LVIF_STATE) && |
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) void CImagePage::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) |
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 Parameters 你在PRESTRANSLATEMESSAGE里面截获,这样LVN_ITEMCHANGING 没有被处理,系统执行默认动作 |
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 |