輸入法(IME)程式設計(2)

來源:互聯網
上載者:User

有譯的不妥的地方請大家指正,我隨時更改:)

IME Window Class

The "IME" window class is a predefined system global class that defines the appearance and behavior of the standard IME windows. The class is similar to common control classes in that you create a window of this class by using the CreateWindowEx function. Like static controls, an IME window does not respond to user input by itself. Instead, it notifies the IME of user input actions and processes control messages sent to it by the IME or applications to carry out a response to the user action.

IME-aware applications sometimes create their own IME windows using the IME class. This allows the application to take advantage of the default processing of the IME window while having control of the positioning of the window.

 

“IME”視窗類別是一個預定義的系統全域類,它定義了標準IME視窗的外觀與行為。在使用CreateWindowEx函數產生視窗時,這個類與普通的控制項類很相似。像靜態控制項一樣,IME視窗類別自己不響應使用者的輸入。取而代之,它將使用者的輸入操作通知給IME並且處理由IME或者應用程式為了響應使用者行為而發送給它的控制訊息。

       IME感知類型的應用程式有時會應用IME類建立自己的IME視窗。這樣當程式包含有視窗定位控制項時就允許應用程式利用IME視窗的預設資料處理。

 

IME Messages

The system sends IME window messages to the window procedure of the application when certain events occur that affect the IME windows. For example, the system sends the WM_IME_SETCONTEXT message to the application when a window is activated. IME-unaware application pass these messages to the DefWindowProc function which sends them to the corresponding default IME window. IME-aware applications either process these messages or forward them to their own IME windows.

You can direct an IME window to carry out a command, such as change the position of composition window, by using the WM_IME_CONTROL message. The IME notifies the application about changes to the composition string by using the WM_IME_COMPOSITION message and about general changes to the status of the IME windows by sending the WM_IME_NOTIFY message.

 

       當某些能影響IME視窗的事件發生時,系統將嚮應用程式的視窗過程(window procedure)發送IME視窗訊息。例如:當(應用程式的)視窗啟用時系統將嚮應用程式發送WM_IME_SETCONTEXT訊息。IME無感知類型的應用程式會把這些訊息傳遞給DefWindowProc 函數,函數會把它們發送給相應的IME視窗。IME感知型的應用程式也會將這些訊息或者把這些訊息傳遞給自己的IME視窗。

       你可以直接控制IME視窗來執行命令,諸如可以用WM_IME_CONTROL訊息來改變字母組合視窗(composition window,見上文)的位置。IME會使用WM_IME_COMPOSITION訊息來通知應用程式關於字母組合字元串的變化,或用WM_IME_NOTIFY訊息來通知關於IME視窗狀態的常規改變。

 

Input Context

An input context is an internal structure, maintained by the IME, that contains information about the status of the IME and is used by IME windows. By default, the system creates and assigns an input context to each thread. Within the thread, this default input context is a shared resource and is associated with each newly created window.

 

       輸入上下文(Input context)是一個內建結構,由IME來維護,它包含了IME視窗所使用的有關IME狀態的資訊。預設情況下,系統會為每一個線程建立並指定一個輸入上下文。線上程中,這個預設的輸入上下文是一個共用資源,並且將會與每個建立視窗關聯。

 

To retrieve or set information in the IME, an application must first retrieve a handle to the input context associated with a specified window. You retrieve the handle by using the ImmGetContext function. You can use the retrieved handle in subsequent calls to the input method manager functions to retrieve and set IME values, such as the composition window style, the composition style, and the status window position. Once you have finished using the context, you must release it using the ImmReleaseContext function.

 

       要在IME中檢索或設定資訊,應用程式必須首先獲得一個與指定視窗相關聯的輸入內容相關的控制代碼。你可以通過ImmGetContext函數來獲得這個控制代碼。在隨後的IME管理函數調用中,你可以使用這個控制代碼來檢索和設定IME的值,諸如字母組合視窗的風格、字母組合的風格以及狀態視窗的位置等。一旦你完成了內容相關的使用,你就必須使用ImmReleaseContext函數來釋放它。

 

Because the default input context is a shared resource, any changes you make to it apply to all windows in the thread. However, you can override this default behavior by creating and associating your own input context to one or more windows of the thread. The changes you make to your own input context apply only to the windows with which it is associated.

 

       因為預設的輸入上下文是一個共用資源,你對它的任何改變都將應用於線程中的所有視窗。不過,你可以通過為線程中的一個或多個視窗產生並關聯自己的輸入內容相關的方法來重寫預設的行為。(不過,你也可以重寫預設的行為,方法是為線程中的一個或多個視窗產生並關聯自己輸入上下文。)你對自己的輸入上下文所做的改動將僅應用於與其相關的視窗上。

 

You can create an input context by using the ImmCreateContext function. To assign the context to a window, call the ImmAssociateContext function. This function returns a handle to the previously associated input context. If you have not associated an input context with the window before, the returned handle is for the default input context. Typically, you save this handle and later reassociate it with the window when you no longer want to use your own input context.

Once an input context is associated with a window, the system automatically selects that context when the window is activated and receives the input focus. The style and other information in the input context affects subsequent keyboard input for that window, determining whether and how the IME operates.

You must destroy any input context you create before terminating your application. First, you must remove the input context from any association it has with windows in the thread by using the ImmAssociateContext function. Then, call the ImmDestroyContext function.

 

       你可以用調用ImmCreateContext函數來建立一個輸入上下文。要把輸入上下文分配給一個視窗,需要調用ImmAssociateContext函數。這個函數將返回一個控制代碼,這個控制代碼是先前與視窗關聯的輸入內容相關的控制代碼。如果先前沒有輸入上下文與些視窗相關聯,函數將返回的控制代碼將是預設輸入上下文(的控制代碼)。通常,你需要儲存這個控制代碼(預設控制代碼),當你不想再使用自己的輸入上下文時,再把它與視窗重新關聯上。

       在一個輸入上下文與一個視窗關聯後,當視窗被啟用時並且接受輸入焦點時,系統會自動選擇那個上下文。輸入上下文中的格式(style)和其它資訊會影響此視窗隨後的鍵盤輸入——決定IME是否和如何操作。

       在結束應用程式之前,你必須銷毀所有你建立的輸入上下文。首先,你必須使用ImmAssociateContext函數從線程中所有與之有關聯的視窗上移除輸入上下文。然後,調用ImmDestroyContext函數。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.