www.pudn.com > input.rar > MainForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace InputMethodReader
{
public partial class MainForm : Form
{
///
/// 争渡(QQ258190355)
/// 20080529
///
public MainForm()
{
InitializeComponent();
}
#region Call APIs
//[DllImport("user32.dll")]
//static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowA")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("imm32.dll", EntryPoint = "ImmGetContext")]
static extern IntPtr ImmGetContext(IntPtr hwnd); // IME handle取得
[DllImport("imm32.dll", EntryPoint = "ImmReleaseContext")]
static extern void ImmReleaseContext(IntPtr hwnd); // IME handle解放
[DllImport("imm32.dll", EntryPoint = "ImmReleaseContext")]
static extern void ImmSetOpenStatus(IntPtr himc, int b); // IME Status設定
[DllImport("imm32.dll", EntryPoint = "ImmGetCompositionString")]
static extern long ImmGetCompositionString(IntPtr himc, bool b,out string dw2,long l); // IME入力モード設定
[DllImport("user32.dll", EntryPoint = "SendMessage")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, string lParam);
[DllImport("user32.dll", EntryPoint = "GetCursorPos")]//获取鼠标光标位置的API
static extern void GetCursorPos(ref Point p);
[DllImport("user32.dll", EntryPoint = "WindowFromPoint")]//获取光标处窗口句柄的API
static extern IntPtr WindowFromPoint(Point p);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
[DllImport("user32.dll", EntryPoint = "GetActiveWindow")]
static extern IntPtr GetActiveWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetFocus();
//[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
//public static extern IntPtr GetCursorPos(ref Point p);
//[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
//public static extern IntPtr WindowFromPoint(Point p);
#endregion
#region variables
public IME ime = new IME();
IntPtr hwnd = new IntPtr();
IntPtr focusHwnd = new IntPtr();
#endregion
#region constants
// IME系メッセージ
public const int WM_IME_STARTCOMPOSITION = 0x010D;
public const int WM_IME_ENDCOMPOSITION = 0x010E;
public const int WM_IME_COMPOSITION = 0x010F;
public const int WM_IME_KEYDOWN = 0x0209;
public const int WM_SETTEXT = 0x000C;
#endregion
#region methods
#endregion
#region events
private void MainForm_Load(object sender, EventArgs e)
{
focusHwnd = IntPtr.Zero;
hwnd = this.Handle;
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
}
private void timer1_Tick(object sender, EventArgs e)
{
this.label1.Text = "";
if (hwnd != IntPtr.Zero)
{
string[] result = ime.GetAllCandidateList(hwnd);
for (int i = 1; i <= result.Length; i++)
this.label1.Text += i + "." + result[i - 1] + " ";
}
}
#endregion
}
}