Operation of input method and font

zhaozj2021-02-16  48

(This article is suitable for beginners)

Today this topic mainly surrounds input methods and fonts.

1. First let's talk about how to get the currently used font.

Let's talk about the information of the system storage input method.

Open the registry to HKEY_LOCAL_MACHINE // System // CurrentControlSet // Control // Keyboard Layouts //

There are a lot of folders in this, and each is named at a string of 8 words.

Click any of these, you can see two primary key values, all of the reg_sz type,

One is a Layout file, record the DLL used in the input method,

One is the Chinese name of the Chinese name of the input method.

In fact, the 8-word long string is the ID of this input method.

Know these, let's handle the input method that is currently used.

Let's take a look at a WindAPI function:

Bool getKeyboardLayoutname

LPTSTR PWSZKLID / / INPUT LOCALE Identifier Name

);

This function can easily get the ID of the input method currently being used by the system.

That question is obvious, we have to get the name of the input method corresponding to this ID.

In this way, the registry discussed above will send it to the field.

Because HKEY_LOCAL_MACHINE // System // CurrentControlSet // Control // Keyboard Layouts // All

Some folders are named after the name of the input method ID.

As long as we position the ID of the obtained input method to the folder,

You can get from one of the keys: Layout Text get the Chinese name of the input method

I wrote two functions, used to implement: void getLayouname () // Call directly This function will display the current input method {cstring data; // to save the name cstring id; // to save ID getKeyboardLayoutname (ID .GetBuffer (ID.getLength ()); id.releasebuffer (); Disp = loadimeInfo2000 (ID); // Get the name of the name by ID, below MessageBox (DISP); // Display} cstring cmydilog :: loadimeInfo2000 ( CString p) // Get the current input method name {HKEY HK; CSTRING STR; CSTRING VALUE; STR = "System // CurrentControlSet // CONTROL // Keyboard LayoutS //" / 存 输入 输入 法 信息 信息;;;;;;;;;; p; dword type = reg_sz; if (: regopenkey (hkey_local_machine, str, & hk) == error_suCcess) // Open key {lpbyte lpd = new byte [80]; // DataValue DWORD LPS = 80; // DataSize IF RegQueryValueex (HK, "Layout Text", NULL, & TYPE, LPD, & LPS)! = Error_Success

// Read the information of the layout text, that is, the Chinese name of the input method AFXMessageBox ("query error"); else {value = lpd;} delete lpd;} else afxMessageBox ("Open error"); :: regclosekeyKey (HK); Return Value;} OK, try it, when you run getLayouname () will show the current input method name. II. Below us, how to enumerate the system, this problem is relatively simple, only Need a callback function, enumerate all font information, then display it. There are not many words below,

Write directly to implement the code.

INCLUDE

Char * fname = ""; // Defines a variable to save input method information

INT Callback MenumFontFameXProc (Enumlogfontex * LPelfE, NewTextMellex * LPntMe, unsigned long fonttype, long lparam) // callback function

{

STRCAT (FNAME, (CHAR *) LPELFE-> ELFFULLNAME); // Put all font information into the FNAME, easy to display

STRCAT (FNAME, "/ R / N");

Return 1;

} Void getCharset () // Get the function of the input method, run, as long as the function is called, you will print out the name of all fonts {hw = :: getfocus (); HDC HDC = :: getDC (HW); logfont LF; Memset (& LF, 0, SIZEOF (LF)); lf.lfcharset = default_charset ;: ENUMFONTFAMILIESEX (HDC, & LF, (FontenumProc) MenumfontFameXProc, 0, 0); MessageBox (FNAME); // Display Font Name}

Also introduce a trick, used to open / close the input method, this problem we start directly from the analog buttons,

Everyone knows, pressing Ctrl Space at the same time to turn the input method, then we just simulate this button:

KeyBD_Event (VK_Control, 0, 0); // Press CTRL

KeyBD_Event (vk_space, 0,0,0); // Press the space

KeyBD_Event (vk_control, 0, keyeventf_keyup, 0); // Bringing Ctrl

KeyBD_EVENT (VK_SPACE, 0, KEYEVENTF_KEYUP, 0) // Bringing the space to open / close

If you don't understand, you can communicate through the mailbox:

Zhucde@jxfw.com

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

New Post(0)