views:

70

answers:

1

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.

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:

  • A button to start an unscheduled scan/process manually.
  • A button to open a dialog for modifying settings.
  • A List Box for displaying status messages sent from the processing thread.
  • A custom drawn window for displaying image data (the file processing includes the creation and saving of images).
  • A status bar - while a process is not running, it shows a countdown to the next scheduled scan. During a scan it also provides some status feedback, including a progress bar.

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.

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.

+4  A: 

You can't do this as a service.

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.

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.

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.

Reed Copsey
Thank you for your response. I've never dealt with IPC but your link looks like it will be very helpful. I'll see what I learn.
Tim Coolman
+1. Also see my answer below for some tips in getting set up converting your application to a service: http://stackoverflow.com/questions/1554047/convert-a-c-program-to-a-windows-service/1554405#1554405
the_mandrill
You can do this with paired UI and service (two separate entities). The service exposes a COM object or RPC server and the UI connects to the COM object/RPC server to do the work.
Larry Osterman