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

📄 inputmethddlg.cpp

📁 在EVC下的记事本程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// InputMethddlg.cpp : implementation file
//

#include "stdafx.h"
#include "InputMethddlg.h"
#include "NotepadDlg.h"
#include "MyWord.h"

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

/////////////////////////////////////////////////////////////////////////////
// CInputMethddlg dialog

CNotepadDlg * pNotepaddlg = NULL;

_MYINPUTBTN g_Inputbtn[] = {
	{UP, IDB_LETTERRESULT, IDB_LETTERRESULT, {15,1,130,31}},
	{UP, IDB_CHARACTERBAR, IDB_CHARACTERBAR, {184,1,234,31}},
	{UP, IDB_CHARACTERBAR, IDB_CHARACTERBAR, {234,1,284,31}},
	{UP, IDB_CHARACTERBAR, IDB_CHARACTERBAR, {284,1,334,31}},
	{UP, IDB_CHARACTERBAR, IDB_CHARACTERBAR, {334,1,384,31}},
	{UP, IDB_CHARACTERBAR, IDB_CHARACTERBAR, {384,1,434,31}},
	
	{UP, IDB_MOVELEFT, IDB_MOVELEFT, {153,1,184,31}},
	{UP, IDB_MOVERIGHT, IDB_MOVERIGHT, {434,1,465,31}},
	
	{UP, IDB_SIGNUNSEL, IDB_SIGNSEL, {415,35,465,67}},
	{UP, IDB_SIGNUNSEL, IDB_SIGNSEL, {415,73,465,105}},
	
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {15,35,55,55}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {60,35,100,55}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {105,35,145,55}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {150,35,190,55}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {195,35,235,55}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {240,35,280,55}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {285,35,325,55}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {330,35,370,55}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {375,35,415,55}},
	
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {15,60,55,80}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {60,60,100,80}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {105,60,145,80}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {150,60,190,80}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {195,60,235,80}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {240,60,280,80}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {285,60,325,80}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {330,60,370,80}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {375,60,415,80}},
	
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {15,85,55,105}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {60,85,100,105}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {105,85,145,105}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {150,85,190,105}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {195,85,235,105}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {240,85,280,105}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {285,85,325,105}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {330,85,370,105}},
	{UP, IDB_LETTERUNSEL, IDB_LETTERSEL, {375,85,415,105}},
	
	{UP, IDB_BMPSWITCHUNSEL, IDB_BMPSWITCHSEL, {15,106,83,128}},
	{UP, IDB_BMPSWITCHUNSEL, IDB_BMPSWITCHSEL, {113,106,181,128}},
	{UP, IDB_BMPSWITCHUNSEL, IDB_BMPSWITCHSEL, {211,106,279,128}},
	{UP, IDB_BMPSWITCHUNSEL, IDB_BMPSWITCHSEL, {309,106,377,128}},
	{UP, IDB_BMPSWITCHUNSEL, IDB_BMPSWITCHSEL, {407,106,475,128}},
	
};//初始化按钮位置

CInputMethddlg::CInputMethddlg(CWnd* pParent /*=NULL*/)
	: CDialog(CInputMethddlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInputMethddlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
//	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	g_keyswitchflag = 0;
	g_movewinflag = 0;
	
	m_Resultstr = _T("");
	m_letterstr = _T("");
	
	g_rightflag = 0;	//左移右移标志位
	b_pinyinflag = false;	//拼音输入标志
	b_wubiflag = false;		//五笔输入标志
	b_forbidflag = false;	//不允许move
	
	g_onestr = 0;
	g_twostr = 0;
	g_threestr = 0;
	g_fourstr = 0;
	g_fivestr = 0;
}


void CInputMethddlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInputMethddlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CInputMethddlg, CDialog)
	//{{AFX_MSG_MAP(CInputMethddlg)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_LBUTTONUP()
	ON_WM_TIMER()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInputMethddlg message handlers

BOOL CInputMethddlg::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
	SetCursorPos(500,500);
	g_screenwidth = GetSystemMetrics(SM_CXSCREEN);
	g_screenheight = GetSystemMetrics(SM_CYSCREEN) - 142;
	
	pNotepaddlg = new CNotepadDlg;
	
	HWND pNotepadhwnd = ::FindWindow(_T("PVNotepad"), NULL);
	pNotepaddlg->m_hWnd = pNotepadhwnd;
	InitResource();
	this->SetWindowPos(&this->wndTopMost,0,142,g_screenwidth,g_screenheight,0);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CInputMethddlg::InitResource()
{
	bitmapback.LoadBitmap(IDB_INPUTBACK);
	CharacterBar.LoadBitmap(IDB_CHARACTERBAR);
	LetterResultbmp.LoadBitmap(IDB_LETTERRESULT);
	LetterSel.LoadBitmap(IDB_LETTERSEL);
	LetterUnsel.LoadBitmap(IDB_LETTERUNSEL);
	BigKeySel.LoadBitmap(IDB_BMPSWITCHSEL);
	BigKeyUnsel.LoadBitmap(IDB_BMPSWITCHUNSEL);
	MoveLeftSel.LoadBitmap(IDB_MOVELEFT);
	MoveLeftUnsel.LoadBitmap(IDB_MOVELEFT);
	MoveRightUnsel.LoadBitmap(IDB_MOVERIGHT);
	MoveRightSel.LoadBitmap(IDB_MOVERIGHT);
	SignSel.LoadBitmap(IDB_SIGNSEL);
	SignUnsel.LoadBitmap(IDB_SIGNUNSEL);
}

void CInputMethddlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CDialog::OnPaint() for painting messages
}

BOOL CInputMethddlg::OnEraseBkgnd(CDC * pDC)
{
	CDC memDC,tempDC;
	memDC.CreateCompatibleDC(pDC);
	tempDC.CreateCompatibleDC(pDC);
	
	CBitmap membitmap;
	membitmap.CreateCompatibleBitmap(pDC, g_screenwidth, g_screenheight);
	CBitmap * pOldbitmap = memDC.SelectObject(&membitmap);
	CBitmap * tOldbitmap = tempDC.SelectObject(&bitmapback);
	memDC.BitBlt(0, 0, g_screenwidth, g_screenheight, &tempDC, 0, 0, SRCCOPY);
	tempDC.SelectObject(tOldbitmap);
	tempDC.DeleteDC();
	for (int i = 0; i < INPUT_BTNEND; i++)
	{
		CBitmap * btnbitmap = NULL;
		int left,top,right,bottom;
		if (i >= INPUT_BTNONE && i <= INPUT_BTNFIVE)
		{	
			right = 50;
			bottom = 30;
			if (UP == g_Inputbtn[i].nstatus)
				btnbitmap = &CharacterBar;
			else
				btnbitmap = &CharacterBar;
		}
		else if (i == INPUT_BTNRESULT)
		{
			right = 115;
			bottom = 30;
			if (UP == g_Inputbtn[i].nstatus)
				btnbitmap = &LetterResultbmp;
			else
				btnbitmap = &LetterResultbmp;
		}
		else if(i == INPUT_BTNLEFT || i == INPUT_BTNRIGHT)
		{
			right = 31;
			bottom = 29;
			if (i == INPUT_BTNLEFT)
			{
				if (UP == g_Inputbtn[i].nstatus)
					btnbitmap = &MoveLeftUnsel;
				else
					btnbitmap = &MoveLeftSel;
			}
			else
				if (UP == g_Inputbtn[i].nstatus)
					btnbitmap = &MoveRightUnsel;
				else
					btnbitmap = &MoveRightSel;
		}
		else if (i == INPUT_BTNBACKSPACE || i == INPUT_BTNENTER)
		{
			right = 50;
			bottom = 32;
			if (UP == g_Inputbtn[i].nstatus)
				btnbitmap = &SignUnsel;
			else
				btnbitmap = &SignSel;
		}
		else if (i >= INPUT_BTNMOVEWIN && i <= INPUT_BTNEXIT)
		{
			right = 65;
			bottom = 20;
			if (UP == g_Inputbtn[i].nstatus)
				btnbitmap = &BigKeyUnsel;
			else
				btnbitmap = &BigKeySel;
		}
		else
		{
			right = 40,
			bottom = 20;
			if (UP == g_Inputbtn[i].nstatus)
				btnbitmap = &LetterUnsel;
			else
				btnbitmap = &LetterSel;
		}
		left = g_Inputbtn[i].rectbtn.left;
		top = g_Inputbtn[i].rectbtn.top;

		CDC btnmemDC;
		btnmemDC.CreateCompatibleDC(&memDC);
		CBitmap * pBtnbitmap = btnmemDC.SelectObject(btnbitmap);
		if (i >= INPUT_BTNMOVEWIN && i <= INPUT_BTNEXIT)
			TransparentImage(memDC.GetSafeHdc(),left,top,right,bottom,
			btnmemDC.GetSafeHdc(),0,0,right,bottom,btnmemDC.GetPixel(1,1));
		else
			memDC.BitBlt(left, top, right, bottom, &btnmemDC, 0, 0, SRCCOPY);
		btnmemDC.SelectObject(pBtnbitmap);
		btnmemDC.DeleteDC();
		
		DrawKeyTextToBack(i, &memDC);
		
	}
	
	pDC->BitBlt(0, 0, g_screenwidth, g_screenheight, &memDC, 0, 0, SRCCOPY);
	memDC.SelectObject(pOldbitmap);
	membitmap.DeleteObject();
	memDC.DeleteDC();

	return true;
}

int CInputMethddlg::GetBtnIDFromPoint(POINT pt)
{
	for (int i = 0; i < INPUT_BTNEND; i++)
	{
		if (PtInRect(&g_Inputbtn[i].rectbtn, pt))
			break;
	}
	
	return i;
}

void CInputMethddlg::DrawKeyTextToBack(int nID, CDC * pDC)
{
	unsigned short ptext[80] = {0};
	RECT rectex = g_Inputbtn[nID].rectbtn;
	if (nID >= INPUT_BTNLETA && nID <= INPUT_BTNSWITCH)
		rectex.top += 2;
	else if (nID >= INPUT_BTNMOVEWIN && nID <= INPUT_BTNEXIT)
		rectex.top += 3;
	else
		rectex.top += 6;
	//	rectex.left += 4;
	COLORREF color = RGB(0,0,0);
	
	if (nID == INPUT_BTNBACKSPACE)
		wcscpy(ptext,_T("CE"));
	else if (nID == INPUT_BTNENTER)
		wcscpy(ptext,_T("Enter"));
	else if (nID == INPUT_BTNMOVEWIN)
		wcscpy(ptext,_T("移动"));
	else if (nID == INPUT_BTNPINYIN)
		wcscpy(ptext,_T("拼音"));
	else if (nID == INPUT_BTNBLANK)
		wcscpy(ptext,_T("空格"));
	else if (nID == INPUT_BTNSIGN)
		wcscpy(ptext,_T("数字符号"));
	else if (nID == INPUT_BTNEXIT)
		wcscpy(ptext,_T("隐藏"));
	else if (nID == INPUT_BTNONE)
	{	
		if (0 == g_onestr)
			wcscpy(ptext, _T(""));
		else
		{
			CString onestr;
			onestr.Format(_T("%s %c"), _T("1."), g_onestr);
			wcscpy(ptext, onestr);
		}
	}	
	else if (nID == INPUT_BTNTWO)
	{
		if (0 == g_twostr)
			wcscpy(ptext, _T(""));
		else
		{
			CString twostr;
			twostr.Format(_T("%s %c"), _T("2."), g_twostr);
			wcscpy(ptext, twostr);
		}	
	}
	else if (nID == INPUT_BTNTHREE)
	{	
		if (0 == g_threestr)
			wcscpy(ptext, _T(""));
		else
		{
			CString threestr;
			threestr.Format(_T("%s %c"), _T("3."), g_threestr);
			wcscpy(ptext, threestr);
		}
	}
	else if (nID == INPUT_BTNFOUR)
	{	
		if (3 >= g_fourstr)
			wcscpy(ptext, _T(""));
		else
		{
			CString fourstr;
			fourstr.Format(_T("%s %c"), _T("4."), g_fourstr);
			wcscpy(ptext, fourstr);
		}
	}
	else if (nID == INPUT_BTNFIVE)
	{	
		if (0 == g_fivestr)
			wcscpy(ptext, _T(""));
		else
		{
			CString fivestr;
			fivestr.Format(_T("%s %c"), _T("5."), g_fivestr);
			wcscpy(ptext, fivestr);
		}
	}

	else if (nID == INPUT_BTNRESULT)
	{
		if (0 == m_letterstr.GetLength() || m_letterstr.GetLength() >= 80)
			wcscpy(ptext,_T(""));
		else
			wcscpy(ptext,m_letterstr);
	}	

	
	if (0 == g_keyswitchflag)			//选小写时的键盘
	{
		if (nID >= INPUT_BTNLETA && nID <= INPUT_BTNLETZ)
		{
			char ch = 'a' + nID - INPUT_BTNLETA;
			CString str = ch;
			wcscpy(ptext, str);
		}
		else if (nID == INPUT_BTNSWITCH)
			wcscpy(ptext, _T("abc"));
		
	}
	else if (1 == g_keyswitchflag)		//大写键盘
	{
		if (nID >= INPUT_BTNLETA && nID <= INPUT_BTNLETZ)
		{
			char ch = 'A' + nID - INPUT_BTNLETA;
			CString str = ch;
			wcscpy(ptext, str);
		}
		else if (nID == INPUT_BTNSWITCH)
			wcscpy(ptext,_T("ABC"));
	}
	
	DrawTextToBack(pDC, 16,6,rectex.left,rectex.top,rectex.right,rectex.bottom,
		color, DT_CENTER|DT_SINGLELINE,ptext,PVGPS_FONT_SELECTED);
}

void CInputMethddlg::OnBtnSign()
{
	g_rightflag = 0;
	b_pinyinflag = false;
	m_Resultstr.Empty();
	m_letterstr.Empty();
	g_onestr = g_twostr = g_threestr = g_fourstr = g_fivestr = 0;
	
	m_Resultstr = _T(",。:;、?—()【】{}‘’“”《》…0123456789.[]<>+-*/@#¥%$~·\\|_");
	g_onestr = m_Resultstr.GetAt(0);
	g_twostr = m_Resultstr.GetAt(1);
	g_threestr = m_Resultstr.GetAt(2);
	g_fourstr = m_Resultstr.GetAt(3);
	g_fivestr = m_Resultstr.GetAt(4);
}

void CInputMethddlg::OnBtnMoveLeft()
{

	if (g_rightflag <= 0)
		return ;
	else
	{
		g_rightflag --;
		int ncount = g_rightflag*5; 
		g_onestr = m_Resultstr.GetAt(0+ncount);
		g_twostr = m_Resultstr.GetAt(1+ncount);
		g_threestr = m_Resultstr.GetAt(2+ncount);
		g_fourstr = m_Resultstr.GetAt(3+ncount);
		g_fivestr = m_Resultstr.GetAt(4+ncount);

	}
}

void CInputMethddlg::OnBtnMoveRight()
{	

	int len = m_Resultstr.GetLength();	
	if (0 == len)		//字符串为空则返回
		return ;
	else
	{
		int i = len%5;		//整除5之后的余位
		
		g_rightflag ++;
		int ncount = g_rightflag*5;		//需要得到的字符的位置

		if (g_rightflag > len/5)
		{	
			g_rightflag = len/5;
			return ;		
		}

		if (0 == i)  //可以5被整除
		{
			if (g_rightflag == len/5)
				return ;

			g_onestr = m_Resultstr.GetAt(0+ncount);
			g_twostr = m_Resultstr.GetAt(1+ncount);
			g_threestr = m_Resultstr.GetAt(2+ncount);
			g_fourstr = m_Resultstr.GetAt(3+ncount);
			g_fivestr = m_Resultstr.GetAt(4+ncount);
		}	//
		else
		{		

			if (g_rightflag == len/5)
			{
				switch(i)
				{
				case 1:
					g_onestr = m_Resultstr.GetAt(0+ncount);
					g_twostr = 0;
					g_threestr = 0;
					g_fourstr = 0;
					g_fivestr = 0;
					break;
				case 2:
					g_onestr = m_Resultstr.GetAt(0+ncount);
					g_twostr = m_Resultstr.GetAt(1+ncount);
					g_threestr = 0;
					g_fourstr = 0;
					g_fivestr = 0;
					break;
				case 3:
					g_onestr = m_Resultstr.GetAt(0+ncount);
					g_twostr = m_Resultstr.GetAt(1+ncount);
					g_threestr = m_Resultstr.GetAt(2+ncount);
					g_fourstr = 0;
					g_fivestr = 0;
					break;
				case 4:
					g_onestr = m_Resultstr.GetAt(0+ncount);
					g_twostr = m_Resultstr.GetAt(1+ncount);
					g_threestr = m_Resultstr.GetAt(2+ncount);
					g_fourstr = m_Resultstr.GetAt(3+ncount);
					g_fivestr = 0;
					break;
				}
				return ;
			}	
			else
			{
				g_onestr = m_Resultstr.GetAt(0+ncount);

⌨️ 快捷键说明

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