|An advanced service application|
|Step 5. How to show messages to user from a service|
Usually services run in background and does not show anything to the user. But sometimes it is necessary to show some information to user or ask him about something. There are several ways to implement such behaviour. The message boxes are one of them. This example shows how to use message boxes from service. There are many cases in which using of message box is quite enough. In our example we shall ask user whether to stop service or not. If user confirms that service should be stopped it will stop. In other case the stopping request will be rejected and service will continue to run.
Modify the OnStop event handler as shown below.
Note that we use the MessageBoxEx function instead of MessageBox or Delphi's MessageDlg. We use it because this function allows to show a message box from a service. In addition the MB_SERVICE_NOTIFICATION flag is necessary. It is this flag that says Windows that it should show message window in the user's desktop not in the desktop of service.
Another feature is usage of the DoAction parameter. By default it is True when the event handler is called. By setting it to False we prevent the service state from change.
|<< | Index | Step 1 | Step 2 | Step 3 | Step 4 | Step 5|