带 GUI 监视器的 Windows 服务? [英] Windows Service with GUI monitor?

查看:35
本文介绍了带 GUI 监视器的 Windows 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C++ Win32 应用程序,它是作为一个 Windows GUI 项目编写的,现在我正试图将它变成一个服务/GUI 混合体.我了解 Windows 服务不能/不应该有用户界面.但请允许我解释一下我目前所拥有的以及我的目标.

I have a C++ Win32 application that was written as a Windows GUI project, and now I'm trying to figure out to make it into a Service / GUI hybrid. I understand that a Windows Service cannot / should not have a user interface. But allow me to explain what I have so far and what I'm shooting for.

我现在拥有什么是一个 Windows 应用程序.当它运行时,它会在系统托盘中放置一个图标,您可以双击该图标以打开 GUI.此应用程序的目的是按夜间计划处理位于指定目录中的文件.GUI 由以下部分组成:

WHAT I HAVE NOW is a windows application. When it is run it places an icon in the system tray that you can double-click on to open up the GUI. The purpose of this application is to process files located in a specified directory on a nightly schedule. The GUI consists of the following:

  • 手动启动计划外扫描/处理的按钮.
  • 用于打开修改设置对话框的按钮.
  • 用于显示从处理线程发送的状态消息的列表框.
  • 用于显示图像数据的自定义绘制窗口(文件处理包括图像的创建和保存).
  • 状态栏 - 当进程未运行时,它会显示下一次计划扫描的倒计时.在扫描过程中,它还提供一些状态反馈,包括进度条.

我要拍摄什么 是一项将在启动时运行且不需要用户登录的服务.这将包括预定的文件处理.但是,当用户登录时,我仍然希望加载托盘图标并允许他们打开我上面描述的 GUI 以监视服务的当前状态、更改设置、手动启动扫描并监视进度扫描.

WHAT I'M SHOOTING FOR is a service that will run on boot-up and not require a user to login. This would consist of the scheduled file processing. However, when a user logs in I would still like the tray icon to be loaded and allow them to open up a GUI as I described above to monitor the current state of the service, change settings, start a scan manually, and monitor the progress of a scan.

我确信我见过这样的应用程序 - 即使我没有登录,它也可以作为服务运行,但仍然为我提供一个用户界面,以便在我登录后使用.

I'm sure that I have seen applications like this - that function as a service even when I'm not logged in, but still give me a user interface to work with once I do log in.

我在想,与其有一个从处理线程向 GUI 线程发送消息的单个多线程应用程序,我还需要两个应用程序 - 一个用于执行处理的服务和一个用于提供视觉反馈的 GUI 应用程序服务,还向服务发送消息(例如,手动启动扫描).但我是 Windows 服务的新手,不知道这是如何完成的.

I'm thinking that instead of having a single multi-threaded application that sends messages to the GUI thread from the processing thread, I need two applications - a Service to perform the processing and a GUI application to provide visual feedback from the Service and also send messages to the Service (for example, to start a scan manually). But I am new to Windows Services and have no idea how this is done.

也有可能我完全不在基地,而服务根本不是我想要的.

It is also possible that I'm completely off base and a Service is not what I'm looking for at all.

任何帮助/想法/建议将不胜感激!谢谢.

Any help / ideas / suggestions would be greatly appreciated! Thank you.

推荐答案

您不能将此作为服务来执行.

You can't do this as a service.

您需要将 Windows 服务设为普通服务应用程序.这将在系统启动时启动,并在系统启动时一直运行.

You'll need to make your Windows Service as a normal service application. This will startup on system startup, and run the entire time the system is up.

然后,您将创建一个完全独立的 GUI 应用程序,该应用程序与服务对话".这可以设置为在用户登录时在用户帐户中运行.

You'd then make a completely separate GUI application, which "talks" to the service. This can be set to run when a user logs in, in the user's account.

为了让它们彼此交谈",您需要使用某种形式的 IPC.由于它们运行在同一系统上(但通常在不同的帐户中),因此命名管道或套接字都可以很好地工作.

In order to make them "talk" to each other, you'll need to use some form of IPC. Since these run on the same system (but in different accounts, typically), named pipes or sockets both work quite well.

这篇关于带 GUI 监视器的 Windows 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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