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

📄 askdlg.cpp

📁 能够进行汉字的查询
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// AskDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Ask.h"
#include "AskDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 

#define  RE_CY     1001   //向 RichEditCtrl 控件中增加“成语”
#define  RE_PY     1002	//向 RichEditCtrl 控件中增加“拼音”
#define  RE_BT     1003	//向 RichEditCtrl 控件中增加“标题”
#define  RE_EMAIL  1004
#define  RE_NORMAL  0	//向 RichEditCtrl 控件中增加其他内容

//#define  _DEBUG_AFXMESSAGEBOX_


/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CAskDlg dialog

CAskDlg::CAskDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAskDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAskDlg)
	m_strWORD = _T("");
	m_bShowAllCY = FALSE;
	m_strPY = _T("拼音编码:");
	m_strWB = _T("五笔编码:");
	m_strSpell = _T("");
	m_strREditCY = _T("");
	m_strSpellNum = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_iSelCy    = -1;
	m_strSelSpell = ""; 
	m_bClickSpellListCtrl = false;

	m_bAddDataFlag = true;
}

void CAskDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAskDlg)
	DDX_Control(pDX, IDC_REDIT_CY, m_REditCtrlCY);
	DDX_Control(pDX, IDC_LIST_SPELL, m_listCtrlSpell);
	DDX_Control(pDX, IDC_LIST_CY, m_listCtrlCY);
	DDX_Control(pDX, IDC_EDIT_WORD, m_editWORD);
	DDX_Control(pDX, IDC_STA_WORD, m_staCtlWORD);
	DDX_Text(pDX, IDC_EDIT_WORD, m_strWORD);
	DDV_MaxChars(pDX, m_strWORD, 2);
	DDX_Check(pDX, IDC_CHK_ShowAllCY, m_bShowAllCY);
	DDX_Text(pDX, IDC_STA_PY, m_strPY);
	DDX_Text(pDX, IDC_STA_WB, m_strWB);
	DDX_Text(pDX, IDC_EDIT_SPELL, m_strSpell);
	DDV_MaxChars(pDX, m_strSpell, 8);
	DDX_Text(pDX, IDC_REDIT_CY, m_strREditCY);
	DDX_Text(pDX, IDC_STA_SPELLNUM, m_strSpellNum);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAskDlg, CDialog)
	//{{AFX_MSG_MAP(CAskDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_SETFOCUS(IDC_EDIT_WORD, OnSetfocusEditWord)
	ON_EN_CHANGE(IDC_EDIT_WORD, OnChangeEditWord)
	ON_BN_CLICKED(IDC_BTN_SelFont, OnBTNSelFont)
	ON_BN_CLICKED(IDC_CHK_ShowAllCY, OnCHKShowAllCY)
	ON_WM_CTLCOLOR()
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_CY, OnItemchangedListCy)
	ON_EN_CHANGE(IDC_EDIT_SPELL, OnChangeEditSpell)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_SPELL, OnItemchangedListSpell)
	ON_BN_CLICKED(IDC_BTN_CopyCYList, OnBTNCopyCYList)
	ON_BN_CLICKED(IDC_BTN_CopyR, OnBTNCopyR)
	ON_EN_SETFOCUS(IDC_EDIT_SPELL, OnSetfocusEditSpell)
	ON_NOTIFY(NM_SETFOCUS, IDC_LIST_SPELL, OnSetfocusListSpell)
	ON_NOTIFY(NM_SETFOCUS, IDC_LIST_CY, OnSetfocusListCy)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAskDlg message handlers

BOOL CAskDlg::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_staCtlWORD.SetFontName("宋体")
				.SetFontSize(90)
				.SetFontBold(TRUE)
				.SetText3DHiliteColor(RGB(0,0,255))
				.SetFont3D(TRUE,CLabel::Raised)
				.SetBkColor(RGB(163,239,203),RGB(218,184,216), CLabel::Gradient);

	int i = 0;
	m_listCtrlSpell.InsertColumn(i++,"汉字",LVCFMT_RIGHT,50);
	m_listCtrlSpell.InsertColumn(i++,"五笔(86)",LVCFMT_LEFT,60);
	m_listCtrlSpell.InsertColumn(i++,"五笔(98)",LVCFMT_LEFT,60);
	m_listCtrlSpell.InsertColumn(i++,"拼音编码",LVCFMT_LEFT,60);

	m_listCtrlSpell.SetExtendedStyle( LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);


	
	try
	{
		CString  sDSN="DRIVER=Microsoft Access Driver (*.mdb);SRVR='';DBQ=Info.dat;UID=sa;PWD=";
		m_Database.OpenEx(sDSN,CDatabase::noOdbcDialog);	
		m_Recordset.m_pDatabase=&m_Database;		
	}
	catch(CDBException* pEx)
	{
		pEx = NULL;
		AfxMessageBox(" “汉字查询系统” 无法启动。找不到 “Info.dat” 文件!");
		DestroyWindow();
		return TRUE;
	}
	
	ShowCopyRight();

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

void CAskDlg::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 CAskDlg::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();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CAskDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CAskDlg::OnOK() 
{
	// TODO: Add extra validation here
	return;
	CDialog::OnOK();
}


void CAskDlg::OnChangeEditWord() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
#ifdef _DEBUG_AFXMESSAGEBOX_
	AfxMessageBox("OnChangeEditWord() ");
#endif
	
	UpdateData(TRUE);
	if(m_strWORD.GetLength()!=2)
	{
		m_strWORD.Empty();
		m_editWORD.SetSel(0,-1);
		UpdateData(false);
		return;
	}		
	
	m_bAddDataFlag = true;
	FindWBPY(m_strWORD);

	m_editWORD.SetSel(0,-1);
	m_editWORD.SetFocus();	
}

void CAskDlg::OnBTNSelFont() 
{	
	LOGFONT  lfont;
	::GetObject(GetStockObject(SYSTEM_FONT),sizeof(LOGFONT),&lfont);

	strcpy(lfont.lfFaceName, "宋体");
	CFontDialog  fontDlg(&lfont);
	if(fontDlg.DoModal()==IDOK)
	{
		m_staCtlWORD.SetFont(lfont);
	}	
}

BOOL CAskDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class

#ifdef _DEBUG_AFXMESSAGEBOX_	
	AfxMessageBox("DestroyWindow");
#endif
	
	m_Database.Close();	
	return CDialog::DestroyWindow();
}

void CAskDlg::AddDataToCYListCtrl(CString strWord, BOOL bShowAllCY)
{	
	m_listCtrlCY.DeleteAllItems();
	m_listCtrlCY.SetTextBkColor(RGB(255,255,255));
	if(strWord.IsEmpty ())
	{
		ShowCopyRight();
		GetDlgItem(IDC_STA_CYNUM)->SetWindowText("成语");
		return;
	}
	
	if(bShowAllCY)
	{
		m_strSQL = "Select cy from cyk where cy like '%";	
	}
	else
	{
		m_strSQL = "Select cy from cyk where cy like '";		
	}
	m_strSQL += strWord;
	m_strSQL += "%' Order by cy";

#ifdef _DEBUG_AFXMESSAGEBOX_
	AfxMessageBox(m_strSQL);
#endif

	m_Recordset.Open(CRecordset::forwardOnly,m_strSQL,CRecordset::readOnly);
	int	nItem=0;	
	CString strTemp;
	while( !m_Recordset.IsEOF() )
	{	
		
		m_Recordset.GetFieldValue("cy",strTemp);
		strTemp.TrimRight();	
		m_listCtrlCY.InsertItem(nItem,strTemp);	
		
		m_Recordset.MoveNext();	
		nItem++;
	}
	m_Recordset.Close();
	strTemp.Format("成语:共 %d 条", nItem);	
	if(nItem == 0)
	{
		ShowCopyRight();
	}
	else
	{
		AddDataToCYEdit(m_listCtrlCY.GetItemText(0,0));	
	}	
	GetDlgItem(IDC_STA_CYNUM)->SetWindowText(strTemp);
}

void CAskDlg::OnCHKShowAllCY() 
{	
	m_bShowAllCY = !m_bShowAllCY;
	AddDataToCYListCtrl(m_strWORD,m_bShowAllCY);
}

HBRUSH CAskDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	if((pWnd->GetDlgCtrlID() == IDC_STA_PY)||(pWnd->GetDlgCtrlID() == IDC_STA_WB))
	{		
		CFont		font;
		LOGFONT		lf;
		::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT),sizeof(lf), &lf);
	//	lf.lfItalic = TRUE;
		lf.lfHeight = 15;
		font.CreateFontIndirect(&lf);
		pDC->SelectObject(&font);

		pDC->SetBkMode(TRANSPARENT);   //设置背景透明,输出字符时无背景色
	//	pDC->SetBkColor(RGB(0,282,0));        //设置字体的背景色
		pDC->SetTextColor(RGB(0,0,255));      //设置字体的前景色   
		return CreateSolidBrush(RGB(204,255,255));  //设置控件的颜色 
	}	

	return hbr;
}


void CAskDlg::InsertTextToCYEdit(CString str, int iFlag)
{	
	memset(&m_cf, 0, sizeof(CHARFORMAT));
	m_cf.cbSize = sizeof(CHARFORMAT);
	strcpy(m_cf.szFaceName,"宋体");
	
	if(str.IsEmpty())return;

	switch(iFlag)
	{
	case RE_NORMAL:
		m_cf.yHeight     = 180;     
		m_cf.crTextColor = RGB(0,0,0);
		m_cf.dwMask      = CFM_COLOR|CFM_SIZE|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE;
		m_cf.dwEffects   = CFE_AUTOCOLOR;//CFE_BOLD | CFE_ITALIC |CFE_UNDERLINE;
		break;
		
	case RE_CY:
		m_cf.yHeight     = 340;     
		m_cf.crTextColor = RGB(0,0,255);
		m_cf.dwMask      = CFM_COLOR|CFM_SIZE|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE;
		m_cf.dwEffects   = CFE_BOLD ;
		break;

	case RE_PY:
		m_cf.yHeight     = 350;     
		m_cf.crTextColor = RGB(128,64,64);
		m_cf.dwMask      = CFM_COLOR|CFM_SIZE|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE;
		m_cf.dwEffects   = CFE_BOLD ;

⌨️ 快捷键说明

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