用FindWindowEx找不到句柄,各位进来帮下

luvain3 2009-12-12 07:31:53
我窗体上就放了一个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;
}

}

}
...全文
168 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gisyellow 2009-12-12
  • 打赏
  • 举报
回复
参数不对吧
soaringbird 2009-12-12
  • 打赏
  • 举报
回复
用spy++查看一下真正的类名,不是"RichTextBox"

111,121

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧