蘑菇的视角

.Net开发文章,技术文档及随笔

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

转载:如何在Smartphone程序中切换输入法?

作者:Daric   来源:Biplip.com   时间:2004年12月18日 7:05   阅读1899
 

本文适用于在Windows Mobile 2003 for Smartphone平台下使用.net Compact Framework + C# 进行应用开发的人员,由biplip开发人员在dopod 565手机上测试通过。

1、导入API

public class MyForm : System.Windows.Forms.Form
 {
  ..........
public const uint EM_SETINPUTMODE = 0xDE;
  public const uint EIM_SPELL = 0;
  public const uint EIM_AMBIG = 1;
  public const uint EIM_NUMBERS = 2;

  [DllImport("coredll.dll")]
  public static extern IntPtr GetFocus();

  [DllImport("coredll.dll")]
  public static extern int SendMessage(IntPtr hWnd, uint Message, uint wParam, uint lParam);
  ...........
}

2、在组件初始化函数中定义事件处理
private void InitializeComponent()
{
  ............
     this.tbNum.GotFocus += new System.EventHandler(this.tbNum_GotFocus);
  ...........
 }

3、在事件发生时将输入法切换为数字模式

private void tbNum_GotFocus(object sender, System.EventArgs e)
  {
  .............
   IntPtr hWnd;
   hWnd = GetFocus();
   SendMessage(hWnd, EM_SETINPUTMODE, 0, EIM_NUMBERS);
  ............
  }

posted on 2006-03-08 13:30  斯文的蘑菇  阅读(362)  评论(0)    收藏  举报