PostMessage调用窃取兄弟姐妹的焦点

时间:2012-11-10 21:42:10

标签: c#

晚上好。 我理解这个问题可能看起来很奇怪,所以让我稍微解释一下我的问题:我正在构建一个Windows From Application,它可以打开多个Child Form,每个子窗体都包含一个加载Flash动画的WebBrowser组件。

现在,我需要模拟给定打开表单上的点击,而不会显示在其他所有表单之上。为了模拟点击,我使用的代码与https://stackoverflow.com/a/11161632/533599非常相似:我必须实现2次更改

  1. 我必须停止使用“Internet Explorer_Server”,因为我没有 在句柄链中有一个“MacromediaFlashPlayerActiveX”
  2. 为了     点击开火,我必须“加倍”,即鼠标向下,向上,     向下,向上。
  3. 代码工作得非常好,并且点击被触发,但每次它都会被触发,目标Form会获得焦点并弹出所有兄弟姐妹的顶部(但是会在我打开的每个窗口后面停留)。有没有办法防止这种行为?

1 个答案:

答案 0 :(得分:0)

目前我设法做了类似于我需要的事情

[DllImportAttribute("user32.dll", EntryPoint = "SetForegroundWindow")]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow([InAttribute()] IntPtr hWnd);

[DllImportAttribute("user32.dll", EntryPoint = "GetForegroundWindow")]
public static extern IntPtr GetForegroundWindow();

[DllImportAttribute("user32.dll", EntryPoint = "BringWindowToTop")]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
public static extern bool BringWindowToTop([InAttribute()] IntPtr hWnd);

IntPtr old = GetForegroundWindow();
LeftClick(hw, x, y);
SetForegroundWindow(old);
BringWindowToTop(old);

缺点是,“点击”形式仍然会弹出一秒钟,造成不良的风格效果。任何其他有助于将表单保留在后台的提示都很受欢迎:)