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

📄 democode.cpp

📁 democode.cpp是模拟器的主程序参考代码。用户可以通过它了解移植腾凌智能数字中文输入法需要做那些工作。
💻 CPP
字号:
// TenglingSimDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TenglingSim.h"
#include "TenglingSimDlg.h"

#include "tlapi.h"

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

CEdit	*pEditText;
CEdit	*pEditWordList;
CEdit	*pEditInput;
CEdit   *pEditSelectIndex;

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

/////////////////////////////////////////////////////////////////////////////
// CTenglingSimDlg dialog

CTenglingSimDlg::CTenglingSimDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTenglingSimDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTenglingSimDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_pEditFont=new CFont;
	m_pEditFont->CreatePointFont(150,"黑体");
}

void CTenglingSimDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTenglingSimDlg)
	DDX_Control(pDX, IDC_EDIT_SELECTINDEX, m_EditSelectIndex);
	DDX_Control(pDX, IDC_EDIT_TEXTAREA, m_EditText);
	DDX_Control(pDX, IDC_EDIT_WORDLIST, m_EditWordList);
	DDX_Control(pDX, IDC_EDIT_INPUT, m_EditInput);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTenglingSimDlg, CDialog)
	//{{AFX_MSG_MAP(CTenglingSimDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON_2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON_3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON_4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON_5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON_6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON_8, OnButton8)
	ON_BN_CLICKED(IDC_BUTTON_9, OnButton9)
	ON_BN_CLICKED(IDC_BUTTON_0, OnButton0)
	ON_BN_CLICKED(IDC_BUTTON_7, OnButton7)
	ON_BN_CLICKED(IDC_BUTTON_OK, OnButtonOk)
	ON_BN_CLICKED(IDC_BUTTON_BACKSPACE, OnButtonBackspace)
	ON_BN_CLICKED(IDC_BUTTON_UP, OnButtonUp)
	ON_BN_CLICKED(IDC_BUTTON_DOWN, OnButtonDown)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_JING, OnButtonJing)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTenglingSimDlg message handlers

BOOL CTenglingSimDlg::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

	m_EditText.SetFont(m_pEditFont);
	m_EditInput.SetFont(m_pEditFont);
	m_EditWordList.SetFont(m_pEditFont);
	m_EditSelectIndex.SetFont(m_pEditFont);

	pEditText=&m_EditText;
	pEditWordList=&m_EditWordList;
	pEditInput=&m_EditInput;
	pEditSelectIndex=&m_EditSelectIndex;

	TL_Init();

	TL_SetPYShowLength(20);
	TL_SetHZShowLength(20);

	// TODO: Add extra initialization here	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTenglingSimDlg::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 CTenglingSimDlg::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 CTenglingSimDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
void CTenglingSimDlg::OnButton0() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('0');	
}

void CTenglingSimDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('1');
}

void CTenglingSimDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('2');
}

void CTenglingSimDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('3');
}

void CTenglingSimDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('4');	
}

void CTenglingSimDlg::OnButton5() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('5');
}

void CTenglingSimDlg::OnButton6() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('6');
}
void CTenglingSimDlg::OnButton7() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('7');
	
}
void CTenglingSimDlg::OnButton8() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('8');
}

void CTenglingSimDlg::OnButton9() 
{
	// TODO: Add your control notification handler code here
	TL_OnChar('9');
}

void CTenglingSimDlg::OnButtonOk() 
{
	if(!TL_OnKey(TL_KEY_OK_CODE))
	{
		CString oldtext;
		m_EditText.GetWindowText(oldtext);
		m_EditText.SetWindowText(oldtext + "\r\n");
	}
}

void CTenglingSimDlg::OnButtonBackspace() 
{
	// TODO: Add your control notification handler code here
	if(!TL_OnKey(TL_KEY_CANCEL_CODE))
	{
		CString oldtext;
		m_EditText.GetWindowText(oldtext);
		if(oldtext.GetLength()>=2)
			m_EditText.SetWindowText(oldtext.Left(oldtext.GetLength() - 2));
	}
}

void CTenglingSimDlg::OnButtonUp() 
{
	// TODO: Add your control notification handler code here
	TL_OnKey(TL_KEY_UP_CODE);
}

void CTenglingSimDlg::OnButtonDown() 
{
	// TODO: Add your control notification handler code here
	TL_OnKey(TL_KEY_DOWN_CODE);
}

void CTenglingSimDlg::OnDestroy() 
{
	CDialog::OnDestroy();	
	delete m_pEditFont;
	TL_Release();
}

void CTenglingSimDlg::OnButtonJing() 
{
	// TODO: Add your control notification handler code here
	char Path[512];
	int nlen=GetModuleFileName(NULL,Path,512);

	CString fstr(Path,nlen);
	int     npos=fstr.ReverseFind('\\');
	CString helpfilename=fstr.Left(npos + 1) + "help.doc";

	ShellExecute(NULL, "open", helpfilename, NULL, NULL, SW_SHOWNORMAL);
}

/*-----------------------------------------------------------------*/
/* api called by TengLing Pinyin Input module                      */
/* implemented by porting user                                     */
/*-----------------------------------------------------------------*/
void UI_ShowPYList(const char *pylist,int selstart,int selend,int finished)
{
	pEditInput->SetWindowText(pylist);
	pEditInput->SetSel(selstart,selend);
}
void UI_ShowHZList(const char *hzlist,int selstart,int selend,int finished)
{
	pEditWordList->SetWindowText(hzlist);
	pEditWordList->SetSel(selstart,selend);
}
void UI_ShowSelectIndex(const char *str)
{
	pEditSelectIndex->SetWindowText(str);
}
/*------------------------------------------------------------------*/
/* hzstr is the hzstr user selected                                 */
/*------------------------------------------------------------------*/
void UI_SelectHZ(char *hzstr,int hzstrlen)
{
	CString inputhz(hzstr,hzstrlen);
	CString oldtext;
	
	pEditText->GetWindowText(oldtext);
	pEditText->SetWindowText(oldtext + inputhz);
}

⌨️ 快捷键说明

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