private const int WM_COPYDATA = 0x004A; // 结构定义 public struct CopyDataStructIN { public IntPtr dwData; public int cbData; public IntPtr lpData; } //1 [DllImport("dwApiLib.dll", EntryPoint = "DWAPI_SendCmdA", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] private static extern bool DWAPI_SendCmdA(StringBuilder fullPath); [DllImport("User32.dll")] public static extern int RegisterWindowMessage(string Name);2、设置开机启动
private void Form1_Load(object sender, EventArgs e) { // 堆代码 duidaima.com // 输入法主程序:DWMain.exe // 它应该是随电脑开机启动,如果没有启动,你也可以在这里启动它。 // 路径:安装目录\bin\windwos32\DWMain.exe textBox2.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件 textBox2.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生 }3、鼠标在文本框的时候,调用显示方法
// 显示 private void buttonShow_Click(object sender, EventArgs e) { DWAPI_SendCmdA(new StringBuilder("show")); }4、离开的时候,退出输入法
// 退出输入法 private void buttonClose_Click(object sender, EventArgs e) { DWAPI_SendCmdA(new StringBuilder("close")); }
效果图如下