C#プログラムアナログキーボード入力メモ帳に内容を追加
2358 ワード
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
[DllImport("User32.dll ")]
public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string FrmText);
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
bool a = true;
private void button1_Click(object sender, EventArgs e)
{
Test();
if (a == true)
{
this.txtText.Text = " …!";
Form2 for2 = new Form2();
for2.ShowDialog();
}
a = false;
}
HotKeys h = new HotKeys();
private void Form1_Load(object sender, EventArgs e)
{
// Ctrl+E
h.Regist(this.Handle, (int)HotKeys.HotkeyModifiers.Control, Keys.E, CallBack);
//MessageBox.Show(" ");
}
// WndProc
protected override void WndProc(ref Message m)
{
h.ProcessHotKey(m);//
base.WndProc(ref m);
}
//
public void Test()
{
const int WM_SETTEXT = 0x000C;
IntPtr hwnd = FindWindow(null, " - ");
IntPtr htextbox = FindWindowEx(hwnd, IntPtr.Zero, "EDIT", null);
IntPtr htextbox2 = FindWindowEx(hwnd, htextbox, "EDIT", null);// , 。
SendMessage(htextbox, WM_SETTEXT, IntPtr.Zero, this.txtText.Text);
}
//
public void CallBack()
{
Test();
}
}
}
ソースのダウンロード