📄 hikerwbui.cpp
字号:
}
else if ((50 == wParam || 51 == wParam || 52 == wParam || 53 == wParam || 54 == wParam
|| 55 == wParam || 187 == wParam || 189 == wParam) && bCtrlDown)//Control+2,3,4,5,6,7 and '+', new word
{
int loc = GetCurrLoc();
CString csSent = CString(wordstr);
CString csWord;
int lenw = 4 + (wParam-50)*2;
if (wParam <= 55)
{
csWord = csSent.Mid(loc-lenw, lenw);
if (csWord.GetLength() < lenw)
csWord = "";
newWordWnd.m_bNew = TRUE;
}
else if (187 == wParam)
{
csWord = "";
newWordWnd.m_bNew = TRUE;
}
else if (189 == wParam)
{
csWord = csSent.Mid(loc-wordstr[currpos], wordstr[currpos]);
newWordWnd.m_bNew = FALSE;
}
if (csWord == "")
{
newWordWnd.m_csWord = "";
newWordWnd.m_csCode = "";
}
else
{
CString csCode;
GeneCode(csWord, csCode);
newWordWnd.m_csWord = csWord;
newWordWnd.m_csCode = csCode;
}
newWordWnd.UpdateData(FALSE);
newWordWnd.ShowWindow(SW_HIDE);
newWordWnd.ShowWindow(SW_SHOW);
}
else if (192 == wParam && !bShiftDown) //temporary pinyin
{
if (giLastKey == 192)
return TRUE;
if (codelen > 0 && codelen < giMaxCodeLen && code[codelen-1] != 32 ) //code is not full, return
return TRUE;
currpos ++;
memset(code, 0, sizeof(code));
memset(wordlist, 0, sizeof(wordlist));
giPageNo = 0;
selwordnum = 0;
gbTmpPy = TRUE;
editWnd.SetCode((LPCSTR)code);
editWnd.SetWord((LPCSTR)CString("临时拼音"));
//editWnd.SetSent((LPCSTR)wordstr);
if (!editWnd.IsWindowVisible())
ShowFloatStaWnd();
giLastKey = wParam;
}
else if (27 == wParam) //escape key
{
if (27 != giLastKey)
{
if (codelen >= giMaxCodeLen || code[codelen-1] == 32)
{
//delete last input word
DeleteCode(currpos);
DeleteWord(currpos, TRUE);
// currpos --;
// GetCode(currpos, code);
}
currpos --;
memset(code, 0, sizeof(code));
giPageNo = 0;
selwordnum = 0;
gbTmpPy = 0;
memset(wordlist, 0, sizeof(wordlist));
editWnd.SetCode((LPCSTR)code);
editWnd.SetWord((LPCSTR)CString("再次按下Esc键清除内容!"));
editWnd.SetSent((LPCSTR)wordstr, wordslen, wordnum, currpos);
}
else
{
Clean();
}
giLastKey = wParam;
}
else //aplha in English state, or 0~9 digital number, or punctuation
{
CString csKeyName;
if (gbTmpPy)
{
if (codelen > 0)
return TRUE;
else
{
gbTmpPy = TRUE;
currpos --;
}
}
//if is a special key, find its code
if (isalpha(c) && 32 != c) //alpha
{
if (isupper(c))
c = wParam + 32; //!!!note, captical alpha key and lower case alpah key have the same wParam, But 0~9 key and punctuation key have not!
int keyid = GetKeyId(c);
if (!gbChsSta && gbSBCSta)
iSoftKeyboard = 11;
if (bCapsLock && !bShiftDown || !bCapsLock && bShiftDown)//captical
{
if (0 == iSoftKeyboard) //soft pc-keyboard
csKeyName = gKeyArr[iSoftKeyboard*2][keyid*2];
else
csKeyName = CString(gKeyArr[iSoftKeyboard*2][keyid*2]) +
CString(gKeyArr[iSoftKeyboard*2][keyid*2+1]);
}
else //lower letter
{
if (0 == iSoftKeyboard) //soft pc-keyboard
csKeyName = gKeyArr[iSoftKeyboard*2+1][keyid*2];
else
csKeyName = CString(gKeyArr[iSoftKeyboard*2+1][keyid*2]) +
CString(gKeyArr[iSoftKeyboard*2+1][keyid*2+1]);
}
}
else if (48 <= c && c <= 57) //0~9 digital
{
int keyid = GetKeyId(c);
if (gbSBCSta)
iSoftKeyboard = 11;
if (0 == iSoftKeyboard) //soft pc-keyboard
csKeyName = gKeyArr[iSoftKeyboard*2+1][keyid*2];
else
csKeyName = CString(gKeyArr[iSoftKeyboard*2+1][keyid*2]) +
CString(gKeyArr[iSoftKeyboard*2+1][keyid*2+1]);
}
else if ( ispunct(c))
{
int keyid = GetKeyId(c);
if (gbChsPctSta) //Chinses punctuation
{
if (c != 34)
csKeyName = GetChsPunc(c);
else
{
if (gbFirstQuota)
{
csKeyName = "“";
gbFirstQuota = FALSE;
}
else
{
csKeyName = "”";
gbFirstQuota = TRUE;
}
}
}
else //English punctuation state
{
//csKeyName = CString(c);
if (gbSBCSta)
{
iSoftKeyboard = 11;
}
int iKbOffset = 1;
if (IsShPct(c))
iKbOffset = 0;
// if (0 == iSoftKeyboard) //soft pc-keyboard
// csKeyName = gKeyArr[iSoftKeyboard*2][keyid*2];
// else
csKeyName = CString(gKeyArr[iSoftKeyboard*2+iKbOffset][keyid*2]) +
CString(gKeyArr[iSoftKeyboard*2+iKbOffset][keyid*2+1]);
}
}
else if ( 32 == c )
{
int keyid = GetKeyId(c);
if (gbSBCSta) //SBC space
csKeyName = CString(" ");
else
csKeyName = CString(c);
}
//output
if (cslen > 0 || codelen > 0
|| (cslen == 0) && csKeyName.GetLength() >= 2 && !ispunct(c)
|| (cslen == 0) && csKeyName == "“") //from hard keyboard or soft pc-keyboard
{
if (gbFloatWnd && !editWnd.IsWindowVisible()) //show floating state window
{
ShowFloatStaWnd();
}
if (csKeyName != "")
{
if (codelen > 0 )
{
if (codelen < giMaxCodeLen && code[codelen-1] != 32) //current code is not full
{
code[strlen((char*)code)] = 32;
InsertCode(code, currpos);
}
}
(*(pMem+1)) = (HANDLE)0xFFFFFFFF; //////////////////
memset(code, 0, sizeof(code));
FindKeyCode(csKeyName, code);
editWnd.SetCode((LPCSTR)code);
memset(wordlist, 0, sizeof(wordlist));
selwordnum = 1;
giPageNo = 0;
editWnd.SetWord((LPCSTR)csKeyName);
currpos++;
InsertCode(code, currpos);
strcpy((char*)lastwordstr, (char*)wordstr);
memset(wordstr, 0, sizeof(wordstr));
if (!pTranslateProc(codestr, wordstr, codenum, wordnum, codeslen, wordslen))
strcpy((char*)wordstr, (char*)lastwordstr);
if (codenum > 0)
{
CorrSent();
editWnd.SetSent((LPCSTR)wordstr, wordslen, wordnum, currpos);
}
}
}
else
{
if (csKeyName != "")
PostChar(csKeyName, lParam);
// else if (c != 0)
// PostChar(c, lParam);
else
PostKey(wParam, lParam);
//keybd_event(wParam, 0, 0, 0);
//return FALSE;
editWnd.SetWord(""); //usually the word is empty when cslen=0, but some time
} //the word may be used for show some prompt information
giLastKey = wParam;
}
return TRUE;
}
BOOL CreateSubWnd(HWND hWnd)
{
//create makeword window
newWordWnd.Create(IDD_DIALOG_MAKEWORD, NULL);
LPCTSTR cname = AfxRegisterWndClass(0);
//editWnd.Create(cname, "HikerWB", |WS_BORDER|WS_VISIBLE, rect, CWnd::FromHandle(hWnd), 0);
editWnd.CreateEx(WS_EX_LEFT|WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW,
cname, "HikerWBEditWnd",
WS_VISIBLE|WS_POPUP|WS_CLIPSIBLINGS,
0, 0, 0, 0, hWnd, 0, 0);
//note!, hWnd isn't specified as parent, for display the float state window at correct position.
editWnd.SetChsSta(gbChsSta);
editWnd.SetSbcSta(gbSBCSta);
editWnd.SetChsPct(gbChsPctSta);
WNDCLASS ws;
ws.style = 0;
ws.lpfnWndProc = AfxWndProc;
ws.hInstance = AfxGetInstanceHandle();
ws.hIcon = 0;
ws.hCursor = 0;
ws.hbrBackground = 0;
ws.lpszMenuName = 0;
ws.lpszClassName = "HikerWBStateWnd";
ws.cbClsExtra = 0;
ws.cbWndExtra = 0;
BOOL bOK = AfxRegisterClass(&ws);
staWnd.CreateEx(WS_EX_LEFT|WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW,
ws.lpszClassName, "HikerWBStateWnd",
WS_VISIBLE|WS_POPUP|WS_CLIPSIBLINGS,//|WS_DISABLED,
0, 0, 0, 0, hWnd, 0, 0);
staWnd.SetChsSta(gbChsSta);
staWnd.SetSbcSta(gbSBCSta);
staWnd.SetChsPct(gbChsPctSta);
InitHook(editWnd.GetSafeHwnd(), staWnd.GetSafeHwnd());
return TRUE;
}
BOOL DestroySubWnd()
{
editWnd.DestroyWindow();
newWordWnd.DestroyWindow();
EndHook();
return TRUE;
}
//06.3.14
void GetSysParaFromFile()
{
int iFloatWnd, iShowStateWnd;
int iStyle;
CFile file;
try
{
file.Open("sysset.ini", CFile::modeRead);
file.Read(&iStyle, 4);
file.Read(&giCharset, 4);
file.Read(&giSwitchChs, 4);
file.Read(&iFloatWnd, 4);
file.Read(&iShowStateWnd, 4);
file.Close();
}
catch(...)
{
file.Close();
iStyle = 1;
giCharset = 0;
giSwitchChs = 0; //left shift
iFloatWnd = 1;
iShowStateWnd = 1;
}
giMaxCodeLen = ((iStyle == 0)?4:2);
gbFloatWnd = iFloatWnd;
gbShowStateWnd = iShowStateWnd;
pSetStyleProc(GetOutputStyle());
pSetCharSetProc(giCharset);
}
void SaveSysParaToFile()
{
int iStyle = GetOutputStyle();
int iFloatWnd = GetFloatWndStyle();
int iShowStateWnd = IsShowStateWnd();
CFile file;
try
{
file.Open("sysset.ini", CFile::modeCreate|CFile::modeWrite);
file.Write(&iStyle, 4);
file.Write(&giCharset, 4);
file.Write(&giSwitchChs, 4);
file.Write(&iFloatWnd, 4);
file.Write(&iShowStateWnd, 4);
file.Close();
}
catch(...)
{
file.Close();
}
}
//05.11.10
BOOL ShowSoftKeyboard(BOOL bShow, int iKeyboardId)
{
return pShowSoftKeyboardProc(bShow, iKeyboardId);
}
int GetOutputStyle()
{
//GetSysParaFromFile();
return ((giMaxCodeLen == 4)?0:1);
}
void SetOutputStyle(int iStyle)
{
PostSent();
Clean();
giMaxCodeLen = ((iStyle == 0)?4:2);
pSetStyleProc(iStyle);
SaveSysParaToFile();
}
int GetFloatWndStyle()
{
//GetSysParaFromFile();
return ((gbFloatWnd)?1:0);
}
int IsShowStateWnd()
{
//GetSysParaFromFile();
return ((gbShowStateWnd)?1:0);
}
void SetFloatWndStyle(int iStyle)
{
gbFloatWnd = ((iStyle == 1)?TRUE:FALSE);
editWnd.SetFloat(gbFloatWnd);
if (!gbOpenSta)
return;
if (!gbFloatWnd)
{
editWnd.ShowFix();
}
else
{
if (strlen((char*)codestr)>0 || strlen((char*)code)>0)
{
ShowFloatStaWnd();
}
else
{
editWnd.ShowWindow(SW_HIDE);
}
}
SaveSysParaToFile();
}
int GetOutputCharset()
{
//GetSysParaFromFile();
return giCharset;
}
void SetOutputCharset(int iCharset)
{
giCharset = iCharset;
pSetCharSetProc(iCharset);
}
void SetFocusWnd(HWND hWnd)
{
ghFocusWnd = hWnd;
}
void SetChsState(BOOL bState)
{
gbChsSta = bState;
editWnd.SetChsSta(bState);
staWnd.SetChsSta(bState);
if (gbChsSta)
((CHikerWBStartDlg*)AfxGetMainWnd())->ChangeIcon(0);
else
((CHikerWBStartDlg*)AfxGetMainWnd())->ChangeIcon(1);
}
void SetSbcState(BOOL bState)
{
gbSBCSta = bState;
editWnd.SetSbcSta(bState);
staWnd.SetSbcSta(bState);
}
void SetChsPctState(BOOL bState)
{
gbChsPctSta = bState;
editWnd.SetChsPct(bState);
staWnd.SetChsPct(bState);
}
void SetCurrPos(int pos)
{
currpos = pos;
lastpos = -1;
GetCode(currpos, code);
//get the code's corresponding words
memset(wordlist, 0, sizeof(wordlist));
pGetWordsProc(code, codestr, currpos, wordlist, selwordnum);
giPageNo = 0;
CString csWords = TransWords(giPageNo);
editWnd.SetCode((LPCSTR)code);
editWnd.SetWord((LPCSTR)csWords, giPageNo, selwordnum);
editWnd.SetSent((LPCSTR)wordstr, wordslen, wordnum, currpos);
}
void NewWord(CString csCode, CString csWord)
{
pNewWordProc((unsigned char*)(LPCSTR)csCode, (unsigned char*)(LPCSTR)csWord);
}
void DelWord(CString csCode, CString csWord)
{
pDeleteWordProc((unsigned char*)(LPCSTR)csCode, (unsigned char*)(LPCSTR)csWord);
memset(wordstr, 0, sizeof(wordstr));
pTranslateProc(codestr, wordstr, codenum, wordnum, codeslen, wordslen);
//get select words again(by post)
memset(wordlist, 0, sizeof(wordlist));
pGetWordsProc(code, codestr, currpos, wordlist, selwordnum);
giPageNo = 0;
CString csWords = TransWords(giPageNo);
//show select words
editWnd.SetWord((LPCSTR)csWords, giPageNo, selwordnum);
//display translated word stream
CorrSent();
if (codenum > 0)
editWnd.SetSent((LPCSTR)wordstr, wordslen, wordnum, currpos);
}
BOOL GeneCode(CString csWord, CString& csCode)
{
CString code;
pGeneCodeProc((unsigned char*)(LPCSTR)csWord, (unsigned char*)code.GetBuffer(CODELEN));
code.ReleaseBuffer();
csCode = code;
return TRUE;
}
BOOL TrainFromFile()
{
char bigBuff[2048] = "";
CFileDialog dlg(TRUE, "txt", NULL, OFN_ALLOWMULTISELECT|OFN_EXPLORER,
"Text Files (*.txt)|*.txt||", CWnd::GetDesktopWindow());
dlg.m_ofn.lpstrTitle = "打开学习文章";
dlg.m_ofn.lpstrFile = bigBuff;
dlg.m_ofn.nMaxFile = sizeof(bigBuff);
if (dlg.DoModal() == IDCANCEL)
return FALSE;
CString csFileName;
for (POSITION pos = dlg.GetStartPosition(); pos; )
{
csFileName = dlg.GetNextPathName(pos);
pTrainFromFileProc((LPCSTR)csFileName);
}
return TRUE;
}
void SetKeyProcSign(BOOL bSign)
{
//pSetKeyProcSignProc(bSign);
HANDLE* pm = pMem;
pm++;
pm++;
//ResumeThread(*pm);
}
void MoveStateWnd(CRect rect)
{
CRect rt;
staWnd.GetWindowRect(rt);
if (rect != rt)
{
SetWindowPos(staWnd.GetSafeHwnd(), HWND_TOPMOST, -1, -1, -1, -1, SWP_SHOWWINDOW|SWP_NOACTIVATE);
::MoveWindow(staWnd.GetSafeHwnd(), rect.left, rect.top, rect.Width(), rect.Height(), TRUE);
}
}
void HideStateWnd()
{
ShowWindow(staWnd.GetSafeHwnd(), SW_HIDE);
}
//only called by staWnd, implemented by calling editWnd.ReleaseFocus.
void ReleaseFocus()
{
editWnd.ReleaseFocus();
}
void SetSysPara()
{
STARTUPINFO si;
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwX = CW_USEDEFAULT;
si.dwXSize = CW_USEDEFAULT;
PROCESS_INFORMATION pi;
CString csEWHandle;
csEWHandle.Format("00%d", editWnd.GetSafeHwnd());
if (!CreateProcess("hikerwbset.exe", (LPTSTR)(LPCTSTR)csEWHandle, 0, 0, 0, REALTIME_PRIORITY_CLASS, 0, 0, &si, &pi))
{
MessageBox(0, "系统设置程序未能成功启动!", AfxGetAppName(), MB_OK|MB_ICONERROR);
return;
}
// GetSysParaFromFile();
// pSetStyleProc(GetOutputStyle());
// pSetCharSetProc(giCharset);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -