Using the software Input Panel in the development of win CE programs

Source: Internet
Author: User

Software input panels (software Input Panel, SIP) are a basic feature of each mobile platform equipped with the wince system. It provides a means for users to enter data on a PDA. When it comes to sip, we usually think of two points: SIP itself, and the second is how to use SIP in the program.
SIP is a COM object that implements the Iinputmethod or IINPUTMETHOD2 interface. It should be used by the system, so you can't do sip development in C #. C or C + + is a good language to develop. Because SIP itself is just another COM object, ATL makes the development process extremely simple. I do not want to discuss SIP development here, the SDK package contains a good routine atldvoraksip, so you can learn this routine to get more information. What I want to talk about here is how to manage SIP in your own program. This may seem trivial and simple, but if you want to make your program smarter and more user-friendly because the screen is not enough, SIP management becomes an important aspect. In addition, if you develop a lot of SIPs for different occasions (such as multilingual, digital, and so on), you may want to use a particular sip on an occasion. This ability allows you to accomplish a number of different tasks: when the user only needs to enter the digital input, you can show a large numeric keypad, so that he does not use the pen and only the finger can be entered. Of course you can also have your own ideas, which depends on what the programmer should do.
Win32 API
SIP API functions are simple, and only a few functions can be seen from sipapi.h:

***); int **);

I put this in the beginning because it supports both Windows Mobile and the platform. If you are programming with Windows Mobile devices, then the Aygshell.h file provides you with more SIP-related functions to use. Of course choosing which to use depends on your own needs, and using SIP on Windows Mobile will make the job a little more perfect. If you use the same OS version, but different build versions, you may get a slightly different sip behavior. Therefore, a method does not necessarily apply to all PDAs, as you might think.
Lists the available SIP
The first step is to understand how to enumerate all available sips. You can use the following code:

1Ctypedptrmap<cmapstringtoptr,cstring,clsid*>G_sipmap;2 intSipenumimproc (Imenuminfo *piminfo)3 {4clsid* PCLSID =NewCLSID;5memcpy (Pclsid,&piminfo->clsid,sizeof(CLSID));6G_sipmap.setat (CString (piminfo->szName), PCLSID);7TRACE (_t ("%SN"), CString (piminfo->szName));8    return 1;9 }Ten voidCsipdemodlg::onbuttonenum () One { A Sipenumim (sipenumimproc); - CString Ssipname; -CLSID *pclsid =NULL; the     for(POSITION pos =g_sipmap.getstartposition (); pos;) - { - G_sipmap.getnextassoc (POS,SSIPNAME,PCLSID); - m_siplist.addstring (ssipname); + } -}

What the code does is populate a global map that contains the "SIP name"/clsid pair. This example and the rest of the use of MFC, of course, you can also use the familiar Win32 API or other framework
How to select, Show and hide specific sip
When you know the CLSID of a sip, you can choose it. At the same time, the currently selected SIP can also be obtained:

1 voidCsipdemodlg::onbuttonenum ()2 {3 Sipenumim (sipenumimproc);4 CLSID Currsip;5Sipgetcurrentim (&currsip);6    intNcurrsip = lb_err, Nsipcount =0;7 CString ssipname, scurrsipname;8CLSID *pclsid =NULL;9     for(POSITION pos =g_sipmap.getstartposition (); pos;)Ten { One G_sipmap.getnextassoc (POS,SSIPNAME,PCLSID); A m_siplist.addstring (ssipname); -     if(MEMCMP (&currsip,pclsid,sizeof(CLSID)) ==0 ) - { theNcurrsip =Nsipcount; -Scurrsipname =Ssipname; - } -nsipcount++; + } -M_siplist.selectstring (0, scurrsipname); + } A voidCsipdemodlg::onbuttonselect () at { -   intNsel =M_siplist.getcursel (); -    if(Lb_err = =Nsel) -     return; - CString Ssipname; - M_siplist.gettext (nsel,ssipname); inCLSID *pclsid =NULL; -   if( !g_sipmap.lookup (ssipname,pclsid)) to     return; +BOOL bRes =Sipsetcurrentim (PCLSID); -    if( !bRes) theTRACE (L"Sipsetcurrentim returned%lun", GetLastError ()); * } $ voidcsipdemodlg::onbuttonshowhide ()Panax Notoginseng { -    if( !g_bshow) the { + Sipshowim (sipf_on); AG_bshow =TRUE; the } +    Else - { $ Sipshowim (sipf_off); $G_bshow =FALSE; - } - } the voidCsipdemodlg::onbuttonshowhide2 () - {Wuyi Sipinfo Sipinfo; thememset (&sipinfo,0,sizeof(Sipinfo)); -Sipinfo.cbsize=sizeof(sipinfo); WuBOOL bRes = Sipgetinfo (&sipinfo); -    if(bRes) About { $     if( !g_bshow) - { -Sipinfo.fdwflags |=sipf_on; -G_bshow =TRUE; A } +     Else the { -Sipinfo.fdwflags =Sipf_off; $G_bshow =FALSE; the } theBRes = Sipsetinfo (&sipinfo); the } the    Else - { inTRACE (L"Sipgetinfo returned%lun", GetLastError ()); the } the}

Here, you can see the example of the modification (Csipdemodlg::onbuttonenum ()), which detects which SIP is active and selects the corresponding row in the listbox. Other examples of dialog box methods select SIP and Show or hide it. Note that in order for Sipgetinfo or sipsetinfo to work, you must initialize Sipinfo.cbsize with the value of sizeof (Sipinfo) so that the operating system can react normally. This is a very common way to solve Win32.
Sipgetinfo gives you a visual desktop and sip size so you can re-customize the SIP location when you need it. The sipsetinfo does not change the SIP location. If you need to move the SIP, use Sipsetdefaultrect. Here are some examples to illustrate.
Using Shell functions
If you decide to use AYGShell-based functions, Shsippreference will do similar tasks for you. As with Sipshowim, this API will show and hide the Input Panel. Its last parameter defines what to do, can request to show or hide Input Panel, hide it immediately (because the operating system will set a timer for this in a regular case) or discard all waiting requests. Shsipinfo allows you to do the same thing as the SIPXXX function.
Typically, you can use all of the above APIs to respond to Wm_settingchaange or wm_create messages. According to the documentation, be very careful when you use Shsipinfo to process wm_settingchange messages. There are several reasons: first, SIP changes can cause the shell to send wm_settingchange messages, so be careful about infinite loops when you call in your handler function, and second, The Shsipinfo will interact with the Device.exe and Input Panel threads, so it will occupy about 100ms of time. This causes the WM_SETTINGCHANGE message to be sent to all running programs, so the system will lose its response for a period of time. Passing the lparam value at the same time as Wm_settingchange will avoid such a delay.
When it comes to shell functions, some of the functions on the Windows Mobile platform can be very useful and can get you into a headache. These include shinputdialog,shfullscreen or similar calls. In addition, Shhandlewmactivate and Shhandlewmsettingchange will allow you to fully enjoy the keyboard pop-up in MFC programs because they are used in the CDialog and CFrameWnd classes of the appropriate message handle. If you do not want to have the default behavior, you can overload the OnActivate or OnSettingChange handle.
Custom control
If you want to support the behavior of an intelligent input box class-The keyboard automatically pops up each time the input is entered, and then when the input focus is removed from the input box and the keyboard is hidden, the wm_setfocus and wm_killfocus need to be processed. The following code can help you:

1 voidCsipedit::onsetfocus (cwnd*Poldwnd)2 {3 Cedit::onsetfocus (poldwnd);4 shsippreference (m_hwnd,sip_up);5 }6 voidCsipedit::onkillfocus (cwnd*Pnewwnd)7 {8 Cedit::onkillfocus (pnewwnd);9 shsippreference (m_hwnd,sip_forcedown);Ten}

Setting the SIP location
Here's how to move the SIP to a location on the screen. Sipsetdefaultrect will change the default SIP hold, but it will not take effect immediately unless you re-select the Input method:

1 voidCsipdemodlg::onbuttonmove ()2 {3 Sipinfo Sipinfo;4memset (&sipinfo,0,sizeof(Sipinfo));5Sipinfo.cbsize=sizeof(sipinfo);6BOOL bRes = Sipgetinfo (&sipinfo);7    if(bRes)8 {9 CRect RC (sipinfo.rcsiprect);TenRc. Offsetrect (0,- -); OneSipsetdefaultrect (&RC); A CLSID CLSID; -     if(Sipgetcurrentim (&clsid)) - { theSipsetcurrentim (&clsid); - } - Sipshowim (sipf_on); - } +}

The above code shows you how to move the SIP location on the screen. This is useful when you want to place some controls on the lower end of the screen. Of course this does not conform to Microsoft's Pocket PC GUI design standards, but there are times when you have no other choice.
If you can get a handle to the window to control the style of the window, for example:

1 long lstyle=GetWindowLong (hwndsip,gwl_style); 2 lstyle |= ws_caption| Ws_sysmenu; 3 SetWindowLong (Hwndsip,gwl_style,lstyle);

Using the software Input Panel in the development of win CE programs

Related Article

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: 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.