gpt4 book ai didi

C# - 需要 Psuedo 单击一个窗口

转载 作者:行者123 更新时间:2023-11-30 18:46:37 25 4
gpt4 key购买 nike

好吧,首先,我想要做的是在 web 浏览器控件内单击 flash 对象内的特定点。我不确定为什么它不起作用,但我似乎无法单击任何窗口,无论是记事本还是实际程序。

这是我正在使用的代码。

    [DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String sAppName);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

public IntPtr find()
{
return this.Handle;//FindWindow("", "Form1");
}

public enum WMessages : int
{
WM_LBUTTONDOWN = 0x201, //Left mousebutton down
WM_LBUTTONUP = 0x202, //Left mousebutton up
WM_LBUTTONDBLCLK = 0x203, //Left mousebutton doubleclick
WM_RBUTTONDOWN = 0x204, //Right mousebutton down
WM_RBUTTONUP = 0x205, //Right mousebutton up
WM_RBUTTONDBLCLK = 0x206, //Right mousebutton do
}

private int MAKELPARAM(int p, int p_2)
{
return ((p_2 << 16) | (p & 0xFFFF));
}

/** This is the non-working code **/
public void DoMouseLeftClick(IntPtr handle, Point x)
{
SendMessage(handle, (int)WMessages.WM_LBUTTONDOWN, 0, MAKELPARAM(x.X, x.Y));
SendMessage(handle, (int)WMessages.WM_LBUTTONUP, 0, MAKELPARAM(x.X, x.Y));

return;

//I have tried PostMessage, and SendMessage, and both of them at the same time, and neither works.

PostMessage(handle, (uint)WMessages.WM_LBUTTONDOWN, 0, MAKELPARAM(x.X, x.Y));
PostMessage(handle, (uint)WMessages.WM_LBUTTONUP, 0, MAKELPARAM(x.X, x.Y));
}


private void timer2_Tick(object sender, EventArgs e)
{
//I try hovering my mouse over a button I added to the form, and nothing happens.
DoMouseLeftClick(find(), Cursor.Position);
}

所以,我尝试过使用 PostMessage 和 SendMessage,但它们似乎都不起作用。我需要它做的就是点击一个特定的点。

另外,我需要指出我不能使用 mouse_event,因为据我所知,窗口需要处于事件状态,而且光标需要位于您单击的点上。我正在制作一个自动在 flash 对象中执行进程的机器人,所以这就是我不能使用 mouse_event 的原因。

感谢您的帮助。

最佳答案

我遇到了同样的问题。

我试图在 MS Paint 中画一些东西。事实证明,我是在主窗口上单击,但结果是 MS Paint(和大多数应用程序)由许多子窗口组成,而您实际上想单击子窗口。所以我不得不改变我的代码:

IntPtr handle = FindWindow(null, "Untitled - Paint");
PostMessage(handle, (uint)MOUSE_BUTTONS.LEFT_DOWN, 0, lparam);

IntPtr handle = FindWindow(null, "Untitled - Paint");
handle = FindWindowEx(handle, IntPtr.Zero, "MSPaintView", null);
canvasHandle = FindWindowEx(handle, IntPtr.Zero, "Afx:00007FF676DD0000:8", null);
PostMessage(canvasHandle, (uint)MOUSE_BUTTONS.LEFT_DOWN, 0, lparam);

如果你想调试这些东西(即使你用 C# 编程),你需要使用 C++ Visual Studio 包附带的 Spy++ for Windows 等工具

希望对大家有帮助。

关于C# - 需要 Psuedo 单击一个窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19237034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com