Vista服务:可以在隐形桌面上显示表格吗?

发布于 2024-08-09 09:32:18 字数 301 浏览 3 评论 0原文

我试图在 Vista 上的服务中显示一个表单(使用 .NET winforms),

显然该表单不会向控制台用户显示,因为服务在会话 0 中被隔离。

但是,实验是为了看看是否可以“显示” " 一个不可见的窗体并获取窗口句柄&消息循环

我已经尝试过,但是当我发出 form.Show() 时,只有 form.Load 事件触发,而不触发 .Shown 或 .FormClosing

有没有办法像用户应用程序那样以这种方式捕获 Windows 消息?

我没有尝试使服务“交互”,因为我不希望与登录用户交互。

I am attempting to show a form from a service on Vista (using .NET winforms)

Obviously the form would not show to the console user, as services are isolated in session 0.

However the experiment is to see if it is possible to "show" an invisible form and obtain a window handle & message loop

I have tried but when I issue form.Show(), only the form.Load event fires not .Shown or .FormClosing

Is there any way to capture windows messages in this way as a user application would?

I have not attempted to make the service 'interactive' as I do not wish to interact with the logged-on user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裸钻 2024-08-16 09:32:18

是的,您可以在服务的桌面上显示表单。它不会向任何登录的用户显示,事实上,在 Vista 和更高版本的操作系统中,即使您将服务设置为“交互式”,您也无法向用户显示它。由于桌面不是交互式的,表单接收到的 Windows 消息将略有不同,但绝大多数事件应该在服务中触发,就像在交互式桌面上一样(我刚刚做了一个快速测试并得到了表单加载、显示、激活和关闭事件)。

要记住的一件事是,为了显示表单,您的线程必须是 STA 线程,并且必须通过调用 ShowDialog 或 Applicaton.Run 创建消息循环。另外,请记住与表单的所有外部交互都需要使用表单实例上的 Invoke 或 BeginInvoke 将其编组到正确的线程。

这当然是非常可行的,但实际上根本不推荐。您必须绝对确保表单及其包含的任何组件在任何情况下都不会显示任何意外的 UI,例如消息框。这种方法唯一真正合理的时候是当您使用质量可疑的遗留工具或需要创建句柄才能正常运行的第三方工具时。

Yes you can show a form on a service's desktop. It will not be shown to any logged in user, in fact in Vista and later OSes you cannot show it to a user even if you set the service to 'interactive'. Since the desktop is not interactive the windows messages the form receives will be slightly different but the vast majority of the events should be triggered the same in a service as they would be on an interactive desktop (I just did a quick test and got the form load, shown, activated and closing events).

One thing to remember is that in order to show a form your thread must be an STA thread and a message loop must be created, either by calling ShowDialog or Applicaton.Run. Also, remember all external interaction with the form will need to be marshaled to the correct thread using Invoke or BeginInvoke on the form instance.

This is certainly very doable but is really not recommended at all. You must be absolutely sure that the form and any components it contains will not show any unexpected UI, such as a message box, under any circumstances. The only time this method can really be justified is when you are working with a dubious quality legacy or 3rd party tool that requires handle creation in order to function properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文