用FindWindowEx找不到句柄,各位进来帮下
我窗体上就放了一个timer1和一个richtextbox控件和一个button控件。调试的时候findwindowdx没有返回句柄
。我是菜鸟啊,各位大哥哥大姐姐帮忙看下这个错哪儿了
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 输出你好
public partial class Form1 : Form
{
[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, string lParam);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
IntPtr c = new IntPtr();
IntPtr b = new IntPtr();
b = GetForegroundWindow();
if (b != IntPtr.Zero)
{
c = FindWindowEx(b, IntPtr.Zero, "RichTextBox", null);
if(c != IntPtr.Zero)
{
SendMessage(c, 0x000C, IntPtr.Zero, "你好");
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;
}
}
}