Q:请问,我用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;
}
Q:如何在CListCtrl的ICON上显示ToolTips?
A:handle LVN_INFOTIPO
DONOT use AddTool
www.codeproject.com/listctrl/listctrldemo.asp
Q:如何不让鼠标选中加亮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中只显示图标而没有文本?有下面的一段程序:
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中的标题拦时,如何得到当前位置的字符串或者当前是第几列,在线等候
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不可选?使用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:例子:
http://www.vckbase.com/code/downcode.asp?id=336
1、谁有这个例子中关于CThumbListCtrl类的ThumbListCtrl.cpp文件???
2、能不能让缩略图更大一些???
3、当图片文件的文件名太长的时候,不能自动换行,该怎么解决???
4、怎么给图片加上边框???
A:刚好用ShellAPI和OLEAPI写了一个文件夹缩略图的程序……准备发在专栏的……
http://www.csdn.net/Develop/read_article.asp?id=22243
http://www.csdn.net/develop/author/netauthor/jiangsheng/files/picview.zip