[WIN32K] -Implement NtUserCalcMenuBar.
[reactos.git] / reactos / base / services / thmsvc / thmsvc.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: base/services/thmsvc/thmsvc.c
5 * PURPOSE: Themes service
6 * PROGRAMMER: Giannis Adamopoulos
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <windows.h>
12 #include <uxtheme.h>
13 #include <uxundoc.h>
14 #include <wine/debug.h>
15
16 WINE_DEFAULT_DEBUG_CHANNEL(thmsvc);
17
18
19 /* GLOBALS ******************************************************************/
20
21 static VOID CALLBACK ServiceMain(DWORD argc, LPWSTR *argv);
22 static WCHAR ServiceName[] = L"Themes";
23 static SERVICE_TABLE_ENTRYW ServiceTable[] =
24 {
25 {ServiceName, ServiceMain},
26 {NULL, NULL}
27 };
28
29 SERVICE_STATUS_HANDLE ServiceStatusHandle;
30 SERVICE_STATUS ServiceStatus;
31
32
33 /* FUNCTIONS *****************************************************************/
34
35 static VOID
36 UpdateServiceStatus(DWORD dwState)
37 {
38 ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
39 ServiceStatus.dwCurrentState = dwState;
40
41 if (dwState == SERVICE_RUNNING)
42 ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
43 else if (dwState == SERVICE_PAUSED)
44 ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE;
45 else
46 ServiceStatus.dwControlsAccepted = 0;
47
48 ServiceStatus.dwWin32ExitCode = 0;
49 ServiceStatus.dwServiceSpecificExitCode = 0;
50 ServiceStatus.dwCheckPoint = 0;
51
52 if (dwState == SERVICE_START_PENDING ||
53 dwState == SERVICE_STOP_PENDING ||
54 dwState == SERVICE_PAUSE_PENDING ||
55 dwState == SERVICE_CONTINUE_PENDING)
56 ServiceStatus.dwWaitHint = 10000;
57 else
58 ServiceStatus.dwWaitHint = 0;
59
60 SetServiceStatus(ServiceStatusHandle,
61 &ServiceStatus);
62 }
63
64
65 static DWORD WINAPI
66 ServiceControlHandler(DWORD dwControl,
67 DWORD dwEventType,
68 LPVOID lpEventData,
69 LPVOID lpContext)
70 {
71 TRACE("ServiceControlHandler() called\n");
72
73 switch (dwControl)
74 {
75 case SERVICE_CONTROL_STOP:
76 TRACE(" SERVICE_CONTROL_STOP received\n");
77 ThemeHooksRemove();
78 UpdateServiceStatus(SERVICE_STOPPED);
79 return ERROR_SUCCESS;
80
81 case SERVICE_CONTROL_PAUSE:
82 TRACE(" SERVICE_CONTROL_PAUSE received\n");
83 UpdateServiceStatus(SERVICE_PAUSED);
84 return ERROR_SUCCESS;
85
86 case SERVICE_CONTROL_CONTINUE:
87 TRACE(" SERVICE_CONTROL_CONTINUE received\n");
88 UpdateServiceStatus(SERVICE_RUNNING);
89 return ERROR_SUCCESS;
90
91 case SERVICE_CONTROL_INTERROGATE:
92 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
93 SetServiceStatus(ServiceStatusHandle,
94 &ServiceStatus);
95 return ERROR_SUCCESS;
96
97 case SERVICE_CONTROL_SHUTDOWN:
98 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
99 UpdateServiceStatus(SERVICE_STOPPED);
100 return ERROR_SUCCESS;
101
102 default :
103 TRACE(" Control %lu received\n");
104 return ERROR_CALL_NOT_IMPLEMENTED;
105 }
106 }
107
108
109 static VOID CALLBACK
110 ServiceMain(DWORD argc, LPWSTR *argv)
111 {
112 UNREFERENCED_PARAMETER(argc);
113 UNREFERENCED_PARAMETER(argv);
114
115 TRACE("ServiceMain() called\n");
116
117 ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
118 ServiceControlHandler,
119 NULL);
120
121 TRACE("Calling SetServiceStatus()\n");
122 UpdateServiceStatus(SERVICE_RUNNING);
123 TRACE("SetServiceStatus() called\n");
124
125 ThemeHooksInstall();
126
127 TRACE("ServiceMain() done\n");
128 }
129
130
131 int
132 wmain(int argc, WCHAR *argv[])
133 {
134 UNREFERENCED_PARAMETER(argc);
135 UNREFERENCED_PARAMETER(argv);
136
137 TRACE("thmsvc: main() started\n");
138
139 StartServiceCtrlDispatcher(ServiceTable);
140
141 TRACE("thmsvc: main() done\n");
142
143 return 0;
144 }
145
146 /* EOF */