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

📄 speedview.cpp

📁 测量被试的阅读速度
💻 CPP
字号:
// SpeedView.cpp : implementation of the CSpeedView class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"

#include "SpeedView.h"
#include ".\speedview.h"

const TCHAR* const speedRegKey = _T("Software\\Speed");

bool LoadOption(HKEY hKeyParent, TCHAR szFontName[], DWORD& FontHeight, DWORD& FontWeight, DWORD& Charset)
{
//	TCHAR sKey[MAX_PATH];
//	wsprintf(sKey, _T("%s\\%s"), kPadRegKey, _T("Option"));

	CRegKey key;
	if (ERROR_SUCCESS != key.Open(hKeyParent, _T("Option")))
		return false;

	DWORD dw = LF_FACESIZE;
	key.QueryStringValue(_T("FontName"), szFontName, &dw);
	key.QueryDWORDValue(_T("FontHeight"), FontHeight);
	key.QueryDWORDValue(_T("FontWeight"), FontWeight);
	key.QueryDWORDValue(_T("Charset"), Charset);

	return true;
}

bool SaveOption(HKEY hKeyParent, TCHAR szFontName[], DWORD FontHeight, DWORD FontWeight, DWORD Charset)
{
	CRegKey key;
	if (ERROR_SUCCESS != key.Create(hKeyParent, _T("Option")))
		return false;

	key.SetStringValue(_T("FontName"), szFontName);
	key.SetDWORDValue(_T("FontHeight"), FontHeight);
	key.SetDWORDValue(_T("FontWeight"), FontWeight);
	key.SetDWORDValue(_T("Charset"), Charset);

	return true;
}

BOOL CSpeedView::PreTranslateMessage(MSG* pMsg)
{
	pMsg;
	return FALSE;
}


LRESULT CSpeedView::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	LRESULT lRet = DefWindowProc(uMsg, wParam, lParam);

	SetLimitText(0);

	CRegKey key;			
	if (ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, speedRegKey))
	{
		TCHAR font_name[LF_FACESIZE];
		DWORD font_height, font_weight, charset;
		if (LoadOption(key, font_name, font_height, font_weight, charset)) {
			LOGFONT lf;
			memset(&lf, 0, sizeof(lf));
			lf.lfHeight = font_height;
			lf.lfWeight = font_weight;
			strcpy(lf.lfFaceName, font_name);
			lf.lfCharSet = (BYTE)charset;

			m_font.CreateFontIndirect(&lf);
			m_fontText.CreateFontIndirect(&lf);
			SetFont(m_font);
		}
		else {
			m_font.CreatePointFont(100,"宋体");
			m_fontText.CreatePointFont(100,"宋体");
			SetFont(m_font);
		}
	}


	return 0;
}

LRESULT CSpeedView::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	CRegKey key;			
	if (ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, speedRegKey))
	{
		//TCHAR font_name[LF_FACESIZE];
		//DWORD font_height, font_weight, charset;
		LOGFONT lf;
		m_font.GetLogFont(&lf);

		SaveOption(key, lf.lfFaceName, lf.lfHeight, lf.lfWeight, lf.lfCharSet);
	}

	return 0;
}

LRESULT CSpeedView::OnCtlColorStatic(HDC hdc, HWND hwnd)
{
	::SetBkMode(hdc, TRANSPARENT);
	return (LRESULT) GetStockObject(WHITE_BRUSH);
}

LRESULT CSpeedView::OnEditFont(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	LOGFONT lf, lfnew;
	m_font.GetLogFont(&lf);
	CFontDialog fontdlg(&lf);
	
	if (fontdlg.DoModal() == IDOK) {
		fontdlg.GetCurrentFont(&lfnew);

		HFONT htempft;
		htempft = CreateFontIndirect(&lfnew);
		SetFont(htempft);
		m_font = htempft;
	}
	return 0;
}

LRESULT CSpeedView::OnEditFontLarge(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	LOGFONT lf;
	m_font.GetLogFont(&lf);
	lf.lfHeight -= 1;
	HFONT htempft;
	htempft = CreateFontIndirect(&lf);
	SetFont(htempft);
	m_font = htempft;

	return 0;
}

LRESULT CSpeedView::OnEditFontSmall(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	LOGFONT lf;
	m_font.GetLogFont(&lf);
	lf.lfHeight += 1;
	HFONT htempft;
	htempft = CreateFontIndirect(&lf);
	SetFont(htempft);
	m_font = htempft;
	return 0;
}

void CSpeedView::SetFontPoint(int pt)
{
	LOGFONT lf;
	m_fontText.GetLogFont(&lf);
	HDC hdc = GetDC();
	lf.lfHeight = -MulDiv(pt, GetDeviceCaps(hdc, LOGPIXELSY), 72);
    ReleaseDC(hdc);
	HFONT htempft;
	htempft = CreateFontIndirect(&lf);
	SetFont(htempft);
	m_fontText = htempft;
}

void CSpeedView::SetDefaultFont()
{
	SetFont(m_font);
}

⌨️ 快捷键说明

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