?? testlistctrldlg.cpp
字號:
// testlistctrlDlg.cpp : implementation file
//
#include "stdafx.h"
#include "testlistctrl.h"
#include "testlistctrlDlg.h"
#include <map>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//利用stl中的multimap來保存列表項的排序
multimap <int,listitem,less<int> >::iterator iIterLess;//迭代器
multimap <int,listitem,less<int> > mNumLess;//聯合容器
multimap <int,listitem,greater<int> >::iterator iIterGreater;
multimap <int,listitem,greater<int> > mNumGreater;
multimap <CString,listitem,less<CString> >::iterator strIterLess;
multimap <CString,listitem,less<CString> > mNameLess;
multimap <CString,listitem,greater<CString> >::iterator strIterGreater;
multimap <CString,listitem,greater<CString> > mNameGreater;
multimap <int,listitem,less<int> > mScoreLess;
multimap <int,listitem,greater<int> > mScoreGreater;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestlistctrlDlg dialog
CTestlistctrlDlg::CTestlistctrlDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestlistctrlDlg::IDD, pParent)
, m_bGreater(true)
{
//{{AFX_DATA_INIT(CTestlistctrlDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestlistctrlDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestlistctrlDlg)
DDX_Control(pDX, IDC_LIST_TEST, m_ctrlList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestlistctrlDlg, CDialog)
//{{AFX_MSG_MAP(CTestlistctrlDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_TEST, OnColumnclickListTest)
//}}AFX_MSG_MAP
ON_NOTIFY ( NM_CUSTOMDRAW, IDC_LIST_TEST, OnCustomdrawMyList )
ON_BN_CLICKED(IDOK, &CTestlistctrlDlg::OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, &CTestlistctrlDlg::OnBnClickedCancel)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestlistctrlDlg message handlers
BOOL CTestlistctrlDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//初始化列表
InitList();
//設置表頭自繪屬性
HDITEM hdItem;
hdItem.mask = HDI_FORMAT;
for(int i=0;i<m_ctrlList.GetHeaderCtrl()->GetItemCount();i++)
{
m_ctrlList.GetHeaderCtrl()->GetItem(i,&hdItem);
hdItem.fmt |= HDF_OWNERDRAW;
m_ctrlList.GetHeaderCtrl()->SetItem(i,&hdItem);
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestlistctrlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestlistctrlDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestlistctrlDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//通過消息NM_CUSTOMDRAW改變item項背景色
void CTestlistctrlDlg::OnCustomdrawMyList ( NMHDR* pNMHDR, LRESULT* pResult )
{
/********************按行設置字體顏色************************/
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
// Take the default processing unless we set this to something else below.
*pResult = 0;
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
// This is the prepaint stage for an item. Here's where we set the
// item's text color. Our return value will tell Windows to draw the
// item itself, but it will use the new color we set here.
// We'll cycle the colors through red, green, and light blue.
COLORREF crText,crBkgnd;
if ( (pLVCD->nmcd.dwItemSpec % 2) == 0 )
{
crText = RGB(0,0,0);
crBkgnd = RGB(255,255,255);
}
else if ( (pLVCD->nmcd.dwItemSpec % 2) == 1 )
{
crText = RGB(0,0,0);
crBkgnd = RGB(232,232,232);
}
// Store the color back in the NMLVCUSTOMDRAW struct.
pLVCD->clrText = crText;
pLVCD->clrTextBk = crBkgnd;
// Tell Windows to paint the control itself.
*pResult = CDRF_DODEFAULT;
}
/*****************按列設置item背景和字體顏色****************/
/* NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
// Take the default processing unless we set this to something else below.
*pResult = CDRF_DODEFAULT;
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -