📄 t9dlg.cpp
字号:
// T9Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "T9.h"
#include "T9Dlg.h"
#include "T9Dispose.h" //自定义头文件
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CDispose *pT9input;
/////////////////////////////////////////////////////////////////////////////
// CT9Dlg dialog
CT9Dlg::CT9Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CT9Dlg::IDD, pParent)
{
pT9input = new CDispose();
pMain = pParent;
m_bIsShow = false;
pFont1 = new CFont();
pFont2 = new CFont();
m_iCursorStart = 0;
m_iCursorEnd = 0;
m_strShowWord.Empty();
pFont1->CreateFont(14,0,0,0,700,0,0,0,ANSI_CHARSET,
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,_T("arial"));
pFont2->CreateFont(12,0,0,0,700,0,0,0,ANSI_CHARSET,
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,_T("宋体"));//宋体
//{{AFX_DATA_INIT(CT9Dlg)
// 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 CT9Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX,IDC_EDIT1,m_strShowWord);
DDX_Control(pDX,IDC_LIST1,m_CListBox);
DDX_Control(pDX,IDC_EDIT1,m_CEdit);
DDX_Control(pDX, IDC_BUTTON1, m_btn1);
DDX_Control(pDX, IDC_BUTTON2, m_btn2);
DDX_Control(pDX, IDC_BUTTON3, m_btn3);
DDX_Control(pDX, IDC_BUTTON4, m_btn4);
DDX_Control(pDX, IDC_BUTTON5, m_btn5);
DDX_Control(pDX, IDC_BUTTON6, m_btn6);
DDX_Control(pDX, IDC_BUTTON7, m_btn7);
DDX_Control(pDX, IDC_BUTTON8, m_btn8);
DDX_Control(pDX, IDC_BUTTON9, m_btn9);
DDX_Control(pDX, IDC_BUTTON10, m_btn10);
DDX_Control(pDX, IDC_BUTTON11, m_btn11);
DDX_Control(pDX, IDC_BUTTON12, m_btn12);
// DDX_Control(pDX, IDC_BTN_LEFT, m_btnDel);
// DDX_Control(pDX, IDC_BTN_EXIT, m_btnExit);
// DDX_Control(pDX, IDC_BTN_CLEAR, m_btnClear);
//{{AFX_DATA_MAP(CT9Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CT9Dlg, CDialog)
//{{AFX_MSG_MAP(CT9Dlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
ON_BN_CLICKED(IDC_BUTTON12, OnButton12)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_WM_LBUTTONDOWN()
ON_BN_CLICKED(IDC_BUTTON13, OnButton13)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CT9Dlg message handlers
BOOL CT9Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
//使程序同时只能运行一次//////////////////////////////////////////////////////////
m_hOneInstance = ::CreateMutex(NULL,false,_T("T9"));
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
AfxMessageBox(_T("程序已经运行!"));
CloseHandle(m_hOneInstance);
OnCancel();
//return false;
}
m_CListBox.SetFont(pFont1);
m_CEdit.SetFont(pFont2);
CRect rt;
GetClientRect(&rt);
rt.left = 72;
rt.top = 245;
rt.right = 160;
pT9input->InitDispose(&rt,this);
pRt = pT9input->GetDisposeRect();
// ExchangeRect(this);
return TRUE; // return TRUE unless you set the focus to a control
}
void CT9Dlg::ExchangeRect(CWnd *pWnd)
{
CRect OutRect,oRect;
pWnd->GetWindowRect(OutRect);
oRect =ExchangeRect(OutRect);
pWnd->MoveWindow(oRect,TRUE);
CWnd* pBt= pWnd->GetWindow(GW_CHILD);
while (pBt)
{
pBt->GetWindowRect(oRect);
oRect =ExchangeRect(oRect,OutRect);
pBt->MoveWindow(oRect,TRUE);
pBt = pBt->GetNextWindow();
}
}
//自交换
CRect CT9Dlg::ExchangeRect(CRect Rect)
{
CRect OutRect;
OutRect.left=Rect.top;
OutRect.top=Rect.left;
OutRect.right=Rect.top+Rect.Height();
OutRect.bottom=Rect.left+Rect.Width();
return OutRect;
}
//外部界面中270度旋转内部窗口
CRect CT9Dlg::ExchangeRect(CRect Rect,CRect OutRect)
{
CRect rc;
rc.top= Rect.left -OutRect.left+OutRect.top;
rc.left=OutRect.left+OutRect.Height()+OutRect.top-Rect.top;
rc.bottom= Rect.right -OutRect.left+OutRect.top;
rc.right=OutRect.left+OutRect.Height()+OutRect.top-Rect.bottom;
rc.NormalizeRect();
return rc;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//自定义函数
///////////////////////////////////////////////////////////////////////////////////////////////////
void CT9Dlg::SetShow(void)
{
CString Temp = _T(""),TempWord = _T("");
if(pT9input->T9Type == 0)
{
m_strShowWord.Insert(m_iCursorStart,pT9input->GetResult());
//m_strShowWord += pT9input->GetResult();
m_iCursorStart++;
m_iCursorEnd = m_iCursorStart;
return;
}
if(pT9input->T9Type == 1)
{
m_bIsShow = true;
InvalidateRect(pRt); //重刷汉字显示区域
UpdateWindow();
return;
}
if(pT9input->m_iPYNum <= 0)
{
m_bIsShow = false;
InvalidateRect(pRt); //重刷汉字显示区域
return ;
}
m_CListBox.ResetContent();
if(m_bIsShow == false)
{
m_bIsShow = true;
pT9input->pControl->ShowCStatic();
m_CListBox.ShowWindow(SW_SHOW);
}
int num = pT9input->m_iPYNum;
for(int i=0;i<num;i++)
{
Temp = pT9input->GetEngWord(i);
m_CListBox.AddString(Temp);
}
m_CListBox.SetCurSel(0);
m_CListBox.SetFocus();
m_CListBox.GetText(0,Temp);
TempWord = pT9input->GetChiWord(Temp);
pT9input->DelControl();
pT9input->SetControl(TempWord);
InvalidateRect(pRt); //重刷汉字显示区域
}
void CT9Dlg::GetEditFocus(void)
{
m_CEdit.GetSel(m_iCursorStart,m_iCursorEnd);
}
void CT9Dlg::SetEditFocus(void)
{
m_CEdit.SetFocus();
m_CEdit.SetSel(m_iCursorStart,m_iCursorEnd);
}
void CT9Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
pT9input->ConfigT9('1');
SetShow();
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton2()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('2');
SetShow();
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton3()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('3');
SetShow();
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton4()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('4');
SetShow();
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton5()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('5');
SetShow();
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton6()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('6');
SetShow();
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton7()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('7');
SetShow();
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton8()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('8');
SetShow();
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton9()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('9');
SetShow();
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton10()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('*');
if(m_CListBox.IsWindowVisible())
{
m_CListBox.ShowWindow(SW_HIDE);
}
InvalidateRect(pRt); //重刷汉字显示区域
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton11()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9('0');
m_strShowWord.Insert(m_iCursorStart,pT9input->GetResult());
m_iCursorStart++;
m_iCursorEnd = m_iCursorStart;
UpdateData(false);
SetEditFocus();
}
void CT9Dlg::OnButton12()
{
// TODO: Add your control notification handler code here
GetEditFocus();
pT9input->ConfigT9(_T('#'));
int type = pT9input->T9Type;
switch(type)
{
case 0:
{
pT9input->Del123All();
if(m_CListBox.IsWindowVisible())
{
m_CListBox.ShowWindow(SW_HIDE);
}
if(pT9input->pControl->m_bIsShow)
{
pT9input->pControl->HideCStatic();
}
}
break;
case 1:
{
pT9input->DelABC();
if(pT9input->pControl->m_bIsShow)
{
pT9input->pControl->HideCStatic();
}
}
break;
case 2:
{
if(pT9input->pControl->m_bIsShow)
{
pT9input->pControl->HideCStatic();
}
pT9input->DelT9All();/*>DelInputWord();*/
SetShow();
}
break;
default:
break;
}
UpdateData(false);
m_CEdit.SetFocus();
m_CEdit.SetSel(m_iCursorStart,m_iCursorEnd);
}
void CT9Dlg::OnSelchangeList1()
{
// TODO: Add your control notification handler code here
GetEditFocus();
CString strTemp = _T(""),strTempWord = _T("");
int index = m_CListBox.GetCurSel();
m_CListBox.GetText(index,strTemp);
strTempWord = pT9input->GetChiWord(strTemp);
pT9input->DelControl();
pT9input->SetControl(strTempWord);
InvalidateRect(pRt); //重刷汉字显示区域
UpdateData(false);
m_CEdit.SetFocus();
m_CEdit.SetSel(m_iCursorStart,m_iCursorEnd);
}
void CT9Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(point.x > pRt.left && point.y > pRt.top && point.x < pRt.right && point.y < pRt.bottom)
{
GetEditFocus();
CString strTemp;
strTemp = pT9input->SelectData(point);
if(!strTemp.IsEmpty()/*!=_T("")*/)
{
m_strShowWord.Insert(m_iCursorStart,strTemp);
m_iCursorStart++;
m_iCursorEnd = m_iCursorStart;
m_bIsShow = false;
m_CListBox.ShowWindow(SW_HIDE);
pT9input->pControl->HideCStatic();
}
UpdateData(false);
InvalidateRect(pRt); //重刷汉字显示区域
m_CEdit.SetFocus();
m_CEdit.SetSel(m_iCursorStart,m_iCursorEnd);
}
CDialog::OnLButtonDown(nFlags, point);
}
void CT9Dlg::OnButton13()
{
// TODO: Add your control notification handler code here
GetEditFocus();
if((pT9input->pControl->m_bIsShow == true) && (m_CListBox.IsWindowVisible() == false))
{
pT9input->pControl->HideCStatic();
m_CEdit.SetFocus();
m_CEdit.SetSel(m_iCursorStart,m_iCursorEnd);
return ;
}
if((m_CListBox.IsWindowVisible() == false) && (m_strShowWord.IsEmpty() == false /*!= _T("")*/))
{
int count = m_strShowWord.GetLength();
CString strTemp = m_strShowWord.Mid(m_iCursorEnd-1,1);//.Right(1);
m_iCursorStart -= 1;
m_iCursorEnd = m_iCursorStart;
m_strShowWord.Delete(m_iCursorStart,1);
UpdateData(false);
m_CEdit.SetFocus();
m_CEdit.SetSel(m_iCursorStart,m_iCursorEnd);
return ;
}
int type = pT9input->T9Type;
switch(type)
{
case 0:
pT9input->Del123Input();
break;
case 1:
pT9input->pControl->HideCStatic();
break;
case 2:
{
pT9input->DelInputWord();
SetShow();
int index = pT9input->m_iPYNum;
if(index <= 0)
{
pT9input->DelT9All();
pT9input->pControl->HideCStatic();
m_CListBox.ShowWindow(SW_HIDE);
m_bIsShow = false;
}
}
break;
default:
break;
}
InvalidateRect(pRt); //重刷汉字显示区域
UpdateData(false);
m_CEdit.SetFocus();
m_CEdit.SetSel(m_iCursorStart,m_iCursorEnd);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -