VC input method control

Source: Internet
Author: User

Anyone who has used Access knows that Access will automatically switch over the input method when entering table data. If a field needs to enter English, Access will automatically switch to the En input state, for example, if another field needs to enter Chinese characters, the system automatically switches to a Chinese Input state, which greatly facilitates data input.

If the user is provided with intelligent automatic switch of input methods in applications like Access, such applications will not only bring convenience to the user, but also become more professional; in this way, our applications will be more competitive.

Like most system configurations, the input method control is implemented by modifying the corresponding registry key; in this article, we will not describe the specific location of the relevant registry items and descriptions of related items. For the sake of practicality, let's talk about the code. The specific code is as follows:

/**************** File (inputlanguage. h) **************** // inputlanguage. h # ifndef feature # define feature # ifndef Unicode # define strcpy # define u_strcmp strcmp # else # define wcscpy # define wcscmp # endif typedef struct tag_ilnode {tchar ilid [15]; // input method code tchar szname [100]; // the description text tag_ilnode * pnext;} ilnode, * pilnode; Class cinputlanguage {public: cinputlanguage (); ~ Cinputlanguage (); Public: // load all input method int loadil (void) installed in the system; // find the input method pilnode findilbyname (tchar * pname) based on the input method name ); // find the input method pilnode findilbycode (tchar * pcode) based on the input code; // obtain the current input when the Code int getcurrentilcode (tchar * pcode ); // set the current input method int selectil (pilnode PIL); // clear the loaded input method information int clear (void); Private: pilnode m_pilhead ;}; # endif ****************//*** * starts the file (inputlanguage. CPP) * *************** // Inputlanguage. CPP # include "stdafx. H "# include" inputlanguage. H "cinputlanguage: cinputlanguage () {m_pilhead = NULL;} cinputlanguage ::~ Cinputlanguage () {clear ();} int cinputlanguage: loadil (void) {hkey, hkey1; dword cp = 16; tchar Lp [15]; cstring szid; cstring szkeyname, szkeyname1; szkeyname = _ T ("keyboard layout \ preload"); szkeyname1 = _ T ("SYSTEM \ CurrentControlSet \ Control \ keyboard layouts \\"); int I = 1; szid. format (_ T ("% d"), I); DWORD LPT = REG_SZ; If (: regopenkey (HKEY_CURRENT_USER, szkeyname, & hkey) = error_success) {While (: Regqueryvalueex (hkey, szid, null, & LPT, (lpbyte) LP, & CP) = error_success) {cstring sztempname; sztempname = szkeyname1 + (lpctstr) (lptstr) LP; If (regopenkey (HKEY_LOCAL_MACHINE, sztempname, & hkey1) = error_success) {tchar LPD [100]; dword lps = 100; // datasize if (regqueryvalueex (hkey1, _ T ("layout text"), null, & LPT, (lpbyte) LPD, & LPS) = error_success) {pilnode P1, P2; P1 = m_pilhead; p2 = new (ilnode); u_strc PY (P2-> ilid, LP); u_strcpy (P2-> szname, lpd); P2-> pnext = NULL; If (P1) {While (P1-> pnext) {p1 = p1-> pnext;} P1-> pnext = P2;} else {m_pilhead = P2 ;}}:: regclosekey (hkey1); I ++; szid. format (_ T ("% d"), I) ;}:: regclosekey (hkey); If (m_pilhead = NULL) {return-1 ;} else {return 0 ;}} int cinputlanguage: selectil (pilnode PIL) {If (! PIL) {return-1;} HKL; HKL = loadkeyboardlayout (Pil-> ilid, kll_activate); // load input method if (hkl = NULL) {return-2 ;} else {activatekeyboardlayout (hkl, kll_setforprocess); // activation Input Method} return 0;} int cinputlanguage: clear (void) {pilnode P1, P2; P1 = m_pilhead; while (P1) {P2 = p1; P1 = p1-> pnext; Delete (P2);} m_pilhead = NULL; return 0;} pilnode cinputlanguage: findilbyname (tchar * pname) {pilnode p1; P1 = m_pilhead; while (P1) {If (u_strcmp (pname, P1-> szname) = 0) {return P1;} p1 = p1-> pnext ;} return NULL;} pilnode cinputlanguage: findilbycode (tchar * pcode) {pilnode P1; P1 = m_pilhead; while (P1) {If (u_strcmp (pcode, P1-> ilid) = 0) {return P1;} p1 = p1-> pnext;} return NULL;} int cinputlanguage: getcurrentilcode (tchar * pcode) {int nret; nret = getkeyboardlayoutname (PC Ode); If (nret! = 0) {return 0;} else {return-1 ;}} /***************************** // For the cinputlanguage class for instructions, see the example code in this document.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.