A class entered by Chinese

xiaoxiao2021-03-06  41

A Chinese input class does not want the IME to display the default window, just want to use its conversion and selection function, see some of the brothers on the Tiemato Forum, fix some BUG I think, joined a group Control function, make the program to display some Button, players can switch input, full corners, medium / English punctuation without having to use hot keys.

// I don't know if this can solve the problem of indentation #pragma comment (lib, "imm32.lib") #include #include class cime {bool g_bime; // IME Allow flag Char g_szcompstr [MAX_PATH]; // Store converted string char g_szcompreadstr [MAX_PATH]; // Store input string char g_szcandlist [max_path]; // Storage sorted into a string selection word table INT G_NIMECSOR; // Store String after converted The cursor position Candidatelist * g_lpcandlist; // Store standard selection table char g_szimename [64]; // Storage input method name bool g_bimeesharp; // full-width flag BOOL g_bimesymbol; // Chinese punctuation mark Void ConvertCandList (CandidateList * PcandList CHAR * pszcandlist); // Summary of the selected word table into a string public: cime (): g_lpcandlist (null) {Disableime ();} // Initialize some data from DIME () {Disableime (); if (g_lpcandlist ) {GlobalFree ((Handle) g_lpcandlist; g_lpcandlist = null;}} // Control function void disableime (); // Off and disable input method, if IME has been turned on, then the player can't call out IME Void Enableime with hotkeys (); // Allow input method, after which players can call out IME void nextime with hotkeys; / / Switch to the next input method, must be enableime to valid Void Sharpime (HWND HWnd); / / Switch the full-angle / half angle VOID SYMBOLIME (HWND HWND); / / Switching / English branch // Status function char * getimename ); // Get the name of the input method, return null bool ifiMesharp () if the current is English; // is full angle BOOL iFIMESYMBOL (); // Whether Chinese punctuation void getimeInput (char ** pszcompstr, char ** pszcompreadstr, int * PNIMECURSOR, CHAR ** PSZCANDLIST; // Get input method, four pointers can be NULL, this state does not return back // Returns the converted string after PSZCompSTR // Return to keyboard directly Enter the keyboard directly / Returns the cursor position of SZCompstr in PNIMecursor // Returns the selection table in PszcandList, each item is separated // must be called in the message, if returned to True, the window function should return 0, Otherwise, you should pass to DefWindowProc Bool OnWM_INPUTLANGCHANGEREQUEST ();

bool OnWM_INPUTLANGCHANGE (HWND hWnd); bool OnWM_IME_SETCONTEXT () {return true;} bool OnWM_IME_STARTCOMPOSITION () {return true;} bool OnWM_IME_ENDCOMPOSITION () {return true;} bool OnWM_IME_NOTIFY (HWND hWnd, WPARAM wParam); bool OnWM_IME_COMPOSITION (HWND hWnd, LParam lparam);}; void cime :: disableime () {while (importKeyboardLayout (0))) ActivateKeyboardLayout ((hkl) hkl_next, 0); // If IME is opened by looping to the next closure g_bime = false; g_szcompstr [0] = 0; g_szcompreadstr [0] = 0; g_nimecursor = 0; g_szimename [0] = 0; g_szcandlist [0] = 0;} void cime :: enableime () {g_bime = true;} void cime :: NextIme () {if (! g_bIme) return; ActivateKeyboardLayout ((HKL) HKL_NEXT, 0);} void CIme :: SharpIme (HWND hWnd) {ImmSimulateHotKey (hWnd, IME_CHOTKEY_SHAPE_TOGGLE);} void CIme :: SymbolIme (HWND hWnd) { Immsimulatehotkey (hwnd, IME_CHOTKEY_SYMBOL_TOGGLE);} void cime :: converTcandList (CandidateList * pcandlist, char * pszcandlist) // Convert Candidat ELIST to a string, / t separate each {Unsigned Int i; if (pcandlist-> dwselection) {pszcandlist [0] = 0; return;} // Total} // Total number, Microsoft Pinyin The second time to select the word table, then press PageDown, and will exit the selected word status, start a new input // but Microsoft Pinyin's own IME window can solve this problem, it is estimated that Microsoft Pinyin is implemented. More interface, so I use this less standard data // I can't solve this problem now, and I have rarely encountered this in actual use, and other standard input methods will not cause this BUG / / Non-standard input method estimates less interfaces, so it should not cause this bug for (i = 0; (i dwselection) && (i dwagesize); i ) {* pszcandlist = (i% 10! = 9)? I% 10 '1': '0'; // Each of the corresponding digital keys * pszcandlist

= '.'; // use '.' Separate strcpy (pszcandlist, (char *) pcandlist pcandlist-> dwoffset [pcandlist-> dwselection i]); // Each actual content pszcandlist = strlen (pszcandlist) * Pszcandlist = '/ t'; // Idle between '/ T' Separation} * (pszcandlist - 1) = 0; // Central, and override the last '/ t'} BOOL CIME: ONWM_INPUTLANGCHANGEREQUEST If IME is prohibited, if IME is prohibited, the window function should return 0, otherwise DefWindowProc will open the input method} BOOL CIME: ONWM_INPUTLANGCHANGE (HWND HWND) // IME Change {HKL HKL = GetKeyboardLayout (0 ); if (ImmIsIME (hKL)) {hIMC hIMC = ImmGetContext (hWnd); ImmEscape (hKL, hIMC, IME_ESC_IME_NAME, g_szImeName); // get a new input name DWORD dwConversion, dwSentence; ImmGetConversionStatus (hIMC, & dwConversion, & dwSentence); ? g_bImeSharp = (dwConversion & IME_CMODE_FULLSHAPE) true: false; // get the whole angle mark g_bImeSymbol = (dwConversion & IME_CMODE_SYMBOL) true:? false; // get Chinese punctuation mark ImmReleaseContext (hWnd, hIMC);} else // English input g_szImeName [ 0] = 0; Return False; // Always return false because window letters are required DefWindowProc number call processing continues} bool CIme :: OnWM_IME_NOTIFY (HWND hWnd, WPARAM wParam) {HIMC hIMC; DWORD dwSize; DWORD dwConversion, dwSentence; switch (wParam) {case IMN_SETCONVERSIONMODE: // full / half width, / English punctuation change hIMC = ImmGetContext (hWnd); ImmGetConversionStatus (hIMC, & dwConversion, & dwSentence); g_bImeSharp = (dwConversion & IME_CMODE_FULLSHAPE) true: false; g_bImeSymbol = (dwConversion & IME_CMODE_SYMBOL) true:?? false; ImmReleaseContext (hWnd, hIMC); break;

Case IMN_OpenCandidate: // Enter the Selection Status Case IMN_CHANGECANDIDATE: / / Selection Letter Himc = ImmgetContext (HWND); if (g_lpcandlist) {GlobalFree ((Handle) g_lpcandlist); g_lpcandlist = null;} // Release the previous selection word table if (dwSize = ImmGetCandidateList (hIMC, 0, NULL, 0)) {g_lpCandList = (LPCANDIDATELIST) GlobalAlloc (GPTR, dwSize); if (g_lpCandList) ImmGetCandidateList (hIMC, 0, g_lpCandList, dwSize);} // get new selected word table ImmReleaseContext (hWnd, hIMC); if (g_lpCandList) ConvertCandList (g_lpCandList, g_szCandList); // table finishing selected word clusters break; case IMN_CLOSECANDIDATE: // Close the selected word list if (g_lpCandList) {GlobalFree ((HANDLE ) g_lpcandlist); g_lpcandlist = NULL;} // Release g_szcandlist [0] = 0; Break;} return true; // Always return TRUE to prevent IME window from opening} bool cime :: onwm_ime_composition (hwnd hwnd, lparam lparam) / / Enter change {HIMC HIMC; DWORD DWSIZE; HIMC = ImmgetCont ext (hWnd); if (lParam & GCS_COMPSTR) {dwSize = ImmGetCompositionString (hIMC, GCS_COMPSTR, (void *) g_szCompStr, sizeof (g_szCompStr)); g_szCompStr [dwSize] = 0;} // made szCompStr if (lParam & GCS_COMPREADSTR) {dwSize = ImmGetCompositionString (hIMC, GCS_COMPREADSTR, (void *) g_szCompReadStr, sizeof (g_szCompReadStr)); g_szCompReadStr [dwSize] = 0;} // made szCompReadStr if (lParam & GCS_CURSORPOS) {g_nImeCursor = 0xffff & ImmGetCompositionString (hIMC, GCS_CURSORPOS, NULL, 0);} // Get Nimecursor if (LParam & GCS_Resultstr) {Unsigned Char Str [MAX_PATH]; DWSIZE =

转载请注明原文地址:https://www.9cbs.com/read-55896.html

New Post(0)