Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MFC window in a windows service?

Status
Not open for further replies.

ylegoc

Programmer
Sep 9, 2005
1
FR
Is it possible to have an output to an MFC window in a windows service?

I have one service running, and I'd to like to keep an error history in an MFC window. This window has a CListBox element.

MessageBox can be launched in the service, but what requires to launch complex windows?

Is there a CWinApp to derive?
 
You can have a CWinApp in your service, just the same as in an ordinary program. You just need cache the pointer to your CWinApp-based object and call StartServiceCtrlDispatcher in the InitInstance of your CWinApp-based class to register a ServiceMain function. Then when the service control manager calls your ServiceMain back, you retrieve the pointer to your CWinApp-based object, call RegisterServiceCtrlHandler, and start a new UI thread by calling AfxBeginThread.

From that point on, the program's main thread is the service thread, while the UI thread you created by calling AfxBeginThread can do things like create dialogs and other windows. Just make sure your service thread shuts down your UI thread properly when the service is told to stop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top