#include "precomp.h"
+
+typedef struct _PAGEDATA
+{
+ PSERVICEPROPSHEET dlgInfo;
+ BOOL bDisplayNameChanged;
+ BOOL bDescriptionChanged;
+ BOOL bBinaryPathChanged;
+ BOOL bStartTypeChanged;
+} PAGEDATA, *PPAGEDATA;
+
+
static VOID
SetButtonStates(PSERVICEPROPSHEET dlgInfo,
HWND hwndDlg)
{
hButton = GetDlgItem(hwndDlg, IDC_START);
EnableWindow (hButton, TRUE);
- HeapFree(GetProcessHeap(), 0, lpServiceConfig);
}
else if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) )
{
}
hButton = GetDlgItem(hwndDlg, IDC_START_PARAM);
- EnableWindow(hButton, (State == SERVICE_STOPPED));
+ EnableWindow(hButton, (State == SERVICE_STOPPED && lpServiceConfig && lpServiceConfig->dwStartType != SERVICE_DISABLED));
+
+ if (lpServiceConfig)
+ HeapFree(GetProcessHeap(), 0, lpServiceConfig);
/* set the main toolbar */
SetMenuAndButtonStates(dlgInfo->Info);
SetServiceStatusText(PSERVICEPROPSHEET dlgInfo,
HWND hwndDlg)
{
- LPTSTR lpStatus;
+ LPWSTR lpStatus;
UINT id;
if (dlgInfo->pService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
hInstance,
id))
{
- SendDlgItemMessage(hwndDlg,
- IDC_SERV_STATUS,
- WM_SETTEXT,
- 0,
- (LPARAM)lpStatus);
+ SendDlgItemMessageW(hwndDlg,
+ IDC_SERV_STATUS,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)lpStatus);
LocalFree(lpStatus);
}
}
* values and sets it to value of the selected item
*/
static VOID
-SetStartupType(LPTSTR lpServiceName,
+SetStartupType(LPWSTR lpServiceName,
HWND hwndDlg)
{
HWND hList;
LPQUERY_SERVICE_CONFIG pServiceConfig;
- LPTSTR lpBuf;
+ LPWSTR lpBuf;
DWORD StartUp = 0;
UINT i;
hInstance,
i))
{
- SendMessage(hList,
- CB_ADDSTRING,
- 0,
- (LPARAM)lpBuf);
+ SendMessageW(hList,
+ CB_ADDSTRING,
+ 0,
+ (LPARAM)lpBuf);
LocalFree(lpBuf);
}
}
case SERVICE_DISABLED: StartUp = 2; break;
}
- SendMessage(hList,
- CB_SETCURSEL,
- StartUp,
- 0);
+ SendMessageW(hList,
+ CB_SETCURSEL,
+ StartUp,
+ 0);
HeapFree(ProcessHeap,
0,
HWND hwndDlg)
{
LPQUERY_SERVICE_CONFIG pServiceConfig;
- LPTSTR lpDescription;
+ LPWSTR lpDescription;
/* set the service name */
- SendDlgItemMessage(hwndDlg,
- IDC_SERV_NAME,
- WM_SETTEXT,
- 0,
- (LPARAM)dlgInfo->pService->lpServiceName);
+ SendDlgItemMessageW(hwndDlg,
+ IDC_SERV_NAME,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)dlgInfo->pService->lpServiceName);
/* set the display name */
- SendDlgItemMessage(hwndDlg,
- IDC_DISP_NAME,
- WM_SETTEXT,
- 0,
- (LPARAM)dlgInfo->pService->lpDisplayName);
+ SendDlgItemMessageW(hwndDlg,
+ IDC_DISP_NAME,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)dlgInfo->pService->lpDisplayName);
/* set the description */
if ((lpDescription = GetServiceDescription(dlgInfo->pService->lpServiceName)))
{
- SendDlgItemMessage(hwndDlg,
- IDC_DESCRIPTION,
- WM_SETTEXT,
- 0,
- (LPARAM)lpDescription);
+ SendDlgItemMessageW(hwndDlg,
+ IDC_DESCRIPTION,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)lpDescription);
HeapFree(ProcessHeap,
0,
pServiceConfig = GetServiceConfig(dlgInfo->pService->lpServiceName);
if (pServiceConfig)
{
- SendDlgItemMessage(hwndDlg,
- IDC_EXEPATH,
- WM_SETTEXT,
- 0,
- (LPARAM)pServiceConfig->lpBinaryPathName);
+ SendDlgItemMessageW(hwndDlg,
+ IDC_EXEPATH,
+ WM_SETTEXT,
+ 0,
+ (LPARAM)pServiceConfig->lpBinaryPathName);
HeapFree(ProcessHeap,
- 0,
- pServiceConfig);
+ 0,
+ pServiceConfig);
}
if (dlgInfo->Info->bIsUserAnAdmin)
{
- HWND hEdit = GetDlgItem(hwndDlg,
- IDC_EDIT);
- EnableWindow(hEdit,
- TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT), TRUE);
}
}
VOID
-SaveDlgInfo(PSERVICEPROPSHEET dlgInfo,
+SaveDlgInfo(PPAGEDATA pPageData,
HWND hwndDlg)
{
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
- HWND hList;
+ PWSTR pDisplayName = NULL;
+ PWSTR pDescription;
+ INT nLength;
DWORD StartUp;
pServiceConfig = HeapAlloc(ProcessHeap,
{
pServiceConfig->dwServiceType = SERVICE_NO_CHANGE;
pServiceConfig->dwErrorControl = SERVICE_NO_CHANGE;
+ pServiceConfig->dwStartType = SERVICE_NO_CHANGE;
- hList = GetDlgItem(hwndDlg, IDC_START_TYPE);
- StartUp = SendMessage(hList,
- CB_GETCURSEL,
- 0,
- 0);
- switch (StartUp)
+ if (pPageData->bStartTypeChanged)
{
- case 0: pServiceConfig->dwStartType = SERVICE_AUTO_START; break;
- case 1: pServiceConfig->dwStartType = SERVICE_DEMAND_START; break;
- case 2: pServiceConfig->dwStartType = SERVICE_DISABLED; break;
+ StartUp = SendDlgItemMessageW(hwndDlg, IDC_START_TYPE, CB_GETCURSEL, 0, 0);
+ switch (StartUp)
+ {
+ case 0:
+ pServiceConfig->dwStartType = SERVICE_AUTO_START;
+ break;
+
+ case 1:
+ pServiceConfig->dwStartType = SERVICE_DEMAND_START;
+ break;
+ case 2:
+ pServiceConfig->dwStartType = SERVICE_DISABLED;
+ break;
+ }
+ }
+
+ if (pPageData->bBinaryPathChanged)
+ {
+ nLength = SendDlgItemMessageW(hwndDlg, IDC_EXEPATH, WM_GETTEXTLENGTH, 0, 0);
+ pServiceConfig->lpBinaryPathName = HeapAlloc(ProcessHeap,
+ HEAP_ZERO_MEMORY,
+ (nLength + 1) * sizeof(WCHAR));
+ if (pServiceConfig->lpBinaryPathName != NULL)
+ SendDlgItemMessageW(hwndDlg, IDC_EXEPATH, WM_GETTEXT, nLength + 1, (LPARAM)pServiceConfig->lpBinaryPathName);
+ }
+
+ if (pPageData->bDisplayNameChanged)
+ {
+ nLength = SendDlgItemMessageW(hwndDlg, IDC_DISP_NAME, WM_GETTEXTLENGTH, 0, 0);
+ pDisplayName = HeapAlloc(ProcessHeap,
+ HEAP_ZERO_MEMORY,
+ (nLength + 1) * sizeof(WCHAR));
+ if (pDisplayName != NULL)
+ {
+ SendDlgItemMessageW(hwndDlg, IDC_DISP_NAME, WM_GETTEXT, nLength + 1, (LPARAM)pDisplayName);
+
+ if (pPageData->dlgInfo->pService->lpDisplayName)
+ HeapFree(ProcessHeap, 0, pPageData->dlgInfo->pService->lpDisplayName);
+
+ pPageData->dlgInfo->pService->lpDisplayName = pDisplayName;
+ pServiceConfig->lpDisplayName = pDisplayName;
+ }
}
if (SetServiceConfig(pServiceConfig,
- dlgInfo->pService->lpServiceName,
+ pPageData->dlgInfo->pService->lpServiceName,
NULL))
{
- ChangeListViewText(dlgInfo->Info,
- dlgInfo->pService,
- LVSTARTUP);
+ if (pPageData->bDisplayNameChanged)
+ ChangeListViewText(pPageData->dlgInfo->Info,
+ pPageData->dlgInfo->pService,
+ LVNAME);
+
+ if (pPageData->bStartTypeChanged)
+ ChangeListViewText(pPageData->dlgInfo->Info,
+ pPageData->dlgInfo->pService,
+ LVSTARTUP);
}
- HeapFree(ProcessHeap,
- 0,
- pServiceConfig);
+ if (pServiceConfig->lpBinaryPathName != NULL)
+ HeapFree(ProcessHeap, 0, pServiceConfig->lpBinaryPathName);
+
+ HeapFree(ProcessHeap, 0, pServiceConfig);
}
-}
-static
-VOID
-OnStart(HWND hwndDlg,
- PSERVICEPROPSHEET dlgInfo)
-{
- WCHAR szStartParams[256];
- LPWSTR lpStartParams = NULL;
+ if (pPageData->bDescriptionChanged)
+ {
+ nLength = SendDlgItemMessageW(hwndDlg, IDC_DESCRIPTION, WM_GETTEXTLENGTH, 0, 0);
+ pDescription = HeapAlloc(ProcessHeap, HEAP_ZERO_MEMORY, (nLength + 1) * sizeof(WCHAR));
+ if (pDescription != NULL)
+ {
+ SendDlgItemMessageW(hwndDlg, IDC_DESCRIPTION, WM_GETTEXT, nLength + 1, (LPARAM)pDescription);
- if (GetDlgItemText(hwndDlg, IDC_START_PARAM, szStartParams, 256) > 0)
- lpStartParams = szStartParams;
+ if (SetServiceDescription(pPageData->dlgInfo->pService->lpServiceName,
+ pDescription))
+ {
+ ChangeListViewText(pPageData->dlgInfo->Info,
+ pPageData->dlgInfo->pService,
+ LVDESC);
+ }
- if (DoStart(dlgInfo->Info, lpStartParams))
- {
- UpdateServiceStatus(dlgInfo->pService);
- ChangeListViewText(dlgInfo->Info, dlgInfo->pService, LVSTATUS);
- SetButtonStates(dlgInfo, hwndDlg);
- SetServiceStatusText(dlgInfo, hwndDlg);
+ HeapFree(ProcessHeap, 0, pDescription);
+ }
}
}
WPARAM wParam,
LPARAM lParam)
{
- PSERVICEPROPSHEET dlgInfo;
+ PPAGEDATA pPageData;
/* Get the window context */
- dlgInfo = (PSERVICEPROPSHEET)GetWindowLongPtr(hwndDlg,
- GWLP_USERDATA);
- if (dlgInfo == NULL && uMsg != WM_INITDIALOG)
+ pPageData = (PPAGEDATA)GetWindowLongPtr(hwndDlg,
+ GWLP_USERDATA);
+ if (pPageData == NULL && uMsg != WM_INITDIALOG)
{
return FALSE;
}
switch (uMsg)
{
case WM_INITDIALOG:
- {
- dlgInfo = (PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam);
- if (dlgInfo != NULL)
+ pPageData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PAGEDATA));
+ if (pPageData != NULL)
{
SetWindowLongPtr(hwndDlg,
GWLP_USERDATA,
- (LONG_PTR)dlgInfo);
- InitGeneralPage(dlgInfo, hwndDlg);
- SetButtonStates(dlgInfo, hwndDlg);
+ (LONG_PTR)pPageData);
+
+ pPageData->dlgInfo = (PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam);
+ if (pPageData->dlgInfo != NULL)
+ {
+ InitGeneralPage(pPageData->dlgInfo, hwndDlg);
+ SetButtonStates(pPageData->dlgInfo, hwndDlg);
+ }
}
- }
- break;
+ break;
+
+ case WM_DESTROY:
+ HeapFree(GetProcessHeap(), 0, pPageData);
+ break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_START_TYPE:
if (HIWORD(wParam) == CBN_SELCHANGE)
+ {
+ pPageData->bStartTypeChanged = TRUE;
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
- break;
-
- case IDC_START:
- OnStart(hwndDlg, dlgInfo);
- break;
+ }
+ break;
- case IDC_STOP:
- if (DoStop(dlgInfo->Info))
+ case IDC_DISP_NAME:
+ if (HIWORD(wParam) == EN_CHANGE)
{
- UpdateServiceStatus(dlgInfo->pService);
- ChangeListViewText(dlgInfo->Info, dlgInfo->pService, LVSTATUS);
- SetButtonStates(dlgInfo, hwndDlg);
- SetServiceStatusText(dlgInfo, hwndDlg);
+ pPageData->bDisplayNameChanged = TRUE;
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
- break;
+ break;
- case IDC_PAUSE:
- if (DoPause(dlgInfo->Info))
+ case IDC_DESCRIPTION:
+ if (HIWORD(wParam) == EN_CHANGE)
{
- UpdateServiceStatus(dlgInfo->pService);
- ChangeListViewText(dlgInfo->Info, dlgInfo->pService, LVSTATUS);
- SetButtonStates(dlgInfo, hwndDlg);
- SetServiceStatusText(dlgInfo, hwndDlg);
+ pPageData->bDescriptionChanged = TRUE;
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
- break;
+ break;
- case IDC_RESUME:
- if (DoResume(dlgInfo->Info))
+ case IDC_EXEPATH:
+ if (HIWORD(wParam) == EN_CHANGE)
{
- UpdateServiceStatus(dlgInfo->pService);
- ChangeListViewText(dlgInfo->Info, dlgInfo->pService, LVSTATUS);
- SetButtonStates(dlgInfo, hwndDlg);
- SetServiceStatusText(dlgInfo, hwndDlg);
+ pPageData->bBinaryPathChanged = TRUE;
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
- break;
+ break;
- case IDC_EDIT:
+ case IDC_START:
{
- HWND hName, hDesc, hExePath;
+ WCHAR szStartParams[256];
+ LPWSTR lpStartParams = NULL;
+
+ if (GetDlgItemText(hwndDlg, IDC_START_PARAM, szStartParams, 256) > 0)
+ lpStartParams = szStartParams;
- hName = GetDlgItem(hwndDlg, IDC_DISP_NAME);
- hDesc = GetDlgItem(hwndDlg, IDC_DESCRIPTION);
- hExePath = GetDlgItem(hwndDlg, IDC_EXEPATH);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_START_PARAM), FALSE);
- SendMessage(hName, EM_SETREADONLY, FALSE, 0);
- SendMessage(hDesc, EM_SETREADONLY, FALSE, 0);
- SendMessage(hExePath, EM_SETREADONLY, FALSE, 0);
+ RunActionWithProgress(hwndDlg,
+ pPageData->dlgInfo->pService->lpServiceName,
+ pPageData->dlgInfo->pService->lpDisplayName,
+ ACTION_START,
+ lpStartParams);
+
+ UpdateServiceStatus(pPageData->dlgInfo->pService);
+ ChangeListViewText(pPageData->dlgInfo->Info, pPageData->dlgInfo->pService, LVSTATUS);
+ SetButtonStates(pPageData->dlgInfo, hwndDlg);
+ SetServiceStatusText(pPageData->dlgInfo, hwndDlg);
+ break;
}
- break;
- case IDC_START_PARAM:
- PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
- break;
+ case IDC_STOP:
+ RunActionWithProgress(hwndDlg,
+ pPageData->dlgInfo->pService->lpServiceName,
+ pPageData->dlgInfo->pService->lpDisplayName,
+ ACTION_STOP,
+ NULL);
+
+ UpdateServiceStatus(pPageData->dlgInfo->pService);
+ ChangeListViewText(pPageData->dlgInfo->Info, pPageData->dlgInfo->pService, LVSTATUS);
+ SetButtonStates(pPageData->dlgInfo, hwndDlg);
+ SetServiceStatusText(pPageData->dlgInfo, hwndDlg);
+ break;
+
+ case IDC_PAUSE:
+ RunActionWithProgress(hwndDlg,
+ pPageData->dlgInfo->pService->lpServiceName,
+ pPageData->dlgInfo->pService->lpDisplayName,
+ ACTION_PAUSE,
+ NULL);
+
+ UpdateServiceStatus(pPageData->dlgInfo->pService);
+ ChangeListViewText(pPageData->dlgInfo->Info, pPageData->dlgInfo->pService, LVSTATUS);
+ SetButtonStates(pPageData->dlgInfo, hwndDlg);
+ SetServiceStatusText(pPageData->dlgInfo, hwndDlg);
+ break;
+
+ case IDC_RESUME:
+ RunActionWithProgress(hwndDlg,
+ pPageData->dlgInfo->pService->lpServiceName,
+ pPageData->dlgInfo->pService->lpDisplayName,
+ ACTION_RESUME,
+ NULL);
+
+ UpdateServiceStatus(pPageData->dlgInfo->pService);
+ ChangeListViewText(pPageData->dlgInfo->Info, pPageData->dlgInfo->pService, LVSTATUS);
+ SetButtonStates(pPageData->dlgInfo, hwndDlg);
+ SetServiceStatusText(pPageData->dlgInfo, hwndDlg);
+ break;
+
+ case IDC_EDIT:
+ SendDlgItemMessage(hwndDlg, IDC_DISP_NAME, EM_SETREADONLY, FALSE, 0);
+ SendDlgItemMessage(hwndDlg, IDC_DESCRIPTION, EM_SETREADONLY, FALSE, 0);
+ SendDlgItemMessage(hwndDlg, IDC_EXEPATH, EM_SETREADONLY, FALSE, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT), FALSE);
+ break;
}
break;
case WM_NOTIFY:
+ switch (((LPNMHDR)lParam)->code)
{
- LPNMHDR lpnm = (LPNMHDR)lParam;
-
- switch (lpnm->code)
- {
- case PSN_APPLY:
- SaveDlgInfo(dlgInfo, hwndDlg);
- SetButtonStates(dlgInfo, hwndDlg);
+ case PSN_APPLY:
+ if (pPageData->bDisplayNameChanged ||
+ pPageData->bDescriptionChanged ||
+ pPageData->bBinaryPathChanged ||
+ pPageData->bStartTypeChanged)
+ {
+ SaveDlgInfo(pPageData, hwndDlg);
+ SetButtonStates(pPageData->dlgInfo, hwndDlg);
+ pPageData->bDisplayNameChanged = FALSE;
+ pPageData->bDescriptionChanged = FALSE;
+ pPageData->bBinaryPathChanged = FALSE;
+ pPageData->bStartTypeChanged = FALSE;
+ }
break;
- }
}
- break;
+ break;
}
return FALSE;