⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uictrl.h

📁 vc座的资源管理器源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// You may use this source code, compile or redistribute it as part of your application 
// for free. You cannot redistribute it as a part of a software development 
// library without the agreement of the author. If the sources are 
// distributed along with the application, you should leave the original 
// copyright notes in the source code without any changes.
// This code can be used WITHOUT ANY WARRANTIES at your own risk.
// 
// For the latest updates to this code, check this site:
// http://www.masmex.com 
// after Sept 2000
// 
// Copyright(C) 2000 Philip Oldaker <email: philip@masmex.com>
//*******************************************************************************

#ifndef __ODLISTCTRL_H__
#define __ODLISTCTRL_H__

#define NUM_BITMAPS 2
#define MAX_TEXT	MAX_PATH

#include "UICont.h"
#include "UIDropTarget.h"
#include "UIMessages.h"
#include "LocaleInfo.h"

class CInPlaceEdit;
class CTextProgressCtrl;

//////////////////////////////////////////////////////////
//CODHeaderCtrl
//////////////////////////////////////////////////////////
class CTRL_EXT_CLASS CODHeaderCtrl : public CHeaderCtrl
{
public:
	CODHeaderCtrl();
	~CODHeaderCtrl();
public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	int SetSortImage(int nCol, BOOL bAsc);
protected:	
	int	m_nSortCol;
	BOOL	m_bSortAsc;
};

//////////////////////////////////////////////////////////////////////////
// CUIODListCtrl
// Extension of the MFC class that enacapsulates the windows list control
// makes some things simpler some things harder and some things better.
//////////////////////////////////////////////////////////////////////////
class CTRL_EXT_CLASS CUIODListCtrl : public CListCtrl 
{
public:
	enum eColTypes
	{
		e_Text,
		e_Numeric,
		e_NumericFormat,
		e_NumericFormatComma,
		e_NumericFormatTime,
		e_Double,
		e_DoubleFormat,
		e_DoubleFormatComma,
		e_DoubleFormatTime,
		e_DateTime
	};
	DECLARE_SERIAL(CUIODListCtrl)
public:
	CUIODListCtrl(bool bDragDrop=true);
	virtual ~CUIODListCtrl();  

// Attributes
	const COleDropTarget &GetDropTarget();

// Operations
public:
	void RegisterDropTarget();
	virtual void SetRowFont(int nRow,CFont *pFont);
	virtual void SetRowBold(int nRow,BOOL bBold=TRUE);
	virtual void SetColFont(int nRow,int nCol,CFont *pFont);
	virtual void SetColBold(int nRow,int nCol,BOOL bBold=TRUE);
	virtual BOOL SetColumnFormat(int nCol,int fmt);
	virtual void Serialize(CArchive& ar);
	 
	// called from CUIListView::OnCreate
	virtual void ChangeStyle(UINT &dwStyle);
	virtual void Init();
	virtual void UpdateEvent(LPARAM lHint,CObject *pHint);
	// Initialize the list control 
	// The first parameter is a pointer to an array or single icon
	// that will be added to an image list
	// The second parameter will create the columns and add the heading
	// but must be in this format Column1|Column2 delimited by the or sign
	// This MUST BE CALLED first unless you use CListCtrl or API methods to add columns
	// then you use AddTextItem to add a row passing the returned row number every time
	virtual int InitListCtrl(const UINT *pIconIDs,LPCTSTR szHeadings,LPCTSTR pszProfile=NULL);
	virtual int InitListCtrl(UINT IconID,LPCTSTR szHeadings,LPCTSTR pszProfile=NULL);
	virtual int InitListCtrl(LPCTSTR szHeadings,LPCTSTR pszProfile=NULL);
	// used to add strings after a text row has been created
	virtual BOOL AddString(int nRow,int nCol,LPCTSTR szText,CUIODListCtrl::eColTypes type=CUIODListCtrl::e_Text);
	virtual BOOL AddString(int nRow,int nCol,int nValue,CUIODListCtrl::eColTypes type=CUIODListCtrl::e_NumericFormatComma);
	virtual BOOL AddString(int nRow,int nCol,double dValue,CUIODListCtrl::eColTypes type=CUIODListCtrl::e_DoubleFormatComma);
	virtual BOOL AddString(int nRow,int nCol,COleDateTime &dtValue,CUIODListCtrl::eColTypes type=CUIODListCtrl::e_DateTime);
	// Refreshes the row after a row has changed after a call to addstring
	virtual void UpdateString(int nRow);
	// add a new column will return index or -1 on failure
	virtual void AddExtraString(int nRow,LPCTSTR pszExtraText);
	// Adds a new column 
	virtual int AddColumn(LPCTSTR szText);
	// Change the the window that receives the popup command messages
	// default is the control
	void SetPopupWnd(CWnd *pPopupWnd);
	// Use your own popup menu
	void SetPopupID(UINT nPopupID);
	// Use your own popup menu when multiple item have been selected
	void SetMultiPopupID(UINT nMultiPopupID);
	// find a column index by text
	int FindColumn(LPCTSTR pszText);
	// same as the list control
	DWORD GetItemData(int nIndex) const;
	// add a row with data on demand see 'GetDispInfo' method
	int AddCallBackItem(DWORD dwData=0,int nImage=0);
	// add a text row where you supply the string
	int AddTextItem(int nImage=0);
	// same as list control with extra flag
	BOOL SetItemData(int nIndex,DWORD dwData,bool bAutoDelete=false);
	// Sets the item data but will also delete the pointer(so make sure it is one)
	// be careful with this one
	BOOL SetItemDataAutoDelete(int nIndex,CObject *pObj);
	void SetDefaultTextColor( int nRow, int nCol);
	void SetDefaultBkColor( int nRow, int nCol);
	// set the row color (only works with ownerdraw control)
	void SetTextColor( int nRow, int nCol, COLORREF TextColor);
	// set the row color (only works with ownerdraw control)
	void SetBkColor( int nRow, int nCol, COLORREF BkColor);
	// toggle between large and small icon
	void SetIconSize(int nImageList);
	// set the icon passing an ICON id from the resources
	int SetIcon(int nRow,UINT nIconID);
	// set the icon passing the image index into the internal image list 
	int SetIcon(int nRow,int nImage);
	// find an item by extension data
	int FindItem(DWORD dwExtData);
	// set the current selection
	int SetCurSel(int nSelect);
	void SetDragDrop(bool bDragDrop);
	void SetDropFiles(bool bDropFiles);
	void SetEditSubItems(bool bEdit);
	// toggles the column sizing permission
	void SetColumnSizing(bool bSet);
	void SetToolTips(bool bSet);
	BOOL SetGridLines(bool bSet);
	BOOL SetTrackSelect(bool bSet);
	BOOL SetCheckBoxes(bool bSet);
	BOOL SetHeaderDragDrop(bool bSet);
	void SetFullRowSel(bool bSet);
	// changes the view type between LVS_ICON, LVS_SMALLICON, LVS_REPORT, etc
	BOOL SetEditLabels(bool bSet);

	void ToggleColumnSizing();
	void ToggleToolTips();
	// toggles grid lines(IE3.0 controls only)
	BOOL ToggleGridLines();
	// toggles hot tracking lines(IE3.0 controls only)
	BOOL ToggleTrackSelect();
	// toggles check boxes (IE3.0 controls only)
	BOOL ToggleCheckBoxes();
	// toggles between moving columns by dragging the header (IE3.0 controls only)
	BOOL ToggleHeaderDragDrop();
	// toggles full row selection lines(IE3.0 controls only)
	void ToggleFullRowSel();
	// changes the view type between LVS_ICON, LVS_SMALLICON, LVS_REPORT, etc
	BOOL ToggleEditLabels();

	BOOL SetViewType(DWORD dwViewType,UINT nFlags=0);
	BOOL GetFullRowSel() const;
	DWORD GetViewType() const;
	// (IE3.0 controls only)
	// set the extended style for the new IE3.0 common controls 
	BOOL SetExStyle(UINT nStyle,BOOL bModify=TRUE);
	DWORD GetExStyle();

	int GetIconSize() const;
	// call this first to get the current or first selection
	// returns -1 if no selection
	int GetCurSel() const;
	// used to get multiple selection
	// returns -1 if no selection
	int GetNextSel(int item) const;
	// number of rows
	int GetCount() const;
	// number of columns
	int GetColumnCount() const;
	// allow the right mouse click to toggle between icons sizes
	void SetRCLickChangeIconSize(BOOL bSize);
	int HitTestEx(CPoint &point, int *col) const;
	CEdit* EditSubLabel( int nItem, int nCol );
	CTextProgressCtrl *AddProgressBar(int nItem,int nCol,int nMin,int nMax);
	virtual void UpdateProgressBar(int nRow,int nCol,int nPos);
	void DeleteProgressBar(int nItem,int nCol);
	// Add an icon to the image list and return the index into the list
	int AddIcon(UINT nIconID);
	int AddIcon(HICON hIcon,UINT nIconID=0);
	int AddIcon(LPCTSTR pszIcon);
	// set the column data type primarily for sorting
	void SetColType(int nCol,eColTypes ColType);
	void SetSection(LPCTSTR pszSection);
	void SetSortHeader();
	void SetSortColumn(int nCol,BOOL bAsc);

	// sort by column
	virtual void Sort();
	// save our profiles
	virtual void SaveProfile();
	virtual void LoadProfile();
	void DelayPaint(bool bDelay);
	static CString StripNonNumeric(LPCTSTR pszOldNum,CUIODListCtrl::eColTypes type);
//////////////////
// Overrides
public:
	virtual DROPEFFECT SelectCurrentTarget(CDD_OleDropTargetInfo *pInfo);
	// ovwner draw
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	// ovwner draw
	virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItem);
	virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);

protected:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual void ConvertToTime(CString &str);
	virtual void AddThousandSeps(CString &str);
	virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
	// override if you added a callback row and fill in the structure
	virtual PFNLVCOMPARE GetCompareFunc();
	virtual BOOL GetDispInfo(LV_DISPINFO *pDispInfo);
	virtual BOOL ColumnClick(NM_LISTVIEW* pNMListView);
	virtual BOOL DoubleClick(NM_LISTVIEW* pNMListView);
	virtual BOOL OnEnter(NM_LISTVIEW* pNMListView);
	virtual BOOL OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
	virtual BOOL OnSelChanged(int nItem, LRESULT* pResult);
	// return true to delete the item from the list control
	virtual bool DeleteKey(int nRow);
	// called when the user has pressed ALt-Enter
	virtual void ShowProperties(int nRow);
	// called when the user has pressed F5
	virtual void Refresh();
	// called when the user has pressed the backspace key
	virtual void GoBack(int nRow);
	// called when the user has has finshed editing a column
	virtual bool EndLabelEdit(int nRow,int nCol,LPCTSTR pszText);
	virtual void PostNcDestroy();
	virtual int OnToolHitTest(CPoint point,TOOLINFO *pTI) const;
	virtual void PreSubclassWindow();
	virtual int CellRectFromPoint(CPoint & point, RECT * cellrect, int * col) const;
	virtual void AllItemsDeleted();
	virtual void GetImageLists(CImageList **pILSmall,CImageList **pILLarge);
	virtual void CreateImageLists();
	// callback called when a new row is added passing the extension data and row index 
	// not valid for AddTextItem only AddCallbackItem
	virtual CUIListCtrlData *GetNewListCtrlData(DWORD dwData,int nItem);
	// option to show context menu if user uses keyboard or mouse(point in client co-ords)
	virtual void ShowPopupMenu(int nRow,int nCol,CPoint point);
	virtual BOOL PopupMenuItem(int nItem,int nCol,CMenu *pPopup,CPoint point);
	virtual BOOL ItemPrePaint(LPNMLVCUSTOMDRAW  lplvcd,LRESULT *pResult);
	virtual BOOL ItemPostPaint(LPNMLVCUSTOMDRAW  lplvcd,LRESULT *pResult);
	virtual BOOL SubItemPrePaint(LPNMLVCUSTOMDRAW lplvcd,LRESULT *pResult);
	virtual BOOL SubItemPostPaint(LPNMLVCUSTOMDRAW lplvcd,LRESULT *pResult);
	//WM_DROPFILES
	virtual void OnDropFile(int nRow,LPCTSTR pszFile,UINT nFlags);
	// OLE Drag and Drop
	// This called when a drop source is dropped on the tree control
	virtual bool DragDrop(CDD_OleDropTargetInfo *pInfo);
	// This called when a drop source is currently over the tree control
	virtual bool DragOver(CDD_OleDropTargetInfo *pInfo);
	// This called when the user entered the window with a drop source
	virtual bool DragEnter(CDD_OleDropTargetInfo *pInfo);
	// This called when the user leaves the window with a drop source
	virtual bool DragLeave(CDD_OleDropTargetInfo *pInfo);
	// This called when the user initiates a OLE drag and drop
	virtual DROPEFFECT DoDragDrop(int *npRows,COleDataSource *pOleDataSource);
	virtual void Empty();

	void SetNoItemsMess(const CString &strNoItemsMess);
	CString GetNoItemsMess() const;
	bool IsDragDrop();
	bool IsDropFiles();
	void OnRClickHeader(CPoint point,int nColIndex);
	// return a pointer to an extension data object
	CUIListCtrlData *GetListCtrlData(int nItem) const;

	int GetHeaderText(CHeaderCtrl *pHeader,int nPos,CString &strText);
	void ReplaceString(CString &rStr,LPCTSTR pszOldText,LPCTSTR pszNewText);
	// owner draw
	BOOL CalcStringEllipsis(HDC hdc, LPTSTR lpszString, int cchMax, UINT uColWidth);
	// owner draw
	void DrawItemColumn(LPDRAWITEMSTRUCT lpDrawItemStruct, int nSubItem, LPRECT prcClip);
	LPCTSTR GetThousandSep() const;
	LPCTSTR GetDecimalSep() const;
	LPCTSTR GetNegativeSign() const;
	LPCTSTR GetTimeSep() const;
	LPCTSTR GetDateSep() const;
	LPCTSTR GetSection() const;
	BOOL InsertItem(LPTSTR szText,LPARAM lParam,int nImage);
	void ChangeIconSize();
	int GetImageIndex(UINT nIconID);
	// owner draw
	static LPCTSTR MakeShortString(CDC* pDC, LPCTSTR lpszLong, int nColumnLen, int nOffset);
	void RepaintSelectedItems();
	void DoOleDrag(NM_LISTVIEW* pNMListView,bool bRightMenu);	
	// for sorting

protected:
	COLORREF m_clrBkgnd;
	COLORREF m_clrTextBk;
	COLORREF m_clrText;
	int m_cxClient;
	int m_cxStateImageOffset;
	int m_nImageList;
	BOOL m_bFullRowSel;
	BOOL m_bClientWidthSel;
	BOOL m_bColumnSizing;
	BOOL m_bHasFocus;
	BOOL m_bRClickChangeIconSize;
	BOOL m_bSortAscending;
	BOOL m_bToolTips;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -