本文介绍了如何在MFC对话框应用程序中添加next,back按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// NBtq2Dlg.cpp : implementation file

#include "stdafx.h"
#include "NBtq2.h"
#include "NBtq2Dlg.h"
#include ".\NBtq2Dlg.h"
//#include "Secondbtq.h"
#include "DlgProxy.h"
#include "SourceDeclaration.h"
#include "afxwin.h"
#include "WinDef.h"
#include "LVCustDraw.h"
#include "Wizar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#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
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};


CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()

// CNBtq2Dlg dialog

IMPLEMENT_DYNAMIC(CNBtq2Dlg, CDialog);

CNBtq2Dlg::CNBtq2Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNBtq2Dlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_pAutoProxy = NULL;
}

CNBtq2Dlg::~CNBtq2Dlg()
{
	// If there is an automation proxy for this dialog, set
	//  its back pointer to this dialog to NULL, so it knows
	//  the dialog has been deleted.
	if (m_pAutoProxy != NULL)
		m_pAutoProxy->m_pDialog = NULL;
}

void CNBtq2Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST1, m_ctlListView);

}

BEGIN_MESSAGE_MAP(CNBtq2Dlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_CLOSE()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CNBtq2Dlg::OnLvnItemchangedList1)

	ON_BN_CLICKED(IDCANCEL, &CNBtq2Dlg::OnBnClickedCancel)
	ON_BN_CLICKED(IDOK, &CNBtq2Dlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON3, &CNBtq2Dlg::OnBnClickedButton3)
END_MESSAGE_MAP()


// CNBtq2Dlg message handlers

BOOL CNBtq2Dlg::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)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		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

	COLORREF a=100,b=175;

	  m_ctlListView.InsertColumn(0, _T(" PART NO   "), LVCFMT_LEFT, 100);
	  m_ctlListView.InsertColumn(1, _T(" DESCRIPTION      "), LVCFMT_LEFT, 140);
	  m_ctlListView.InsertColumn(2, _T("                  "), LVCFMT_RIGHT, 0);


	// Insert data into list-control by copying from datamodel
	    static CString text[6][3]= {
    _T ("P1"),  _T ("D1"),  _T("G1"),
	_T ("P2"),  _T ("D2"),  _T("G1"),
	_T ("P3"),  _T ("D3"),  _T("G2"),
    _T ("P4"),  _T ("D4"),  _T("G2"),
	_T ("P5"),  _T ("D5"),  _T("G3"),
	_T ("P6"),  _T ("D6"),  _T("G3")
		};

		bool TurnOn =1;

        m_ctlListView.SetExtendedStyle(LVS_EX_FULLROWSELECT);


      for (int i=0; i<6; i++)
	   {


       m_ctlListView.InsertItem  (i, text[i][0]);

	   m_ctlListView.SetItemText (i, 1, text[i][1]);

       m_ctlListView.SetItemText (i, 2, text[i][2]);


	  }
   	   m_ctlListView.GroupByColumn(2);

	   m_ctlListView.CollapseAllGroups();

	   return TRUE;  // return TRUE  unless you set the focus to a control
}

void CNBtq2Dlg::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 CNBtq2Dlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CNBtq2Dlg::OnQueryDragIcon()
{
	return static_cast<hcursor>(m_hIcon);
}

// Automation servers should not exit when a user closes the UI
//  if a controller still holds on to one of its objects.  These
//  message handlers make sure that if the proxy is still in use,
//  then the UI is hidden but the dialog remains around if it
//  is dismissed.

void CNBtq2Dlg::OnClose()
{

	if (CanExit())
		CDialog::OnClose();
}

void CNBtq2Dlg::OnOK()
{
	if (CanExit())
		CDialog::OnOK();
}

void CNBtq2Dlg::OnCancel()
{
	if (CanExit())
		CDialog::OnCancel();

}

BOOL CNBtq2Dlg::CanExit()
{
	// If the proxy object is still around, then the automation
	//  controller is still holding on to this application.  Leave
	//  the dialog around, but hide its UI.
	if (m_pAutoProxy != NULL)
	{
		ShowWindow(SW_HIDE);
		return FALSE;
	}

	return TRUE;
}


void CNBtq2Dlg::OnLvnItemchangedList1(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV = reinterpret_cast<lpnmlistview>(pNMHDR);
	// TODO: Add your control notification handler code here
	*pResult = 0;
}




/////////////////////////////////////////////////////////////////////////////
// CLVCustomDrawApp

BEGIN_MESSAGE_MAP(CLVCustomDrawApp, CWinApp)
	//{{AFX_MSG_MAP(CLVCustomDrawApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLVCustomDrawApp construction

CLVCustomDrawApp::CLVCustomDrawApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CLVCustomDrawApp object

//CLVCustomDrawApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CLVCustomDrawApp initialization

BOOL CLVCustomDrawApp::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

	CWizard dlg ( _T("") );
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
void CNBtq2Dlg::OnBnClickedCancel()
{
	// TODO: Add your control notification handler code here
	OnCancel();
}



void CNBtq2Dlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	OnOK();
}

void CNBtq2Dlg::OnBnClickedButton3()
{
	// TODO: Add your control notification handler code here

    CNBtq2Dlg dlg;

	dlg.DoModal();



}
	#include "stdafx.h"
	#include "SourceDeclaration.h"
	#include <shlwapi.h>
	#include <stdio.h>
    #include "resource.h"


	#ifdef _DEBUG
	#define new DEBUG_NEW
	#undef THIS_FILE
	static char THIS_FILE[] = __FILE__;
	#endif
	//#include "CListCtrl_Category_Groups.h"
	BEGIN_MESSAGE_MAP(CnList, CListCtrl)
			// Column Click
	#if _WIN32_WINNT >= 0x0600
		//ON_NOTIFY_REFLECT_EX(LVN_LINKCLICK, OnGroupTaskClick)	// Column Click
	#endif
	END_MESSAGE_MAP()

	namespace {
		LRESULT EnableWindowTheme(HWND hwnd, LPCWSTR classList, LPCWSTR subApp, LPCWSTR idlist)
		{
			LRESULT lResult = S_FALSE;

			HRESULT (__stdcall *pSetWindowTheme)(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);
			HANDLE  (__stdcall *pOpenThemeData)(HWND hwnd, LPCWSTR pszClassList);
			HRESULT (__stdcall *pCloseThemeData)(HANDLE hTheme);

			HMODULE hinstDll = ::LoadLibrary(_T("UxTheme.dll"));
			if (hinstDll)
			{
				(FARPROC&)pOpenThemeData = ::GetProcAddress(hinstDll, "OpenThemeData");
				(FARPROC&)pCloseThemeData = ::GetProcAddress(hinstDll, "CloseThemeData");
				(FARPROC&)pSetWindowTheme = ::GetProcAddress(hinstDll, "SetWindowTheme");
				if (pSetWindowTheme && pOpenThemeData && pCloseThemeData)
				{
					HANDLE theme = pOpenThemeData(hwnd,classList);
					if (theme!=NULL)
					{
						VERIFY(pCloseThemeData(theme)==S_OK);
						lResult = pSetWindowTheme(hwnd, subApp, idlist);
					}
				}
				::FreeLibrary(hinstDll);
			}
			return lResult;
		}

		bool IsCommonControlsEnabled()
		{
			bool commoncontrols = false;

			// Test if application has access to common controls
			HMODULE hinstDll = ::LoadLibrary(_T("comctl32.dll"));
			if (hinstDll)
			{
				DLLGETVERSIONPROC pDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hinstDll, "DllGetVersion");
				if (pDllGetVersion != NULL)
				{
					DLLVERSIONINFO dvi = {0};
					dvi.cbSize = sizeof(dvi);
					HRESULT hRes = pDllGetVersion ((DLLVERSIONINFO *) &dvi);
					if (SUCCEEDED(hRes))
						commoncontrols = dvi.dwMajorVersion >= 6;
				}
				::FreeLibrary(hinstDll);
			}
			return commoncontrols;
		}

		bool IsThemeEnabled()
		{
			bool XPStyle = false;
			bool (__stdcall *pIsAppThemed)();
			bool (__stdcall *pIsThemeActive)();

			// Test if operating system has themes enabled
			HMODULE hinstDll = ::LoadLibrary(_T("UxTheme.dll"));
			if (hinstDll)
			{
				(FARPROC&)pIsAppThemed = ::GetProcAddress(hinstDll, "IsAppThemed");
				(FARPROC&)pIsThemeActive = ::GetProcAddress(hinstDll,"IsThemeActive");
				if (pIsAppThemed != NULL && pIsThemeActive != NULL)
				{
					if (pIsAppThemed() && pIsThemeActive())
					{
						// Test if application has themes enabled by loading the proper DLL
						XPStyle = IsCommonControlsEnabled();
					}
				}
				::FreeLibrary(hinstDll);
			}
			return XPStyle;
		}
	}

	LRESULT CnList::InsertGroupHeader(int nIndex, int nGroupId, const CString& strHeader, DWORD dwState /* = LVGS_NORMAL */, DWORD dwAlign /*= LVGA_HEADER_LEFT*/)
	{
		LVGROUP lg = {0};
		lg.cbSize = sizeof(lg);
		lg.iGroupId = nGroupId;
		lg.state = dwState;
		lg.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE | LVGF_ALIGN;
		lg.uAlign = dwAlign;

		// Header-title must be unicode (Convert if necessary)
	#ifdef UNICODE
		lg.pszHeader = (LPWSTR)(LPCTSTR)strHeader;
		lg.cchHeader = strHeader.GetLength();
	#else
		CComBSTR header = strHeader;
		lg.pszHeader = header;
		lg.cchHeader = header.Length();
	#endif

		return InsertGroup(nIndex, (PLVGROUP)&lg );
	}
	BOOL CnList::SetRowGroupId(int nRow, int nGroupId)
	{
		//OBS! Rows not assigned to a group will not show in group-view
		LVITEM lvItem = {0};
		lvItem.mask = LVIF_GROUPID;
		lvItem.iItem = nRow;
		lvItem.iSubItem = 0;
		lvItem.iGroupId = nGroupId;
		return SetItem( &lvItem );
	}
	int CnList::GetRowGroupId(int nRow)
	{
		LVITEM lvi = {0};
		lvi.mask = LVIF_GROUPID;
		lvi.iItem = nRow;
		VERIFY( GetItem(&lvi) );
		return lvi.iGroupId;
	}

	BOOL CnList::GroupByColumn(int nCol)
	{
		if (!IsCommonControlsEnabled())
			return FALSE;

		CWaitCursor waitCursor;

		//SetSortArrow(-1, false);

		SetRedraw(FALSE);

		RemoveAllGroups();

		EnableGroupView( GetItemCount() > 0 );

		if (IsGroupViewEnabled())
		{
			CSimpleMap<cstring,csimplearray><int> > groups;

			// Loop through all rows and find possible groups
			for(int nRow=0; nRow<getitemcount();>			{
				CString cellText = GetItemText(nRow, nCol);

				int nGroupId = groups.FindKey(cellText);
				if (nGroupId==-1)
				{
					CSimpleArray<int> rows;
					groups.Add(cellText, rows);
					nGroupId = groups.FindKey(cellText);
				}
				groups.GetValueAt(nGroupId).Add(nRow);
			}

			// Look through all groups and assign rows to group

			for(int nGroupId = 0; nGroupId < groups.GetSize(); ++nGroupId)
			{
				const CSimpleArray<int>& groupRows = groups.GetValueAt(nGroupId);
				DWORD dwState = LVGS_NORMAL;

	#ifdef LVGS_COLLAPSIBLE
				if (IsGroupStateEnabled())
					dwState = LVGS_COLLAPSIBLE;
	#endif

					VERIFY( InsertGroupHeader(nGroupId, nGroupId, groups.GetKeyAt(nGroupId), dwState) != -1);

				for(int groupRow = 0; groupRow < groupRows.GetSize(); ++groupRow)
				{
					VERIFY( SetRowGroupId(groupRows[groupRow], nGroupId) );
				}
			}
			SetRedraw(TRUE);
			Invalidate(FALSE);
			return TRUE;
		}

		SetRedraw(TRUE);
		Invalidate(FALSE);
		return FALSE;
	}

	namespace {
		struct PARAMSORT
		{
			PARAMSORT(HWND hWnd, int nCol, bool bAscending)
				:m_hWnd(hWnd)
				,m_ColumnIndex(nCol)
				,m_Ascending(bAscending)
			{}

			HWND m_hWnd;
			int  m_ColumnIndex;
			bool m_Ascending;
			CSimpleMap<int,cstring> m_GroupNames;

			const CString& LookupGroupName(int nGroupId)
			{
				int groupIdx = m_GroupNames.FindKey(nGroupId);
				if (groupIdx==-1)
				{
					static const CString emptyStr;
					return emptyStr;
				}
				return m_GroupNames.GetValueAt(groupIdx);
			}
		};


		int CALLBACK SortFuncGroup(int nLeftId, int nRightId, void* lParamSort)
		{
			PARAMSORT& ps = *(PARAMSORT*)lParamSort;

			const CString& left = ps.LookupGroupName(nLeftId);
			const CString& right = ps.LookupGroupName(nRightId);

			if (ps.m_Ascending)
				return _tcscmp( left, right );
			else
				return _tcscmp( right, left );
		}
	}
	void CnList::PreSubclassWindow()
	{
		CListCtrl::PreSubclassWindow();

		// Focus retangle is not painted properly without double-buffering
	#if (_WIN32_WINNT >= 0x501)
		SetExtendedStyle(LVS_EX_DOUBLEBUFFER | GetExtendedStyle());
	#endif
		SetExtendedStyle(GetExtendedStyle() | LVS_EX_FULLROWSELECT);
		SetExtendedStyle(GetExtendedStyle() | LVS_EX_HEADERDRAGDROP);
		SetExtendedStyle(GetExtendedStyle() | LVS_EX_GRIDLINES);

		// Enable Vista-look if possible
		EnableWindowTheme(GetSafeHwnd(), L"ListView", L"Explorer", NULL);
	}
	BOOL CnList::IsGroupStateEnabled()
	{
		if (!IsGroupViewEnabled())
			return FALSE;

		OSVERSIONINFO osver = {0};
		osver.dwOSVersionInfoSize = sizeof(osver);
		GetVersionEx(&osver);
		WORD fullver = MAKEWORD(osver.dwMinorVersion, osver.dwMajorVersion);
		if (fullver < 0x0600)
			return FALSE;

		return TRUE;
	}
	BOOL CnList::SetGroupTitleImage(int nGroupID, int nImage, const CString& topDesc, const CString& bottomDesc)
	{
		if (!IsGroupStateEnabled())
			return FALSE;

	#if _WIN32_WINNT >= 0x0600
		LVGROUP lg = {0};
		lg.cbSize = sizeof(lg);
		lg.mask = LVGF_TITLEIMAGE;
		lg.iTitleImage = nImage;	// Index of the title image in the control imagelist.

	#ifdef UNICODE
		if (!topDesc.IsEmpty())
		{
			// Top description is drawn opposite the title image when there is
			// a title image, no extended image, and uAlign==LVGA_HEADER_CENTER.
			lg.mask |= LVGF_DESCRIPTIONTOP;
		//	lg.pszDescriptionTop = (LPWSTR)(LPCTSTR)topDesc;
			lg.cchDescriptionTop = topDesc.GetLength();
		}
		if (!bottomDesc.IsEmpty())
		{
			// Bottom description is drawn under the top description text when there is
			// a title image, no extended image, and uAlign==LVGA_HEADER_CENTER.
			lg.mask |= LVGF_DESCRIPTIONBOTTOM;
			lg.pszDescriptionBottom = (LPWSTR)(LPCTSTR)bottomDesc;
			lg.cchDescriptionBottom = bottomDesc.GetLength();
		}
	#else
		CComBSTR bstrTopDesc = topDesc;
		CComBSTR bstrBottomDesc = bottomDesc;
		if (!topDesc.IsEmpty())
		{
			lg.mask |= LVGF_DESCRIPTIONTOP;
			lg.pszDescriptionTop = bstrTopDesc;
			lg.cchDescriptionTop = bstrTopDesc.Length();
		}
		if (!bottomDesc.IsEmpty())
		{
			lg.mask |= LVGF_DESCRIPTIONBOTTOM;
			lg.pszDescriptionBottom = bstrBottomDesc;
			lg.cchDescriptionBottom = bstrBottomDesc.Length();
		}
	#endif

		if (SetGroupInfo(nGroupID, (PLVGROUP)&lg)==-1)
			return FALSE;

		return TRUE;
	#else
		return FALSE;
	#endif
	}

	BOOL CnList::OnEraseBkgnd(CDC* pDC)
	{
		// TODO: Add your message handler code here and/or call default

	  CRect rect;
	  CnList::GetClientRect(rect);

	  POINT mypoint;

	  CBrush brush0(m_colRow1);
	  CBrush brush1(m_colRow2);

	 int chunk_height=GetCountPerPage();
	 pDC->FillRect(&rect,&brush1);

	 for (int i=0;i<=chunk_height;i++)
	 {


		GetItemPosition(i,&mypoint);
		rect.top=mypoint.y ;
		GetItemPosition(i+1,&mypoint);
		rect.bottom =mypoint.y;
		pDC->FillRect(&rect,i %2 ? &brush1 : &brush0);


	 }

	  brush0.DeleteObject();
	  brush1.DeleteObject();

	  return FALSE;
	}
void CnList::CollapseAllGroups()
{
	if (!IsGroupStateEnabled())
		return;

	// Loop through all rows and find possible groups
	for(int nRow=0; nRow<getitemcount();>	{
		int nGroupId = GetRowGroupId(nRow);
		if (nGroupId!=-1)
		{
			if (!HasGroupState(nGroupId,LVGS_COLLAPSED))
			{
				SetGroupState(nGroupId,LVGS_COLLAPSED);
			}
		}
	}
}
BOOL CnList::SetGroupState(int nGroupId, DWORD dwState)
{
	if (!IsGroupStateEnabled())
		return FALSE;

	LVGROUP lg = {0};
	lg.cbSize = sizeof(lg);
	lg.mask = LVGF_STATE;
	lg.state = dwState;
	lg.stateMask = dwState;

#ifdef LVGS_COLLAPSIBLE
	// Maintain LVGS_COLLAPSIBLE state
	if (HasGroupState(nGroupId, LVGS_COLLAPSIBLE))
		lg.state |= LVGS_COLLAPSIBLE;
#endif

	if (SetGroupInfo(nGroupId, (PLVGROUP)&lg)==-1)
		return FALSE;

	return TRUE;
}
BOOL CnList::HasGroupState(int nGroupId, DWORD dwState)
{
	LVGROUP lg = {0};
	lg.cbSize = sizeof(lg);
	lg.mask = LVGF_STATE;
	lg.stateMask = dwState;
	if ( GetGroupInfo(nGroupId, (PLVGROUP)&lg) == -1)
		return FALSE;

	return lg.state==dwState;
}
void CnList::CustDraw( NMHDR * pNMHDR, LRESULT * pResult )
{
	  LPNMCUSTOMDRAW pNMCD = reinterpret_cast<lpnmcustomdraw>(pNMHDR);
	NMTVCUSTOMDRAW* pLVCD = reinterpret_cast<nmtvcustomdraw>( pNMHDR );
	switch( pNMCD->dwDrawStage )
	{
	case CDDS_PREPAINT:
		// Item prepaint notification.
		*pResult= CDRF_NOTIFYITEMDRAW;
		break;
	case CDDS_ITEMPREPAINT:
		{
			if( ( CDIS_SELECTED == ( pNMCD->uItemState & CDIS_SELECTED )))
			{
				pNMCD->uItemState = CDIS_DEFAULT;
				pLVCD->clrText   =  mForeColor;
				pLVCD->clrTextBk =  mBkColor;
			}
			else
			{
				COLORREF crText = RGB(0,0,0);
				COLORREF mBkColor = RGB(255,255,0);

				if ((pLVCD->nmcd.dwItemSpec %2) == 0) // even lines
				{
					crText = RGB(0,0,0);
					mBkColor = RGB(0,255,255);
				}
				pLVCD->clrText = crText;
				pLVCD->clrTextBk =  mBkColor;
			}
		}
		break;

	default:
		*pResult = CDRF_DODEFAULT;
		break;
	}

}
IMPLEMENT_DYNAMIC(MyList, CListCtrl)

MyList::MyList():mBkColor(RGB(255,0,255)),
				 mForeColor(RGB(0,255,255))
{

}

MyList::~MyList()
{
}


BEGIN_MESSAGE_MAP(MyList, CListCtrl)
	ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
END_MESSAGE_MAP()


// MyList message handlers



void MyList::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<lpnmcustomdraw>(pNMHDR);
	NMTVCUSTOMDRAW* pLVCD = reinterpret_cast<nmtvcustomdraw>( pNMHDR );
	switch( pNMCD->dwDrawStage )
	{
	case CDDS_PREPAINT:
		// Item prepaint notification.
		*pResult= CDRF_NOTIFYITEMDRAW;
		break;
	case CDDS_ITEMPREPAINT:
		{
			if( ( CDIS_SELECTED == ( pNMCD->uItemState & CDIS_SELECTED )))
			{
				pNMCD->uItemState = CDIS_DEFAULT;
				pLVCD->clrText   =  mForeColor;
				pLVCD->clrTextBk =  mBkColor;
			}
			else
			{
				COLORREF crText = RGB(0,0,0);
				COLORREF mBkColor = RGB(255,255,0);

				if ((pLVCD->nmcd.dwItemSpec %2) == 0) // even lines
				{
					crText = RGB(0,0,0);
					mBkColor = RGB(0,255,255);
				}
				pLVCD->clrText = crText;
				pLVCD->clrTextBk =  mBkColor;
			}
		}
		break;

	default:
		*pResult = CDRF_DODEFAULT;
		break;
	}
}

推荐答案


这篇关于如何在MFC对话框应用程序中添加next,back按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 21:42