Download the source code
In Windows Mobile, Software Input Panel is a method to input characters like keyboard. The Windows Mobile provides several input methods by default, Keyboard, Block Recognizer, Letter Recognizer, Symbol Pad, Transcriber, etc… We can also create our own SIP. The component that provides this facility is call Input Method. It is a COM component that exposes the IInputMethod and IInputMethod2 interface. To create our own SIP, we have to create COM in-proc component and implement the IInputMethod and optionally IInputMethod2 interface.
The SIP contains two major components, Input Panel and Input Method. The Input Panel is created and maintained by the system. Input Method is the pluggable component of the SIP and is responsible for recognizing and transcribing the strokes and taps from the SIP window which will be child windows of the Input Panel.
To create out own SIP, we have to implement the IInputMethod interface. Using this interface’s methods, we have to create our input window and process the strokes and taps. The IInputMethod interface has the following methods:
The Select is called when the user chooses the Input Method from the list. In this function we have to create our child window and initialize any other variable. The Deselect method is called when the user chooses another Input Method, here we destroy the child window and perform cleanup.
The Showing and Hiding will be called when the Input Method is about to show and hide respectively. The
The cbSize should contain the size of the structure. The hImageNarrow and hImageNarrow variables should be filled with the handle to the image list that contains the image to be displayed on the task bar of the SIP button. The iNarrow and iWide variables should contain the index of the images in the image list. The fdwFlags variable is to specify the nature of or SIP, a combination of the flags SIPF_ON, SIPF_DOCKED, SIPF_LOCKED, and SIPF_DISABLECOMPLETION. The rcSipRect variable should be filled with the default rectangle of the SIP window. Normally we take the rectangle of the parent window.
The method ReceiveSipInfo is called when the SIP is shown and when the state of the SIP is changed. The RegisterCallback method is called only once and with one parameter, a pointer to IIMCallback interface. This interface provides methods to send characters, virtual key codes and strings to the Input Panel. The GetImData and SetImData methods is used to provide additional information about the SIP to the Input Panel. The UserOptionsDlg method is to display Options Dialog. This method is not called by the Input Panel, but by the control panel applet. This Input Method should display an Options dialog to configure the SIP.
The prototypes of the methods are:
HRESULT STDMETHODCALLTYPE Select(HWND hWndSip);
HRESULT STDMETHODCALLTYPE Deselect(void);
HRESULT STDMETHODCALLTYPE Showing(void);
HRESULT STDMETHODCALLTYPE Hiding(void);
HRESULT STDMETHODCALLTYPE GetInfo(IMINFO __RPC_FAR *pimi);
HRESULT STDMETHODCALLTYPE ReceiveSipInfo(SIPINFO __RPC_FAR *psi);
HRESULT STDMETHODCALLTYPE RegisterCallback(IIMCallback __RPC_FAR *lpIMCallback);
HRESULT STDMETHODCALLTYPE GetImData(DWORD dwSize, LPVOID pvImData);
HRESULT STDMETHODCALLTYPE SetImData(DWORD dwSize, LPVOID pvImData);
HRESULT STDMETHODCALLTYPE UserOptionsDlg(HWND hwndParent);
The IIMCallback interface has the following methods:
HRESULT STDMETHODCALLTYPE SetImInfo(IMINFO __RPC_FAR *pimi)
HRESULT STDMETHODCALLTYPE SendVirtualKey(BYTE bVK,DWORD dwFlags)
HRESULT STDMETHODCALLTYPE SendCharEvents(UINT uVK,UINT uKeyFlags,UINT uChars,UINT RPC_FAR *puShift,UINT __RPC_FAR *puChars)
HRESULT STDMETHODCALLTYPE SendString(BSTR ptszStr,DWORD dwChars)
The SetImInfo method is used to set the bitmap, screen location and visibility state of the IM. The SendVirtualKey is used to send a virtual key code to the current window. The SendCharEvents method is used to send Unicode characters to the current window. The SendString is used to send strings to the current window.
The sample presented here is a simple SIP that can be used to input only numbers. The SIP looks like this:
This is created using Microsoft Visual Studio 2008. This is simple example just to demonstrate the SIP, a real SIP will be more complicated that this.