利用C#给另外窗口的输入框赋值和按钮发送点击事件不成功,原因有哪些呢

deadshot123 2017-12-27 11:37:23
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hwnd, int wMsg, string wParam, string lParam);

赋值代码
SendMessage(hwnd, 0x0c,null,"123456");

按钮点击代码
SendMessage(hwnd, 0xF5,null,null);

这两个代码可以操作两个窗口。

但是有另外两个窗口的操作不了。
这个客户端用到TsuiForm,TEdit,按钮为TsuiButton

其中句柄用spy++看过。都是对的。但是就是赋值和按钮点击不成功。请问还有别的办法吗??

还尝试过用鼠标设置把鼠标移动到按钮上面
[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
public static extern int SetCursorPos(int x, int y);

但是使用LeftClick(x + 5,y + 5);鼠标位置对的情况下也不能点击按钮
[DllImport("user32.dll")]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, UIntPtr dwExtraInfo);

public static void LeftClick(double x, double y)
{
var scr = Screen.PrimaryScreen.Bounds;
MouseEvent(MouseEventFlag.LeftDown | MouseEventFlag.LeftUp | MouseEventFlag.Move | MouseEventFlag.Absolute,
(uint)Math.Round(x / scr.Width * 65535),
(uint)Math.Round(y / scr.Height * 65535));
}

public static void MouseEvent(MouseEventFlag e, uint x, uint y)
{
mouse_event((uint)e, x, y, 0, UIntPtr.Zero);
}

public static void LeftClick(Point p)
{
LeftClick((double)p.X, (double)p.Y);
}

[Flags]
public enum MouseEventFlag : uint //设置鼠标动作的键值
{
Move = 0x0001, //发生移动
LeftDown = 0x0002, //鼠标按下左键
LeftUp = 0x0004, //鼠标松开左键
RightDown = 0x0008, //鼠标按下右键
RightUp = 0x0010, //鼠标松开右键
MiddleDown = 0x0020, //鼠标按下中键
MiddleUp = 0x0040, //鼠标松开中键
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800, //鼠标轮被移动
VirtualDesk = 0x4000, //虚拟桌面
Absolute = 0x8000
}


...全文
596 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
秋的红果实 2018-01-18
  • 打赏
  • 举报
回复
TsuiForm,TEdit,按钮为TsuiButton ==> 还可以通过标题找到他们的句柄,可用的API有findwindows,findwindowsex
神马都能聊 2018-01-18
  • 打赏
  • 举报
回复
sendmessage 是同步的,是会卡住的,需要等待对方处理完,有个api是可以指定超时时间的,postmessage是异步的,不想等待处理结果你可以使用postmessage。
deadshot123 2017-12-27
  • 打赏
  • 举报
回复
使用spy++监听操作消息的时候,整个应用都卡主了。连vs都卡主了
twtyypmb123 2017-12-27
  • 打赏
  • 举报
回复
用postmessage试试

110,536

社区成员

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

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

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