www.pudn.com > CListCtrlfjs.rar > ListDemoDlg.cpp
// ListDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ListDemo.h"
#include "ListDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CListDemoDlg dialog
CListDemoDlg::CListDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CListDemoDlg::IDD, pParent)
{
m_textcolor=RGB(10,20,20);
m_backcolor=RGB(120,120,120);
m_checkcolumcolor=RGB(220,20,220);
m_checktextcolor=RGB(200,220,220);
m_checkbackcolor=RGB(0,0,250);
//{{AFX_DATA_INIT(CListDemoDlg)
m_bColumShow = FALSE;
m_bExcelShow = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CListDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListDemoDlg)
DDX_Control(pDX, IDC_LIST1, m_MyListCtrl);
DDX_Check(pDX, IDC_CHECKCOLUM, m_bColumShow);
DDX_Check(pDX, IDC_CHECK2, m_bExcelShow);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CListDemoDlg, CDialog)
//{{AFX_MSG_MAP(CListDemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTONRESET, OnButtonreset)
ON_BN_CLICKED(IDC_BUTTONDISP, OnButtondisp)
ON_BN_CLICKED(IDC_CHECKCOLUM, OnCheckcolum)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListDemoDlg message handlers
BOOL CListDemoDlg::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
m_MyListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_MyListCtrl.SetCustomColor(m_textcolor,m_backcolor,m_checkcolumcolor,m_checktextcolor,m_checkbackcolor);
m_MyListCtrl.SetHeadings(_T("ID,30;Name,100;BirthDate,100;BirthDate,100;BirthDate,100;"));
m_HeadIcon.Create(20,20,TRUE,2,2);
CBitmap bm;
bm.LoadBitmap(IDB_BM);
m_HeadIcon.Add(&bm,RGB(0,128,128));
bm.DeleteObject();
m_HeadIcon.Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
m_MyListCtrl.SetImageList(&m_HeadIcon,LVSIL_SMALL);
// m_MyListCtrl.SetHeadImage(IDB_HEADBACK,IDB_HEADSORT1,IDB_HEADSORT2);
CString str;
for(int i=0;i<6;i++)
{
str.Format("%d",i+1);
m_MyListCtrl.AddItem(str,_T("栾义明"),_T("1979-07-25"),_T("栾义明"),_T("1979-07-25"));
}
// m_MyListCtrl.SetItemImage(1,1,1);
// m_MyListCtrl.GetHeaderCtrl().SetNoTrack(3);
/*
int n=m_MyListCtrl.InsertItem2("kao");
SetItemText(n,2,"kao");
m_MyListCtrl.SetItemColor(0,1,RGB(255,0,0),RGB(0,255,0));
m_MyListCtrl.SetItemColor(0,2,RGB(0,255,0),RGB(0,128,128));
m_MyListCtrl.SetItemColor(1,0,RGB(255,255,200),RGB(0,0,0));
m_MyListCtrl.SetItemColor(1,1,RGB(128,0,200),RGB(100,200,240));
*/
// m_MyListCtrl.SetItemColor(1,2,RGB(180,80,200),RGB(0,128,128));
COLORREF crText,crBak;
crText=0;
crBak=0;
/*
m_MyListCtrl.AddItemColor(_T("1"),RGB(255,0,0),RGB(0,0,0));
m_MyListCtrl.AddItemColor(_T("0"),RGB(255,0,0),RGB(0,0,0));
m_MyListCtrl.AddItemColor(_T("3"),RGB(255,0,0),RGB(0,0,0));
*/
return TRUE; // return TRUE unless you set the focus to a control
}
void CListDemoDlg::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 CListDemoDlg::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();
CClientDC dcc(this);
m_HeadIcon.Draw(&dcc,0,CPoint(10,10),ILD_TRANSPARENT);
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CListDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CListDemoDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CColorDialog cdlg(m_textcolor);
if(cdlg.DoModal()==IDOK)
{
m_textcolor=cdlg.GetColor();
m_MyListCtrl.SetCustomColor(m_textcolor,m_backcolor,m_checkcolumcolor,m_checktextcolor,m_checkbackcolor);
}
}
void CListDemoDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CColorDialog cdlg(m_backcolor);
if(cdlg.DoModal()==IDOK)
{
m_backcolor=cdlg.GetColor();
m_MyListCtrl.SetCustomColor(m_textcolor,m_backcolor,m_checkcolumcolor,m_checktextcolor,m_checkbackcolor);
}
}
void CListDemoDlg::OnButton3()
{
// TODO: Add your control notification handler code here
CColorDialog cdlg(m_checkcolumcolor);
if(cdlg.DoModal()==IDOK)
{
m_checkcolumcolor=cdlg.GetColor();
m_MyListCtrl.SetCustomColor(m_textcolor,m_backcolor,m_checkcolumcolor,m_checktextcolor,m_checkbackcolor);
}
}
void CListDemoDlg::OnButton4()
{
// TODO: Add your control notification handler code here
CColorDialog cdlg(m_checktextcolor);
if(cdlg.DoModal()==IDOK)
{
m_checktextcolor=cdlg.GetColor();
m_MyListCtrl.SetCustomColor(m_textcolor,m_backcolor,m_checkcolumcolor,m_checktextcolor,m_checkbackcolor);
}
}
void CListDemoDlg::OnButton5()
{
// TODO: Add your control notification handler code here
CColorDialog cdlg(m_checkbackcolor);
if(cdlg.DoModal()==IDOK)
{
m_checkbackcolor=cdlg.GetColor();
m_MyListCtrl.SetCustomColor(m_textcolor,m_backcolor,m_checkcolumcolor,m_checktextcolor,m_checkbackcolor);
}
}
void CListDemoDlg::OnButtonreset()
{
// TODO: Add your control notification handler code here
m_MyListCtrl.ResetHendings();
}
void CListDemoDlg::OnButtondisp()
{
// TODO: Add your control notification handler code here
m_MyListCtrl.SetHeadings(_T("ID,30;Name,100;BirthDate,100;ID,30;Name,100;BirthDate,100"));
CString str;
for(int i=0;i<10;i++)
{
str.Format("%d",i+1);
m_MyListCtrl.AddItem(str,_T("栾义明"),_T("1979-07-25"),_T("1"),_T("栾义明"),_T("1979-07-25"));
}
// m_HeadIcon.Create(16,16,TRUE,2,2);
// m_HeadIcon.Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
// m_MyListCtrl.SetImageList(&m_HeadIcon,LVSIL_SMALL);
m_MyListCtrl.SetItemColor(0,1,RGB(255,0,0),RGB(0,255,0));
m_MyListCtrl.SetItemColor(0,2,RGB(0,255,0),RGB(0,128,128));
m_MyListCtrl.SetItemColor(1,0,RGB(255,255,200),RGB(0,0,0));
m_MyListCtrl.SetItemColor(1,1,RGB(128,0,200),RGB(100,200,240));
m_MyListCtrl.SetItemColor(1,2,RGB(180,80,200),RGB(0,128,128));
}
void CListDemoDlg::OnCheckcolum()
{
// TODO: Add your control notification handler code here
UpdateData();
m_MyListCtrl.SetColumnColorShow(m_bColumShow);
}
void CListDemoDlg::OnCheck2()
{
// TODO: Add your control notification handler code here
UpdateData();
m_MyListCtrl.SetExcelShow(m_bExcelShow);
}