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

📄 wmpropdlg.cpp

📁 本人买的<<VC++项目开发实例>>源代码配套光盘.
💻 CPP
字号:
// WMPropDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WMVC.h"
#include "WMPropDlg.h"
#include "Configration.h"		//for CConfigration
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWMPropDlg property page

IMPLEMENT_DYNCREATE(CWMPropDlg, CPropertyPage)

CWMPropDlg::CWMPropDlg() : CPropertyPage(CWMPropDlg::IDD)
{
	//{{AFX_DATA_INIT(CWMPropDlg)
	m_strLastHit = _T("");
	//}}AFX_DATA_INIT
	m_hIcons[0] = AfxGetApp()->LoadIcon(IDI_BOOKOPEN);
	m_hIcons[1] = AfxGetApp()->LoadIcon(IDI_BOOKCLOSE);
	//增加图标
	m_psp.dwFlags |= PSP_USEHICON;
	//注意必须要PropertySheet和PropertyPage中同时去除PSP_HASHELP才可以。
	m_psp.dwFlags &= ~PSP_HASHELP;
	m_psp.hIcon = m_hIcons[0];
}

CWMPropDlg::~CWMPropDlg()
{
}

void CWMPropDlg::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWMPropDlg)
	DDX_Control(pDX, IDC_LAST_HIT, m_editLastHit);
	DDX_Control(pDX, IDC_HIT_HIST, m_listHitHist);
	DDX_Control(pDX, IDC_COMBO_WORD, m_cmbWord);
	DDX_Control(pDX, IDC_COMBO_ZI, m_cmbZi);
	DDX_Text(pDX, IDC_LAST_HIT, m_strLastHit);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWMPropDlg, CPropertyPage)
	//{{AFX_MSG_MAP(CWMPropDlg)
	ON_CBN_SELCHANGE(IDC_COMBO_ZI, OnSelchangeComboZi)
	ON_CBN_EDITCHANGE(IDC_COMBO_ZI, OnEditchangeComboZi)
	ON_CBN_SETFOCUS(IDC_COMBO_ZI, OnSetfocusComboZi)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWMPropDlg message handlers

BOOL CWMPropDlg::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();

	//
	// 加载single.txt
	//
	extern CWMVCApp theApp;
	//
	//引入一个变量,使得文件操作发生异常的时候
	//也能保证文件关闭。
	//
	CStdioFile *pFileProtectorZ = NULL;
	CStdioFile *pFileProtectorW = NULL;
	try
	{
		CStdioFile fileZi(theApp.GetAppDir() + "zi.txt"
			, CFile::modeRead | CFile::shareDenyWrite | CFile::typeText);
		pFileProtectorZ = &fileZi;
		CString strLine;
		while(fileZi.ReadString(strLine))
		{
			m_cmbZi.AddString(strLine);
		}		
		pFileProtectorZ = NULL;
		fileZi.Close();

		CStdioFile fileWord(theApp.GetAppDir() + "word.txt"
			, CFile::modeRead | CFile::shareDenyWrite | CFile::typeText);		
		pFileProtectorW = &fileWord;
		while(fileWord.ReadString(strLine))
		{
			m_cmbWord.AddString(strLine);
		}
		pFileProtectorW = NULL;
		fileWord.Close();
	}
	catch(CFileException *e)
	{
		e->ReportError();
		e->Delete();
		//下面的代码不用执行,因为catch住异常之后
		//代码就可以正常进行,所以catch之外的接下来的
		//代码完成了对于文件的关闭。
		/*if (NULL != pFileProtectorZ)
		{
			pFileProtectorZ->Close();
		}
		if (NULL != pFileProtectorW)
		{
			pFileProtectorW->Close();
		}*/
	}
	//关闭打开的文件
	if (pFileProtectorW)
		pFileProtectorW->Close();

	if (pFileProtectorZ)
		pFileProtectorZ->Close();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CWMPropDlg::OnSelchangeComboZi() 
{
	int nSel = m_cmbZi.GetCurSel();
	if ( -1 != nSel)
	{
		//同步Word ComboBox
		m_cmbWord.SetCurSel(nSel);
		m_cmbWord.GetWindowText(m_strLastHit);
		//显示到标签上
		UpdateData(FALSE);
	
		//追加到列表框中,如果超过显示区域则滚动
		CRect rect;
		m_listHitHist.GetClientRect(rect);
		int nCount = rect.Height() / m_listHitHist.GetItemHeight(0);
		if (m_listHitHist.GetCount() >= nCount)
		{
			m_listHitHist.DeleteString(0);
		}		
		m_listHitHist.InsertString(-1, m_strLastHit);
		//Select the ZI Combobox
		m_cmbZi.SetEditSel(0, -1);
		//复制到Clipbrd
		m_cmbZi.Copy();
	}	
}

void CWMPropDlg::OnEditchangeComboZi() 
{
	CString strInput;
	m_cmbZi.GetWindowText(strInput);
	int nIndex = m_cmbZi.SelectString(0, strInput);
	OnSelchangeComboZi();
}

void CWMPropDlg::OnSetfocusComboZi() 
{
	extern CConfigration config;
	ActivateKeyboardLayout((HKL)config.m_dwKeyboardLayout, 0);
}

⌨️ 快捷键说明

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