- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我认为这可能是不可能的。请证明我错了。
以下设置:
gui
)通过创建一个 server
打开另一个应用程序(我们称之为 new Process()
) server
(由其他人开发)以隐藏其 GUI 的参数启动gui
等待用户进行一些输入gui
然后命令 server
执行一些任务server
的程序集/DLL 中定义的现在因为整个用户体验需要针对重复操作进行优化,打开的 GUI 元素(窗口/表单/对话框)需要预先选择/聚焦/激活。
第一个问题出现了,因为我没有找到关于 difference between those 是什么的明确解释。属性(Focus、Active、Selected、TopMost)是。
现在真正的问题是,我如何确保所有 GUI 元素都处于事件状态并被选中,无论它们是否由我的 gui
启动过程或 server
过程?
我读到使用 WINAPI 可以更强大,所以我定义了以下内容
// required to use WINAPI for RegainFocus();
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int SetForegroundWindow(IntPtr hwnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SetActiveWindow(IntPtr hwnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static private void RegainFocus()
{
// set focus back to and show application for faster input
// SW_RESTORE = 9
ShowWindow(Process.GetCurrentProcess().MainWindowHandle, 9);
SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
SetActiveWindow(Process.GetCurrentProcess().MainWindowHandle);
}
那么到目前为止我尝试的是:
StartInfo
的 server
像这样的过程(所以新过程不会窃取 gui
的焦点)
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
server
过程和WaitForInputIdle
(如描述的 here )以确保 server
真的准备好了RegainFocus()
在gui
应用server
的 DLL 中我创建了一个新的 Form()
并尝试(将窗口置于最前面并选中它)
myForm = new Form();
myForm.Activated += dialog_Activated;
myForm.PerformLayout();
myForm.TopMost = true;
myForm.Activate();
myForm.BringToFront();
myForm.Focus();
myForm.Select();
DialogResult result = myForm.ShowDialog();
TopMost=true
致力于将对话框置于 gui
之前dialog_Activated()
方法使用 FocusControl()
将焦点设置在第一个输入控件上.这行得通。结果是在我的 gui
之上出现了一个窗口它的光标在第一个输入控件中闪烁,但已取消选择/处于非事件状态。当我点击 <TAB>
我可以看到在 gui
中选择了一个不同的控件这是在后台。
我试过喷涂 RegainFocus()
也在表格中调用,但没有用。
我还有其他想法但无法实现:
gui
一旦在那里完成输入,但是there is no unFocus()
目标框架是 .NET 4.5,目标操作系统是 Windows 7 和 Windows 10。
感谢您的任何帮助和意见/建议!
最佳答案
我得到了一个似乎适用于 Windows 10 和 Windows 7 的解决方案。
失去焦点后,我使用 RegainFocus()
函数重新获得焦点(并激活窗口),请参阅问题。注意:不要混合处理 HANDLE
和 MainWindowHandle
。当一个对象被隐藏时,它的 MainWindowHandle
很可能是 0
。
我删除了
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
在启动 server
进程时,为了不扰乱可见性状态。不过,我保留了 [WaitForInputIdle][1]
。
在 Windows 7 上,这仍然不够,而且 AllowSetForegroundWindow在创建的进程上不起作用(尽管感谢您的评论),而不是将窗口放在前面,taskbar was flashing .这里的解决方案是 set the registry value的
\HKEY_CURRENT_USER\Control Panel\Desktop\ForegroundLockTimeout
到 0
并重新启动机器。然后代码在 Windows 7 和 10 上的行为相同。如果权限正确,这甚至可能是 done programatically。 .
因为这个问题有很多不同的答案和解决方案,我认为它取决于很多因素(比如 Windows 版本、注册表设置、可能是 UAC 和主题设置、框架和运行时、一些 more conditions ,...)和这就是为什么我想提及我发现的其他方法。
SetForegroundWindow
WM_SHOWWINDOW
消息ShowWindow
与 SW_RESTORE
和 SW_SHOW
before SetForegroundWindow
[SetWindowPos][10]
、SetActiveWindow
、SetFocus
和最后的 AttachThreadInput
AllowSetForegroundWindow
与 [ASFW_ANY][11]
AppActivate
from VB.NET in C# 关于c# - 如何激活由另一个进程启动的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53706056/
每当我运行命令以将 Virtualbox 驱动程序启动 Minishift 到操作系统主机时,它都需要一段疯狂的时间,而且它永远不会结束。有时我什至收到有关达到存储限制的错误消息。 不知道是不是描述h
您好,我正在使用 npm 运行一个基本的 React 项目,我正尝试在 docker 容器中启动它。但是我实际上无法让项目运行。我的 dockerfile 看起来像这样: FROM node:7.8.
所以我想从我的 SSH 终端开始游戏。 这真的很奇怪,当我直接从 Linux GUI 执行此操作时,它可以工作。但是当我使用 SSH 客户端进行远程连接时,它就崩溃了。似乎与我的显示驱动程序有关。 U
我有一个显示图像的动态壁纸。我在 Activity 中更改了该图像。然后我需要通知动态壁纸,以便它知道重新加载资源。 Intent 似乎是完美、简单的解决方案: Intent intent = new
我有一个似乎无法解决的问题。我在 Boot Dashboard 中使用 STS 3.9.2 从 Eclipse (Oxygen) 启动 Spring Boot 应用程序没有任何问题: 但是,当我尝试从
全新的 Python,在我开始摆弄东西之前先设置和安装东西。我的理解是 Python 2.7 和 Python 3.3 之间存在一些显着差异/不兼容,尽管这两个版本都得到了很好的使用,所以我认为最好安
在使用了很长时间的 jQuery 之后,我有一个问题,我正在使用 jQuery 模式(样式)编写一个简单的代码, (function(window, undefined) { var jQu
我正在尝试在 spring boot 应用程序下的非 spring 托管类中配置 Autowired。我在 tomcat 服务器下部署的 Web 应用程序下成功运行了这个。但是当我想在 spring
我对 xmonad 完全陌生,但我想开始使用它来提高我的工作效率。 这是我一直在使用的指南(我使用的是 Apple OS X Snow Leopard) http://xmonad.org/tour.
我试图将Spring Boot指南中的Managing Transactions示例扩展到两个数据源,但是@Transaction注释似乎仅对其中一个数据源有效。 在“Application.java
conEmu 有没有办法默认打开多个不同的选项卡? 我看到这个页面解释了如何使用 splits , 我意识到我可以按 Ctrl + T, 1, Enter,但我希望有一种方法可以自动执行此操作! "%
我正在寻找快速而肮脏的答案。我当时脑子一片空白,盯着屏幕看了 12 个小时以上,我想我中枪了。 我想做一个简单的 SignalR 应用程序作为教程。我找到了这个example ,但我不断收到票证未定义
我正在使用 Azure Powershell cmdlet 来启动/停止 VM。 Start-AzureVM [-ServiceName] [-Name] [ ] Stop-AzureVM [-S
我想使用Powershell脚本代码启动/停止iis和mssql 意味着当我运行ps脚本时,我想启动/停止iis和mssql 我在网上搜索了它,发现了一些代码,但按照我的要求无法正常工作 码: $ii
我在 liferay 工作。我们在我们的项目中使用一个模块来创建 liferay 主题。我使用命令 ant -Ddeploy.war=true 将它部署在服务器中。 war 文件在 liferay 部
我想在已安装 Python 2.7 的 Windows XP 计算机上运行 IPython(版本 0.12)。 我通过 Windows 二进制安装程序安装,但安装后 IPython 没有显示在菜单中,
我从创建了自己的简单图片。 FROM python:2.7.11 RUN mkdir /extra/later/ \ && mkdir /yyy 现在,我可以执行以下步骤: docker run
$(document).ready(function () { setTimeout(function() { window.location.reload(); }, 2000); // 2
我刚刚创建了一个帐户 OpenWeatherMap 我想通过城市 ID API 调用获取当前位置的天气: http://api.openweathermap.org/data/2.5/weather?
我注意到,如果我更改 xcasset 中的图像,启动 Storyboard不会更新。 例如,假设您的启动 Storyboard中有一个 UIImage View ,其中包含一个名为“logo”的蓝色图
我是一名优秀的程序员,十分优秀!