为什么此代码无法正常工作 [英] Why this code is not working properly

查看:58
本文介绍了为什么此代码无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个EXE。每个都有两种不同的形式



EXE 1 - >表格1,表格2



EXE 2 - > FORM 1,FORM 2





为什么我在EXE 1的FORM 1上完成一个流程,

我我正在EXE 2上做一些过程并在EXE 2上打开FORM 2







I am having two EXE. Each having two different forms

EXE 1 --> FORM 1, FORM 2

EXE 2 --> FORM 1, FORM 2


Why I complete a process on FORM 1 of EXE 1,
I am doing some process on EXE 2 and opening FORM 2 on EXE 2



IntPtr hWnd = this.Handle;

if (hWnd != IntPtr.Zero)
{
    SetForegroundWindow(hWnd);
    ShowWindow(hWnd, int.Parse("9"));
}







但我要求的表格不在顶部。

如何操作




But my required form is not on the top.
How to do so

推荐答案

在最简单的情况下,你可以使用 SetActiveWindow with SetForegroundWindow 。但是,在一种情况下效果不佳:要激活的窗口打开模态对话框的时刻。



因此,全面的解决方案是这样的:首先,使用主窗口句柄,您必须找到此对话框的句柄(如果有)。这是使用函数 GetLastActivePopup 完成的。此函数将返回对话框的句柄或您已知道的主窗口的句柄。激活该窗口。



请参阅:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633507%28v=vs.85%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646311%28v=vs.85%29.aspx [ ^ ],

http:// msdn .microsoft.com / zh-CN / library / windows / desktop / ms633539%28v = vs.85%29.aspx [ ^ ]。



-SA
In the simplest case, you can use combination of SetActiveWindow with SetForegroundWindow. However, it works poorly in one case: the moment of time when the window to be activated opens a modal dialog.

So, the comprehensive solution is this: first, using the main window handle, you have to find the handle of this dialog, if any. This is done using the function GetLastActivePopup. This function will return either the handle of the dialog, or the handle of the main window which you already know. Activate that window.

Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633507%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646311%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx[^].

—SA


这篇关于为什么此代码无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆