📄 汉字to拼音简写dlg.cpp
字号:
// 汉字to拼音简写Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "汉字to拼音简写.h"
#include "汉字to拼音简写Dlg.h"
#include "High.h"
#ifdef _DEBUG
#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
//{{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()
/////////////////////////////////////////////////////////////////////////////
// CToDlg dialog
CToDlg::CToDlg(CWnd* pParent /*=NULL*/)
: CDialog(CToDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CToDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CToDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CToDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CToDlg, CDialog)
//{{AFX_MSG_MAP(CToDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_REVERSE, OnReverse)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_BN_CLICKED(IDC_HIGH, OnHigh)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CToDlg message handlers
BOOL CToDlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CToDlg::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 CToDlg::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 CToDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/*********************************汉字到拼音*********************************/
//Function :将一个汉字转换为拼音首字母
//Param :srcStr //汉字串
//return :返回拼音首字母
CString CToDlg::GetPYString(CString srcStr)
{
CString strResult = "";
CString sDoubleChar;
int iLen = srcStr.GetLength();
for (int i=0; i<iLen; i=i+2)
{
sDoubleChar = srcStr.Mid(i,2);//获得一个汉字
strResult += GetPYChar(sDoubleChar);
}
return strResult;
}
//Function :转换一个汉字到拼音首字母
//param :srcStr:一个汉字
//return :返回一个拼音首字母
CString CToDlg::GetPYChar(CString srcStr)
{
unsigned char tmp[2]; //必须用无符号的。
tmp[0] = srcStr.GetAt(0);
tmp[1] = srcStr.GetAt(1);
unsigned int i = (short)(tmp[0] - '\0') * 256 + ((short)(tmp[1] - '\0'));
i = i & 0xffff;
if ( i < 0xB0A1) return "*" ;
if ( i < 0xB0C5) return "A" ;
if ( i < 0xB2C1) return "B" ;
if ( i < 0xB4EE) return "C" ;
if ( i < 0xB6EA) return "D" ;
if ( i < 0xB7A2) return "E" ;
if ( i < 0xB8C1) return "F" ;
if ( i < 0xB9FE) return "G" ;
if ( i < 0xBBF7) return "H" ;
if ( i < 0xBFA6) return "J" ;
if ( i < 0xC0AC) return "K" ;
if ( i < 0xC2E8) return "L" ;
if ( i < 0xC4C3) return "M" ;
if ( i < 0xC5B6) return "N" ;
if ( i < 0xC5BE) return "O" ;
if ( i < 0xC6DA) return "P" ;
if ( i < 0xC8BB) return "Q" ;
if ( i < 0xC8F6) return "R" ;
if ( i < 0xCBFA) return "S" ;
if ( i < 0xCDDA) return "T" ;
if ( i < 0xCEF4) return "W" ;
if ( i < 0xD1B9) return "X" ;
if ( i < 0xD4D1) return "Y" ;
if ( i < 0xD7FA) return "Z" ;
return "*";
}
void CToDlg::OnReverse()
{
CString strInput;
GetDlgItemText(IDC_SOURCE,strInput);
if (strInput.IsEmpty())
{
MessageBox("输入不可为空!\n请重新输入!","警告",MB_OK | MB_ICONSTOP);
//设置输入窗口焦点
SetFocusAt(IDC_SOURCE);
return ;
}
else
{
if (!CheckInputStr(strInput))
{
MessageBox("输入包含《GB2312简体中文编码表》以外的汉字或字符!\n请重新输入!","错误",MB_OK | MB_ICONSTOP);
SetFocusAt(IDC_SOURCE);
}
else
{
SetDlgItemText(IDC_RESULT,GetPYString(strInput));//转换程序
GetDlgItem(IDC_SOURCE)->SetFocus();
}
}
}
//Function :设置控件焦点
BOOL CToDlg::SetFocusAt(UINT id)
{
CWnd *p;
p = NULL;
p = GetDlgItem(id);
if (NULL != p)
{
p->SetWindowText("");//clear Text
p->SetFocus();
return TRUE;
}
else
{
return FALSE;
}
}
//Function :检查输入的汉字串的合法性
//param :src :输入中文字串
//return :TRUE :合法输入
// :FALSE :非法输入
BOOL CToDlg::CheckInputStr(CString src)
{
int iLen = src.GetLength();
if (iLen%2 == 0)
{
unsigned char ch;
for (int i=0; i<iLen; i=i+2)
{
ch = (unsigned char)src.GetAt(i);
if (ch <= 0xb0 || ch >= 0xf8) //检验输入的字符是否
{
return FALSE;
}
}
return TRUE;
}
else
{
return FALSE;
}
}
void CToDlg::OnClear()
{
CWnd *p = GetDlgItem(IDC_SOURCE);
p->SetWindowText("");
p->SetFocus();
p = GetDlgItem(IDC_RESULT);
p->SetWindowText("");
}
void CToDlg::OnHigh()
{
// TODO: Add your control notification handler code here
CHigh dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -