The easiest way to enter numbers (especially non-integer numbers) in Windows Mobile (or in a regular Windows application) is to simply enter a text field into which users are pasted and then confirm that they have entered the correct number.
The problem with this approach in Windows Mobile is that the standard SIP (soft keypad or small pop-up keyboard) looks like this:
alt text http://img510.imageshack.us/img510/6210/sipreg.jpg
Windows Mobile SIP , , . , , - , , "123" :
alt text http://img16.imageshack.us/img16/6128/sipnum.jpg
, () SIP . SIP , Microsoft.WindowsCE.Forms, "SIPHandler" ( ):
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using Microsoft.WindowsCE.Forms;
namespace DeviceApplication1
{
public class SIPHandler
{
public static void ShowSIP()
{
SipShowIM(1);
}
public static void ShowSIPNumeric()
{
SipShowIM(1);
SetKeyboardToNumeric();
}
public static void ShowSIPRegular()
{
SipShowIM(1);
SetKeyboardToRegular();
}
public static void HideSIP()
{
SipShowIM(0);
}
private static void SetKeyboardToRegular()
{
IntPtr hWnd = FindWindow("SipWndClass", null);
hWnd = GetWindow(hWnd, GW_CHILD);
IntPtr hDC = GetDC(hWnd);
int pixel = GetPixel(hDC, 2, 2);
int clrText = (SystemColors.WindowText.R) | (SystemColors.WindowText.G << 8) | (SystemColors.WindowText.B << 16);
SetPixel(hDC, 2, 2, clrText);
int pixelNew = GetPixel(hDC, 2, 2);
SetPixel(hDC, 2, 2, pixel);
if (pixel == pixelNew)
{
Message msg = Message.Create(hWnd, WM_LBUTTONDOWN, new IntPtr(1), new IntPtr(0x00090009));
MessageWindow.SendMessage(ref msg);
msg = Message.Create(hWnd, WM_LBUTTONUP, new IntPtr(0), new IntPtr(0x00090009));
MessageWindow.SendMessage(ref msg);
}
ReleaseDC(hWnd, hDC);
}
private static void SetKeyboardToNumeric()
{
IntPtr hWnd = FindWindow("SipWndClass", null);
hWnd = GetWindow(hWnd, GW_CHILD);
IntPtr hDC = GetDC(hWnd);
int pixel = GetPixel(hDC, 2, 2);
int clrText = (SystemColors.Window.R) | (SystemColors.Window.G << 8) | (SystemColors.Window.B << 16);
SetPixel(hDC, 2, 2, clrText);
int pixelNew = GetPixel(hDC, 2, 2);
SetPixel(hDC, 2, 2, pixel);
if (pixel == pixelNew)
{
Message msg = Message.Create(hWnd, WM_LBUTTONDOWN, new IntPtr(1), new IntPtr(0x00090009));
MessageWindow.SendMessage(ref msg);
msg = Message.Create(hWnd, WM_LBUTTONUP, new IntPtr(0), new IntPtr(0x00090009));
MessageWindow.SendMessage(ref msg);
}
ReleaseDC(hWnd, hDC);
}
[DllImport("coredll.dll")]
private extern static bool SipShowIM(int dwFlag);
[DllImport("coredll.dll")]
private extern static IntPtr FindWindow(string wndClass, string caption);
[DllImport("coredll.dll")]
private extern static IntPtr GetWindow(IntPtr hWnd, int nType);
[DllImport("coredll.dll")]
private extern static int GetPixel(IntPtr hdc, int nXPos, int nYPos);
[DllImport("coredll.dll")]
private extern static void SetPixel(IntPtr hdc, int nXPos, int nYPos, int clr);
[DllImport("coredll.dll")]
private extern static IntPtr GetDC(IntPtr hWnd);
[DllImport("coredll.dll")]
private extern static void ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("coredll.dll")]
private static extern bool SipSetCurrentIM(byte[] clsid);
const int WM_LBUTTONDOWN = 0x0201;
const int WM_LBUTTONUP = 0x0202;
const int GW_CHILD = 5;
}
}
. SIP , :
SIPHandler.ShowSIPNumeric();
:
SIPHandler.ShowSIPRegular();
:
SIPHandler.HideSIP();
, , - "" , , SIP , ( ) , , SIP .
: "" -, , . - SO , , , , .
: , 2 Google, , Daniel Moth:
http://www.danielmoth.com/Blog/InputPanelEx.cs
... :
http://www.alexfeinman.com/download.asp?doc=IMSwitch.zip
, ! ( , ).