Vista 窗口焦点问题
我有一个管理患者人口统计信息的应用程序。 除了这些数据之外,用户还可以扫描患者的图片并将该图片分配给患者。 当用户单击扫描按钮时,将打开一个单独的应用程序作为对话框,以便扫描图像。 在 XP 上运行时一切正常。 成像应用程序加载良好并获得焦点。 然而,在 Vista 上,成像应用程序有时不会获得焦点,而是会在主应用程序后面弹出。 当全屏运行或通过 2008 Application Server 运行时,您无法看到该应用程序,您只会看到锁定的屏幕,并且看起来什么也没有发生。 有什么办法可以改变 Vista 上的窗口焦点管理,使其像 XP 一样工作吗? 我正在寻找一种方法来解决这个问题,如果可能的话,无需对实际应用程序进行更改。
I have an application that manages patient demographic information. Along with this data a user can scan a picture of a patient and assign that picture to a patient. When the user clicks the scan button a separate application is opened as a dialog in order to scan the image. When running this on XP everything worked fine. The imaging application loaded up fine and gained focus. On Vista however occasionally the imaging application will not gain focus and will popup behind the main application. When running full screen or through 2008 Application Server you cannot see the application, you only get a locked screen and it appears nothing has happened. Is there any way to change the window focus management on Vista to work the way XP did? I'm looking for a way to solve this without making changes to the actual application if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您必须对您的应用程序进行更改,以允许成像应用程序获得焦点。 我假设您的应用程序通过
ShellExecute
或CreateProcess
启动成像应用程序。 如果是这样,您可以通过SHELLEXECUTEINFO.hProcess
(对于ShellExecute
)或PROCESS_INFORMATION.hProcess
(对于SHELLEXECUTEINFO.hProcess
)获取启动进程的进程句柄。代码>CreateProcess)。 启动成像应用程序后立即调用 AllowSetForegroundWindow API:这将允许成像应用程序在启动时将其主窗口/对话框置于前台。
I think you will have to make changes to your application to allow the imaging application to take the focus. I'm going to assume that your application launches the imaging application through
ShellExecute
orCreateProcess
. If so, you can get the process handle of the launched process either throughSHELLEXECUTEINFO.hProcess
(forShellExecute
) orPROCESS_INFORMATION.hProcess
(forCreateProcess
). Immediately after launching the imaging application call the AllowSetForegroundWindow API:This will allow the imaging application to place its main window/dialog in the foreground when it's starting up.
您可以尝试以下步骤:
1.右键单击exe
2. 选择属性
3. 选择兼容性选项卡
4. 检查以兼容模式运行此程序:
5. 选择Windows XP (Service Pack 2)
You could try the following steps:
1. Right Click on the exe
2. Select Properties
3. Select the Compatibility Tab
4. Check the Run this program in campatibility mode for:
5. Select Windows XP (Service Pack 2)
您可以遍历所有顶级 HWND 并通过其窗口类识别扫描应用程序,然后发送适当的消息来升起窗口。
You could iterate through all top level HWNDs and identify the scanning application via its window class, then send an appropriate message to raise the window.
我不认为这与 Vista 和 XP 相关。 我认为这个成像应用程序在 Vista 上启动需要更长的时间。
从 Windows 2000 开始,窗口管理器就可以防止后台应用程序窃取前台应用程序。 当应用程序启动时,它有机会创建并显示一个占据前台的窗口。 如果花费的时间太长,窗口管理器会认为当前窗口应该保留前台,并在最终启动时阻止其他应用程序占用前台。
除了在启动应用程序后使用 FindWindow 搜索其他应用程序窗口之外,我想不出任何具体方法来避免这种情况。 当您最终找到它时,对其调用 SetForegroundWindow 将其置于前台。
I don't believe this is Vista vs XP related. I think that simply this imaging app takes longer to start on Vista.
Since Windows 2000, the window manager has prevented background applications stealing the foreground. When an application is launched, it has a window of opportunity to create and show a window that will take the foreground. If it takes too long, the window manager thinks that the current window should keep the foreground, and inhibits the other app taking the foreground when it does finally launch.
I can't think of any specific way to avoid this... other than using FindWindow to search for the other apps window after launching the app. When you eventually find it, call SetForegroundWindow on it to bring it to the foreground.