?? listviewex.cpp
字號:
void CListViewEx::RepaintSelectedItems()
{
CListCtrl& ListCtrl=GetListCtrl();
CRect rcItem, rcLabel;
// invalidate focused item so it can repaint properly
int nItem=ListCtrl.GetNextItem(-1,LVNI_FOCUSED);
if(nItem!=-1)
{
ListCtrl.GetItemRect(nItem,rcItem,LVIR_BOUNDS);
ListCtrl.GetItemRect(nItem,rcLabel,LVIR_LABEL);
rcItem.left=rcLabel.left;
InvalidateRect(rcItem,FALSE);
}
// if selected items should not be preserved, invalidate them
if(!(GetStyle() & LVS_SHOWSELALWAYS))
{
for(nItem=ListCtrl.GetNextItem(-1,LVNI_SELECTED);
nItem!=-1; nItem=ListCtrl.GetNextItem(nItem,LVNI_SELECTED))
{
ListCtrl.GetItemRect(nItem,rcItem,LVIR_BOUNDS);
ListCtrl.GetItemRect(nItem,rcLabel,LVIR_LABEL);
rcItem.left=rcLabel.left;
InvalidateRect(rcItem,FALSE);
}
}
// update changes
UpdateWindow();
}
/////////////////////////////////////////////////////////////////////////////
// CListViewEx diagnostics
#ifdef _DEBUG
void CListViewEx::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
dc << "m_bFullRowSel = " << (UINT)m_bFullRowSel;
dc << "\n";
dc << "m_cxStateImageOffset = " << m_cxStateImageOffset;
dc << "\n";
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CListViewEx message handlers
LRESULT CListViewEx::OnSetImageList(WPARAM wParam, LPARAM lParam)
{
if((int)wParam==LVSIL_STATE)
{
int cx, cy;
if(::ImageList_GetIconSize((HIMAGELIST)lParam,&cx,&cy))
m_cxStateImageOffset=cx;
else
m_cxStateImageOffset=0;
}
return(Default());
}
LRESULT CListViewEx::OnSetTextColor(WPARAM , LPARAM lParam)
{
m_clrText = (COLORREF)lParam;
return(Default());
}
LRESULT CListViewEx::OnSetTextBkColor(WPARAM , LPARAM lParam)
{
m_clrTextBk = (COLORREF)lParam;
return(Default());
}
LRESULT CListViewEx::OnSetBkColor(WPARAM , LPARAM lParam)
{
m_clrBkgnd = (COLORREF)lParam;
return(Default());
}
void CListViewEx::OnSize(UINT nType, int cx, int cy)
{
m_cxClient=cx;
CListView::OnSize(nType, cx, cy);
}
void CListViewEx::OnPaint()
{
// in full row select mode, we need to extend the clipping region
// so we can paint a selection all the way to the right
if(m_bClientWidthSel && (GetStyle() & LVS_TYPEMASK)==LVS_REPORT && GetFullRowSel())
{
CRect rcAllLabels;
GetListCtrl().GetItemRect(0,rcAllLabels,LVIR_BOUNDS);
if(rcAllLabels.right<m_cxClient)
{
// need to call BeginPaint (in CPaintDC c-tor)
// to get correct clipping rect
CPaintDC dc(this);
CRect rcClip;
dc.GetClipBox(rcClip);
rcClip.left=min(rcAllLabels.right-1,rcClip.left);
rcClip.right=m_cxClient;
InvalidateRect(rcClip,FALSE);
// EndPaint will be called in CPaintDC d-tor
}
}
CListView::OnPaint();
}
void CListViewEx::OnSetFocus(CWnd* pOldWnd)
{
CListView::OnSetFocus(pOldWnd);
// check if we are getting focus from label edit box
if(pOldWnd!=NULL && pOldWnd->GetParent()==this)
return;
// repaint items that should change appearance
if(m_bFullRowSel && (GetStyle() & LVS_TYPEMASK)==LVS_REPORT)
RepaintSelectedItems();
}
void CListViewEx::SetColTitle(int nIdx, LPCTSTR sTitle)
{
CListCtrl &list = GetListCtrl();
LVCOLUMN lc;
lc.mask = LVCF_TEXT/*|LVCF_SUBITEM*/;
lc.iSubItem = nIdx;
lc.pszText = (LPTSTR)sTitle;
list.SetColumn( nIdx, &lc );
}
void CListViewEx::OnKillFocus(CWnd* pNewWnd)
{
CListView::OnKillFocus(pNewWnd);
// check if we are losing focus to label edit box
if(pNewWnd!=NULL && pNewWnd->GetParent()==this)
return;
// repaint items that should change appearance
if(m_bFullRowSel && (GetStyle() & LVS_TYPEMASK)==LVS_REPORT)
RepaintSelectedItems();
}
int CListViewEx::GetItemFromPoint(const CPoint& pt, int& nSubItem, CRect* pRect)
{
LVHITTESTINFO ht;
ht.pt = pt;
int nItem = GetListCtrl().SubItemHitTest(&ht);
if (nItem<0 || (ht.flags & LVHT_ONITEMLABEL)==0)
return -1;
nSubItem = ht.iSubItem;
if (!pRect)
return nItem;
// 1st column can have icon
CRect rcFull;
GetListCtrl().GetItemRect(nItem, rcFull, LVIR_BOUNDS);
CRect rcLabel;
GetListCtrl().GetItemRect(nItem, rcLabel, LVIR_LABEL);
CRect rc(rcFull);
if (ht.iSubItem==0)
{
rc = rcLabel;
rc.left -= 3;
}
else
{
CRect rcItem;
GetListCtrl().GetHeaderCtrl()->GetItemRect(ht.iSubItem, rcItem);
rc.left = rcItem.left + 1;
rc.right = rcItem.right;
rc.top--;
rc.bottom++;
}
*pRect = rc;
return nItem;
}
//----------------------------------------------------------------
#ifndef HDF_SORTUP
#define HDF_SORTUP 0x0400
#endif
#ifndef HDF_SORTDOWN
#define HDF_SORTDOWN 0x0200
#endif
CHeaderColSortMark::CHeaderColSortMark()
{
m_nColSorted = -1;
m_bXP = FALSE;
}
void CHeaderColSortMark::Init(UINT nUpBmp, UINT nDownBmp)
{
m_nUpImage = nUpBmp;
m_nDownImage = nDownBmp;
OSVERSIONINFOEX info;
ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if(GetVersionEx((OSVERSIONINFO*)&info))
m_bXP = (info.dwMajorVersion == 5 && info.dwMinorVersion == 1);
}
void CHeaderColSortMark::SetSortMark(CListCtrl& list, int nCol, int nAsc)
{
if (nCol != m_nColSorted && m_nColSorted>=0)
RemoveMark(list, m_nColSorted);
HDITEM HeaderItem;
ZeroMemory(&HeaderItem, sizeof(HeaderItem));
HeaderItem.mask = HDI_FORMAT | HDI_BITMAP;
CHeaderCtrl* HeaderCtrl = list.GetHeaderCtrl();
HeaderCtrl->GetItem(nCol, &HeaderItem);
if (HeaderItem.hbm != 0)
{
DeleteObject(HeaderItem.hbm);
HeaderItem.hbm = 0;
}
HeaderItem.fmt |= HDF_BITMAP;
if ((HeaderItem.fmt & HDF_RIGHT) == 0)
HeaderItem.fmt |= HDF_BITMAP_ON_RIGHT;
if(!m_bXP)
HeaderItem.hbm = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(nAsc ? m_nUpImage : m_nDownImage), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
else
{
HeaderItem.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
HeaderItem.fmt |= nAsc ? HDF_SORTUP : HDF_SORTDOWN;
}
HeaderCtrl->SetItem(nCol, &HeaderItem);
m_nColSorted = nCol;
}
void CHeaderColSortMark::RemoveMark(CListCtrl& list, int nCol)
{
HDITEM HeaderItem;
ZeroMemory(&HeaderItem, sizeof(HeaderItem));
HeaderItem.mask = HDI_FORMAT | HDI_BITMAP;
CHeaderCtrl* HeaderCtrl = list.GetHeaderCtrl();
HeaderCtrl->GetItem(nCol, &HeaderItem);
HeaderItem.fmt &= ~(HDF_BITMAP | HDF_BITMAP_ON_RIGHT);
if(m_bXP)
HeaderItem.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
if (HeaderItem.hbm != 0)
{
DeleteObject(HeaderItem.hbm);
HeaderItem.hbm = 0;
}
HeaderCtrl->SetItem(nCol, &HeaderItem);
}
int CListViewEx::GetVisibleColIndex(int nCol)
{
return nCol; // not implemented yet
}
void CListViewEx::OnRButtonDown(UINT nFlags, CPoint point)
{
m_dwLastRButtonDown = GetTickCount();
CListView::OnRButtonDown(nFlags, point);
}
void CListViewEx::OnRButtonUp(UINT nFlags, CPoint point)
{
CListView::OnRButtonUp(nFlags, point);
m_dwLastRButtonDown = 0;
}
BOOL CListViewEx::OnEraseBkgnd(CDC* pDC)
{
CRect rc;
pDC->GetBoundsRect(&rc,0);
int code=pDC->SaveDC();
long lCount=GetListCtrl().GetItemCount();
for(int i=0;i<lCount;i++){
GetListCtrl().GetItemRect(i,rc,LVIR_BOUNDS);
pDC->ExcludeClipRect(rc);
}
CListView::OnEraseBkgnd(pDC);
pDC->RestoreDC(code);
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -