1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Runtime.InteropServices;
9![]()
10namespace Lqjt
11![]()
{
12public partial class ImeForm : Form
13![]()
{
14public ImeForm()
15![]()
{
16InitializeComponent();
17}
18//声明一些API函数
19[DllImport("imm32.dll")]
20public static extern IntPtr ImmGetContext(IntPtr hwnd);
21[DllImport("imm32.dll")]
22public static extern bool ImmGetOpenStatus(IntPtr himc);
23[DllImport("imm32.dll")]
24public static extern bool ImmSetOpenStatus(IntPtr himc, bool b);
25[DllImport("imm32.dll")]
26public static extern bool ImmGetConversionStatus(IntPtr himc, ref int lpdw, ref int lpdw2);
27[DllImport("imm32.dll")]
28public static extern int ImmSimulateHotKey(IntPtr hwnd, int lngHotkey);
29private const int IME_CMODE_FULLSHAPE = 0x8;
30private const int IME_CHOTKEY_SHAPE_TOGGLE = 0x11;
31protected override void OnActivated(EventArgs e)
32![]()
{
33base.OnActivated(e);
34IntPtr HIme = ImmGetContext(this.Handle);
35if (ImmGetOpenStatus(HIme)) //如果输入法处于打开状态
36![]()
{
37int iMode = 0;
38int iSentence = 0;
39bool bSuccess = ImmGetConversionStatus(HIme, ref iMode, ref iSentence); //检索输入法信息
40if (bSuccess)
41![]()
{
42if ((iMode & IME_CMODE_FULLSHAPE) > 0) //如果是全角
43ImmSimulateHotKey(this.Handle, IME_CHOTKEY_SHAPE_TOGGLE); //转换成半角
44}
45![]()
46}
47}
48}//form
49}
转载于:https://www.cnblogs.com/winnxm/archive/2007/12/10/989506.html
本文介绍了一个使用 C# 实现的 Windows 表单应用程序,该程序能够在激活窗口时检查并切换输入法的全角/半角状态。通过调用 IMM32.DLL 中的 API 函数实现。




}
3490

被折叠的 条评论
为什么被折叠?



