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

📄 stats.cpp

📁 The project demonstrates many Windows common controls, including the extensive use of image lists. T
💻 CPP
字号:
// stats.cpp : implementation file
//

#include "stdafx.h"
#include "DooDads.h"
#include "stats.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStatsDialog dialog


CStatsDialog::CStatsDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CStatsDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStatsDialog)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_pHeader = NULL;
}

CStatsDialog::~CStatsDialog()
{
	if (m_pHeader != NULL)
		delete m_pHeader;
}

void CStatsDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStatsDialog)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStatsDialog, CDialog)
	//{{AFX_MSG_MAP(CStatsDialog)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
	ON_NOTIFY(HDN_ENDTRACK, IDC_HEADER, OnEndTrack)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CStatsDialog message handlers

BOOL CStatsDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// destroy the placemarker

	CWnd*	pWindow = GetDlgItem(IDC_HEADER);
	pWindow->GetWindowRect(m_rect);
	pWindow->DestroyWindow();

	// measure the font in the dialog

	TEXTMETRIC	tm;
	CClientDC	dc(this);
	CRect		rect;

	dc.GetTextMetrics(&tm);

	ScreenToClient(&m_rect.TopLeft());
	ScreenToClient(&m_rect.BottomRight());

	rect = m_rect;
	rect.bottom = m_rect.top + tm.tmHeight;
	m_rect.top = rect.bottom;

	m_pHeader = new CHeaderCtrl;

	if (!m_pHeader->Create(HDS_BUTTONS | HDS_HORZ | WS_VISIBLE | 
			CCS_TOP | WS_CHILD | WS_TABSTOP | WS_BORDER,
		rect, this, IDC_HEADER))
	{
		TRACE0("Creation failed!\n");
		EndDialog(IDCANCEL);
	}

	
    HD_ITEM hdi;
	TCHAR szHeader[] = _T("Team\tPlayer\tPosition\tGoals\tPIM");
	LPTSTR pstrToken = _tcstok(szHeader, _T("\t"));
	int nIndex = 0;

	while (pstrToken != NULL)
	{
	    hdi.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH;
    	hdi.pszText = pstrToken;
    	hdi.cxy = (lstrlen(pstrToken)+3)*tm.tmAveCharWidth;
    	hdi.cchTextMax = lstrlen(hdi.pszText);
    	hdi.fmt = HDF_LEFT | HDF_STRING;

		m_pHeader->InsertItem(nIndex, &hdi);
		nIndex++;
		pstrToken = _tcstok(NULL, _T("\t"));
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CStatsDialog::OnPaint() 
{
	if (m_pHeader == NULL)
		return;

	CPaintDC dc(this); // device context for painting

	int nCount = m_pHeader->GetItemCount();
	int	nColumn;
	int	*pWidth = new int[nCount];
	int *pLeft = new int[nCount];

	for (nColumn = 0; nColumn < nCount; nColumn++)
	{
		HD_ITEM	hd;

		hd.mask = HDI_WIDTH;
		m_pHeader->GetItem(nColumn, &hd);

		pWidth[nColumn] = hd.cxy;

		if (nColumn == 0)
			pLeft[0] =  m_rect.left;
		else
			pLeft[nColumn] = pLeft[nColumn-1] + pWidth[nColumn-1];
	}

	int 	nYPos;
	int 	nRow = 1;
	int 	nHeight;
	CString	str;
	CString strName;

	int nOldMode = dc.SetBkMode(TRANSPARENT);
 
	for (nColumn = 0; nColumn < nCount; nColumn++)
	{
		HD_ITEM	hd;
		hd.mask = HDI_TEXT;
		hd.cchTextMax = 40;
		hd.pszText = strName.GetBuffer(hd.cchTextMax);
		m_pHeader->GetItem(nColumn, &hd);
		strName.ReleaseBuffer();

		nRow = 1;
		for (nYPos = m_rect.top; nYPos < m_rect.bottom; nYPos += nHeight)
		{
			CRect rectPainting(pLeft[nColumn], nYPos,
					min(pLeft[nColumn]+pWidth[nColumn], m_rect.right),
					m_rect.bottom);

			str.Format(_T("%s%d"), (LPCTSTR) strName, nRow);
			nHeight = dc.DrawText(str, rectPainting, DT_TOP | DT_LEFT | DT_SINGLELINE);
			nRow++; 	
		}
	}

	dc.SetBkMode(nOldMode);
	delete pWidth;
	delete pLeft;
	// Do not call CDialog::OnPaint() for painting messages
}

void CStatsDialog::OnEndTrack(NMHDR* pNMHDR, LRESULT* pResult)
{
	// just repaint everything!
	Invalidate();
}

⌨️ 快捷键说明

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