Author: gedmurphy Date: Fri Jun 2 20:47:39 2006 New Revision: 22184
URL: http://svn.reactos.ru/svn/reactos?rev=22184&view=rev Log: - remove all reliance on 'extern' data, using abstraction. - store pointer to currently selected service in info struct so we don't have to keep calling it - rewrite create.c making it more modular. Still has some missing features. - lots of bugfixes and small improvements
Modified: trunk/reactos/base/applications/servman/En.rc trunk/reactos/base/applications/servman/control.c trunk/reactos/base/applications/servman/create.c trunk/reactos/base/applications/servman/delete.c trunk/reactos/base/applications/servman/mainwnd.c trunk/reactos/base/applications/servman/misc.c trunk/reactos/base/applications/servman/precomp.h trunk/reactos/base/applications/servman/propsheet.c trunk/reactos/base/applications/servman/query.c trunk/reactos/base/applications/servman/servman.c trunk/reactos/base/applications/servman/start.c trunk/reactos/base/applications/servman/stop.c
Modified: trunk/reactos/base/applications/servman/En.rc URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/En... ============================================================================== --- trunk/reactos/base/applications/servman/En.rc (original) +++ trunk/reactos/base/applications/servman/En.rc Fri Jun 2 20:47:39 2006 @@ -64,7 +64,7 @@ FONT 8,"Tahoma",0,0 STYLE WS_BORDER | WS_DLGFRAME | WS_SYSMENU | DS_MODALFRAME BEGIN - LTEXT "Service Manager v0.5\nCopyright (C) 2005-2006\nby Ged Murphy (gedmurphy@gmail.com)", IDC_STATIC, 48, 7, 130, 26 + LTEXT "Service Manager v0.5.1\nCopyright (C) 2005-2006\nby Ged Murphy (gedmurphy@gmail.com)", IDC_STATIC, 48, 7, 130, 26 PUSHBUTTON "Close", IDOK, 75, 162, 44, 15 ICON IDI_SM_ICON, IDC_STATIC, 10, 10, 7, 30 EDITTEXT IDC_LICENSE_EDIT, 8, 44, 174, 107, WS_VISIBLE | WS_VSCROLL | WS_TABSTOP | ES_READONLY | ES_MULTILINE @@ -209,7 +209,7 @@ IDS_PROGRESS_INFO_START "ReactOS is attempting to start the following service" IDS_PROGRESS_INFO_STOP "ReactOS is attempting to stop the following service" IDS_CREATE_SUCCESS "Service Created Succesfully" - IDS_CREATE_REQ "* = required fields" + IDS_CREATE_REQ "Fields marked with an\nasterix are mandatory" IDS_DELETE_STOP "You must manually stop the service before deleting!" END
Modified: trunk/reactos/base/applications/servman/control.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/co... ============================================================================== --- trunk/reactos/base/applications/servman/control.c (original) +++ trunk/reactos/base/applications/servman/control.c Fri Jun 2 20:47:39 2006 @@ -16,7 +16,6 @@ HWND hProgBar; SC_HANDLE hSCManager; SC_HANDLE hSc; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; SERVICE_STATUS_PROCESS ServiceStatus; SERVICE_STATUS Status; LVITEM item; @@ -30,9 +29,6 @@ 0, (LPARAM)&item);
- /* copy pointer to selected service */ - Service = (ENUM_SERVICE_STATUS_PROCESS *)item.lParam; - /* set the progress bar range and step */ hProgBar = GetDlgItem(Info->hProgDlg, IDC_SERVCON_PROGRESS); @@ -40,6 +36,7 @@ PBM_SETRANGE, 0, MAKELPARAM(0, PROGRESSRANGE)); + SendMessage(hProgBar, PBM_SETSTEP, (WPARAM)1, @@ -57,7 +54,7 @@
/* open handle to the service */ hSc = OpenService(hSCManager, - Service->lpServiceName, + Info->CurrentService->lpServiceName, SC_MANAGER_ALL_ACCESS); if (hSc == NULL) {
Modified: trunk/reactos/base/applications/servman/create.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/cr... ============================================================================== --- trunk/reactos/base/applications/servman/create.c (original) +++ trunk/reactos/base/applications/servman/create.c Fri Jun 2 20:47:39 2006 @@ -9,22 +9,30 @@
#include "precomp.h"
-extern HINSTANCE hInstance; -BOOL bHelpOpen = FALSE; - - -BOOL Create(LPTSTR ServiceName, - LPTSTR DisplayName, - LPTSTR BinPath, - LPTSTR Description, - LPTSTR Options) +typedef struct _CREATE_DATA +{ + HWND hSelf; + LPTSTR ServiceName; + LPTSTR DisplayName; + LPTSTR BinPath; + LPTSTR Description; + LPTSTR Options; + +} CREATE_DATA, *PCREATE_DATA; + +static BOOL bHelpOpen = FALSE; + +static BOOL +DoCreate(PCREATE_DATA Data) { SC_HANDLE hSCManager; SC_HANDLE hSc; TCHAR Buf[32];
/* open handle to the SCM */ - hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); + hSCManager = OpenSCManager(NULL, + NULL, + SC_MANAGER_ALL_ACCESS); if (hSCManager == NULL) { GetError(); @@ -32,13 +40,13 @@ }
hSc = CreateService(hSCManager, - ServiceName, - DisplayName, + Data->ServiceName, + Data->DisplayName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, - BinPath, + Data->BinPath, NULL, NULL, NULL, @@ -48,25 +56,204 @@ if (hSc == NULL) { GetError(); + CloseServiceHandle(hSCManager); return FALSE; }
- SetDescription(ServiceName, Description); - - LoadString(hInstance, IDS_CREATE_SUCCESS, Buf, - sizeof(Buf) / sizeof(TCHAR)); + /* Set the service description in the registry + * CreateService does not do this for us */ + SetDescription(Data->ServiceName, + Data->Description); + + /* report success to user */ + LoadString(hInstance, + IDS_CREATE_SUCCESS, + Buf, + sizeof(Buf) / sizeof(TCHAR)); DisplayString(Buf); + CloseServiceHandle(hSCManager); CloseServiceHandle(hSc); + return TRUE; }
-#ifdef _MSC_VER -#pragma warning(disable : 4100) -#endif +static BOOL +GetDataFromDialog(PCREATE_DATA Data) +{ + HWND hwnd; + TCHAR Buf[64]; + INT iLen = 0; + + /* get service name */ + hwnd = GetDlgItem(Data->hSelf, + IDC_CREATE_SERVNAME); + iLen = GetWindowTextLength(hwnd); + if (iLen != 0) + { + Data->ServiceName = HeapAlloc(ProcessHeap, + 0, + (iLen+1) * sizeof(TCHAR)); + if (Data->ServiceName != NULL) + { + GetWindowText(hwnd, + Data->ServiceName, + iLen+1); + } + else + return FALSE; + } + else + { + LoadString(hInstance, + IDS_CREATE_REQ, + Buf, + sizeof(Buf)); + DisplayString(Buf); + SetFocus(hwnd); + return FALSE; + } + + /* get display name */ + iLen = 0; + hwnd = GetDlgItem(Data->hSelf, + IDC_CREATE_DISPNAME); + iLen = GetWindowTextLength(hwnd); + if (iLen != 0) + { + Data->DisplayName = HeapAlloc(ProcessHeap, + 0, + (iLen+1) * sizeof(TCHAR)); + if (Data->DisplayName != NULL) + { + GetWindowText(hwnd, + Data->DisplayName, + iLen+1); + } + else + return FALSE; + } + else + { + LoadString(hInstance, + IDS_CREATE_REQ, + Buf, + sizeof(Buf)); + DisplayString(Buf); + SetFocus(hwnd); + return FALSE; + } + + /* get binary path */ + iLen = 0; + hwnd = GetDlgItem(Data->hSelf, + IDC_CREATE_PATH); + iLen = GetWindowTextLength(hwnd); + if (iLen != 0) + { + Data->BinPath = HeapAlloc(ProcessHeap, + 0, + (iLen+1) * sizeof(TCHAR)); + if (Data->BinPath != NULL) + { + GetWindowText(hwnd, + Data->BinPath, + iLen+1); + } + else + return FALSE; + } + else + { + LoadString(hInstance, + IDS_CREATE_REQ, + Buf, + sizeof(Buf)); + DisplayString(Buf); + SetFocus(hwnd); + return FALSE; + } + + /* get description */ + iLen = 0; + hwnd = GetDlgItem(Data->hSelf, + IDC_CREATE_DESC); + iLen = GetWindowTextLength(hwnd); + if (iLen != 0) + { + Data->Description = HeapAlloc(ProcessHeap, + 0, + (iLen+1) * sizeof(TCHAR)); + if (Data->Description != NULL) + { + GetWindowText(hwnd, + Data->Description, + iLen+1); + } + else + return FALSE; + } + + + /* get options */ + iLen = 0; + hwnd = GetDlgItem(Data->hSelf, + IDC_CREATE_PATH); + iLen = GetWindowTextLength(hwnd); + if (iLen != 0) + { + Data->Options = HeapAlloc(ProcessHeap, + 0, + (iLen+1) * sizeof(TCHAR)); + if (Data->Options != NULL) + { + GetWindowText(hwnd, + Data->Options, + iLen+1); + } + else + return FALSE; + } + + return TRUE; +} + +static VOID +FreeMemory(PCREATE_DATA Data) +{ + if (Data->ServiceName != NULL) + HeapFree(ProcessHeap, + 0, + Data->ServiceName); + if (Data->DisplayName != NULL) + HeapFree(ProcessHeap, + 0, + Data->DisplayName); + if (Data->BinPath != NULL) + HeapFree(ProcessHeap, + 0, + Data->BinPath); + if (Data->Description != NULL) + HeapFree(ProcessHeap, + 0, + Data->Description); + if (Data->Options != NULL) + HeapFree(ProcessHeap, + 0, + Data->Options); + + HeapFree(ProcessHeap, + 0, + Data); +} + + BOOL CALLBACK -CreateHelpDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +CreateHelpDialogProc(HWND hDlg, + UINT message, + WPARAM wParam, + LPARAM lParam) { HWND hHelp; HICON hIcon = NULL; @@ -74,31 +261,45 @@
switch (message) { - case WM_INITDIALOG: - hIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0); - SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); - - hHelp = GetDlgItem(hDlg, IDC_CREATE_HELP); - - LoadString(hInstance, IDS_HELP_OPTIONS, Buf, - sizeof(Buf) / sizeof(TCHAR)); - - SetWindowText(hHelp, Buf); - - return TRUE; - - case WM_COMMAND: - if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) - { - DestroyIcon(hIcon); - DestroyWindow(hDlg); + case WM_INITDIALOG: + { + hIcon = LoadImage(hInstance, + MAKEINTRESOURCE(IDI_SM_ICON), + IMAGE_ICON, + 16, + 16, + 0); + + SendMessage(hDlg, + WM_SETICON, + ICON_SMALL, + (LPARAM)hIcon); + + hHelp = GetDlgItem(hDlg, + IDC_CREATE_HELP); + + LoadString(hInstance, + IDS_HELP_OPTIONS, + Buf, + sizeof(Buf) / sizeof(TCHAR)); + + SetWindowText(hHelp, + Buf); + return TRUE; } - break; - - case WM_DESTROY: - bHelpOpen = FALSE; - break; + + case WM_COMMAND: + { + if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) + { + bHelpOpen = FALSE; + DestroyIcon(hIcon); + DestroyWindow(hDlg); + return TRUE; + } + break; + } }
return FALSE; @@ -106,160 +307,94 @@
BOOL CALLBACK -CreateDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +CreateDialogProc(HWND hDlg, + UINT message, + WPARAM wParam, + LPARAM lParam) { HICON hIcon = NULL;
switch (message) { - case WM_INITDIALOG: - hIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0); - SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDOK: + case WM_INITDIALOG: + { + hIcon = LoadImage(hInstance, + MAKEINTRESOURCE(IDI_SM_ICON), + IMAGE_ICON, + 16, + 16, + 0); + + SendMessage(hDlg, + WM_SETICON, + ICON_SMALL, + (LPARAM)hIcon); + return TRUE; + } + + case WM_COMMAND: + { + switch (LOWORD(wParam)) { - LPTSTR ServiceName = NULL; - LPTSTR DisplayName = NULL; - LPTSTR BinPath = NULL; - LPTSTR Description = NULL; - LPTSTR Options = NULL; - HWND hwnd; - TCHAR Buf[32]; - INT iLen = 0; - - /* get service name */ - hwnd = GetDlgItem(hDlg, IDC_CREATE_SERVNAME); - iLen = GetWindowTextLength(hwnd); - if (iLen != 0) + case IDOK: { - ServiceName = HeapAlloc(GetProcessHeap(), 0, iLen+1); - if (ServiceName != NULL) + PCREATE_DATA Data; + + Data = HeapAlloc(ProcessHeap, + HEAP_ZERO_MEMORY, + sizeof(CREATE_DATA)); + if (Data != NULL) { - GetWindowText(hwnd, ServiceName, iLen+1); + Data->hSelf = hDlg; + + if (GetDataFromDialog(Data)) + { + DoCreate(Data); + } + else + { + /* Something went wrong, leave the dialog + * open so they can try again */ + FreeMemory(Data); + break; + } + + FreeMemory(Data); }
+ DestroyIcon(hIcon); + EndDialog(hDlg, + LOWORD(wParam)); + return TRUE; } - else + + case IDCANCEL: { - LoadString(hInstance, IDS_CREATE_REQ, Buf, - sizeof(Buf) / sizeof(TCHAR)); - DisplayString(Buf); - SetFocus(hwnd); - break; + DestroyIcon(hIcon); + EndDialog(hDlg, + LOWORD(wParam)); + return TRUE; }
- /* get display name */ - iLen = 0; - hwnd = GetDlgItem(hDlg, IDC_CREATE_DISPNAME); - iLen = GetWindowTextLength(hwnd); - if (iLen != 0) + case ID_CREATE_HELP: { - DisplayName = HeapAlloc(GetProcessHeap(), 0, iLen+1); - if (DisplayName != NULL) - GetWindowText(hwnd, DisplayName, iLen+1); - - } - else - { - LoadString(hInstance, IDS_CREATE_REQ, Buf, - sizeof(Buf) / sizeof(TCHAR)); - DisplayString(Buf); - SetFocus(hwnd); - break; - } - - /* get binary path */ - iLen = 0; - hwnd = GetDlgItem(hDlg, IDC_CREATE_PATH); - iLen = GetWindowTextLength(hwnd); - if (iLen != 0) - { - BinPath = HeapAlloc(GetProcessHeap(), 0, iLen+1); - if (BinPath != NULL) - GetWindowText(hwnd, BinPath, iLen+1); - - } - else - { - LoadString(hInstance, IDS_CREATE_REQ, Buf, - sizeof(Buf) / sizeof(TCHAR)); - DisplayString(Buf); - SetFocus(hwnd); - break; - } - - /* get description */ - iLen = 0; - hwnd = GetDlgItem(hDlg, IDC_CREATE_DESC); - iLen = GetWindowTextLength(hwnd); - if (iLen != 0) - { - Description = HeapAlloc(GetProcessHeap(), 0, iLen+1); - if (Description != NULL) - GetWindowText(hwnd, Description, iLen+1); - - } - - /* get options */ - iLen = 0; - hwnd = GetDlgItem(hDlg, IDC_CREATE_PATH); - iLen = GetWindowTextLength(hwnd); - if (iLen != 0) - { - Options = HeapAlloc(GetProcessHeap(), 0, iLen+1); - if (Options != NULL) - GetWindowText(hwnd, Options, iLen+1); - - } - - Create(ServiceName, DisplayName, BinPath, Description, Options); - - if (ServiceName != NULL) - HeapFree(GetProcessHeap(), 0, ServiceName); - if (DisplayName != NULL) - HeapFree(GetProcessHeap(), 0, DisplayName); - if (BinPath != NULL) - HeapFree(GetProcessHeap(), 0, BinPath); - if (Description != NULL) - HeapFree(GetProcessHeap(), 0, Description); - if (Options != NULL) - HeapFree(GetProcessHeap(), 0, Options); - - - DestroyIcon(hIcon); - EndDialog(hDlg, LOWORD(wParam)); - return TRUE; - } - - case IDCANCEL: - DestroyIcon(hIcon); - EndDialog(hDlg, LOWORD(wParam)); - return TRUE; - - case ID_CREATE_HELP: - { - HWND hHelp; - - if (! bHelpOpen) - { - hHelp = CreateDialog(hInstance, - MAKEINTRESOURCE(IDD_DLG_HELP_OPTIONS), - hDlg, - (DLGPROC)CreateHelpDialogProc); - if(hHelp != NULL) + HWND hHelp; + + if (! bHelpOpen) { - ShowWindow(hHelp, SW_SHOW); - bHelpOpen = TRUE; + hHelp = CreateDialog(hInstance, + MAKEINTRESOURCE(IDD_DLG_HELP_OPTIONS), + hDlg, + (DLGPROC)CreateHelpDialogProc); + if(hHelp != NULL) + { + bHelpOpen = TRUE; + } } } + break; } - break; - } - + } }
return FALSE;
Modified: trunk/reactos/base/applications/servman/delete.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/de... ============================================================================== --- trunk/reactos/base/applications/servman/delete.c (original) +++ trunk/reactos/base/applications/servman/delete.c Fri Jun 2 20:47:39 2006 @@ -15,7 +15,6 @@ { SC_HANDLE hSCManager; SC_HANDLE hSc; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL;
/* open handle to the SCM */ hSCManager = OpenSCManager(NULL, @@ -27,23 +26,23 @@ return FALSE; }
- /* copy pointer to selected service */ - Service = GetSelectedService(Info); - - /* get a handle to the service requested for starting */ + /* get a handle to the service requested for deleting */ hSc = OpenService(hSCManager, - Service->lpServiceName, + Info->CurrentService->lpServiceName, DELETE); if (hSc == NULL) { GetError(); + CloseServiceHandle(hSCManager); return FALSE; }
- /* start the service opened */ + /* delete the service opened */ if (! DeleteService(hSc)) { GetError(); + CloseServiceHandle(hSCManager); + CloseServiceHandle(hSc); return FALSE; }
@@ -55,9 +54,6 @@ }
-#ifdef _MSC_VER -#pragma warning(disable : 4100) -#endif BOOL CALLBACK DeleteDialogProc(HWND hDlg, UINT message, @@ -65,76 +61,80 @@ LPARAM lParam) { PMAIN_WND_INFO Info = NULL; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; HICON hIcon = NULL; TCHAR Buf[1000]; LVITEM item;
switch (message) { - case WM_INITDIALOG: - { - Info = (PMAIN_WND_INFO)lParam; + case WM_INITDIALOG: + { + Info = (PMAIN_WND_INFO)lParam;
- hIcon = LoadImage(hInstance, - MAKEINTRESOURCE(IDI_SM_ICON), - IMAGE_ICON, - 16, - 16, - 0); + hIcon = LoadImage(hInstance, + MAKEINTRESOURCE(IDI_SM_ICON), + IMAGE_ICON, + 16, + 16, + 0);
- SendMessage(hDlg, - WM_SETICON, - ICON_SMALL, - (LPARAM)hIcon); + SendMessage(hDlg, + WM_SETICON, + ICON_SMALL, + (LPARAM)hIcon);
- /* get pointer to selected service */ - Service = GetSelectedService(Info); - - SendDlgItemMessage(hDlg, - IDC_DEL_NAME, - WM_SETTEXT, - 0, - (LPARAM)Service->lpDisplayName); + SendDlgItemMessage(hDlg, + IDC_DEL_NAME, + WM_SETTEXT, + 0, + (LPARAM)Info->CurrentService->lpDisplayName);
- item.mask = LVIF_TEXT; - item.iItem = Info->SelectedItem; - item.iSubItem = 1; - item.pszText = Buf; - item.cchTextMax = sizeof(Buf); - SendMessage(Info->hListView, - LVM_GETITEM, - 0, - (LPARAM)&item); + item.mask = LVIF_TEXT; + item.iItem = Info->SelectedItem; + item.iSubItem = 1; + item.pszText = Buf; + item.cchTextMax = sizeof(Buf); + SendMessage(Info->hListView, + LVM_GETITEM, + 0, + (LPARAM)&item);
- SendDlgItemMessage(hDlg, - IDC_DEL_DESC, - WM_SETTEXT, - 0, - (LPARAM)Buf); + SendDlgItemMessage(hDlg, + IDC_DEL_DESC, + WM_SETTEXT, + 0, + (LPARAM)Buf);
- return TRUE; - } + SetFocus(GetDlgItem(hDlg, IDCANCEL));
- case WM_COMMAND: - switch (LOWORD(wParam)) + return TRUE; + } + + case WM_COMMAND: { - case IDOK: - if (DoDeleteService(Info, hDlg)) - (void)ListView_DeleteItem(Info->hListView, - Info->SelectedItem); + switch (LOWORD(wParam)) + { + case IDOK: + { + if (DoDeleteService(Info, hDlg)) + (void)ListView_DeleteItem(Info->hListView, + Info->SelectedItem);
- DestroyIcon(hIcon); - EndDialog(hDlg, - LOWORD(wParam)); - return TRUE; + DestroyIcon(hIcon); + EndDialog(hDlg, + LOWORD(wParam)); + return TRUE; + }
- case IDCANCEL: - DestroyIcon(hIcon); - EndDialog(hDlg, - LOWORD(wParam)); - return TRUE; + case IDCANCEL: + { + DestroyIcon(hIcon); + EndDialog(hDlg, + LOWORD(wParam)); + return TRUE; + } + } } }
Modified: trunk/reactos/base/applications/servman/mainwnd.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/ma... ============================================================================== --- trunk/reactos/base/applications/servman/mainwnd.c (original) +++ trunk/reactos/base/applications/servman/mainwnd.c Fri Jun 2 20:47:39 2006 @@ -13,7 +13,6 @@
BOOL bSortAscending = TRUE;
-extern HWND hwndGenDlg;
/* Toolbar buttons */ TBBUTTON tbb [NUM_BUTTONS] = @@ -43,19 +42,24 @@ };
-VOID SetView(HWND hListView, DWORD View) +static VOID +SetListViewStyle(HWND hListView, + DWORD View) { DWORD Style = GetWindowLong(hListView, GWL_STYLE);
if ((Style & LVS_TYPEMASK) != View) - SetWindowLong(hListView, GWL_STYLE, (Style & ~LVS_TYPEMASK) | View); + { + SetWindowLong(hListView, + GWL_STYLE, + (Style & ~LVS_TYPEMASK) | View); + } }
VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info) { HMENU hMainMenu; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; DWORD Flags, State;
/* get handle to menu */ @@ -85,11 +89,8 @@
if (Info->SelectedItem != NO_ITEM_SELECTED) { - /* get pointer to selected service */ - Service = GetSelectedService(Info); - - Flags = Service->ServiceStatusProcess.dwControlsAccepted; - State = Service->ServiceStatusProcess.dwCurrentState; + Flags = Info->CurrentService->ServiceStatusProcess.dwControlsAccepted; + State = Info->CurrentService->ServiceStatusProcess.dwCurrentState;
if (State == SERVICE_STOPPED) { @@ -135,7 +136,8 @@ }
-INT CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) +static INT CALLBACK +CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { ENUM_SERVICE_STATUS_PROCESS *Param1; ENUM_SERVICE_STATUS_PROCESS *Param2; @@ -464,11 +466,7 @@
case ID_DELETE: { - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; - - Service = GetSelectedService(Info); - - if (Service->ServiceStatusProcess.dwCurrentState != SERVICE_RUNNING) + if (Info->CurrentService->ServiceStatusProcess.dwCurrentState != SERVICE_RUNNING) { DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DLG_DELETE), @@ -547,23 +545,23 @@ break;
case ID_VIEW_LARGE: - SetView(Info->hListView, - LVS_ICON); + SetListViewStyle(Info->hListView, + LVS_ICON); break;
case ID_VIEW_SMALL: - SetView(Info->hListView, - LVS_SMALLICON); + SetListViewStyle(Info->hListView, + LVS_SMALLICON); break;
case ID_VIEW_LIST: - SetView(Info->hListView, - LVS_LIST); + SetListViewStyle(Info->hListView, + LVS_LIST); break;
case ID_VIEW_DETAILS: - SetView(Info->hListView, - LVS_REPORT); + SetListViewStyle(Info->hListView, + LVS_REPORT); break;
case ID_VIEW_CUSTOMIZE: @@ -606,6 +604,7 @@
/* Initialize the main window context */ Info->hMainWnd = hwnd; + Info->SelectedItem = NO_ITEM_SELECTED;
SetWindowLongPtr(hwnd, GWLP_USERDATA, @@ -670,7 +669,6 @@ case LVN_ITEMCHANGED: { LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; HMENU hMainMenu;
/* get handle to menu */ @@ -680,9 +678,11 @@ if (GetMenuState(hMainMenu, ID_PROP, MF_BYCOMMAND) != MF_ENABLED) + { EnableMenuItem(hMainMenu, ID_PROP, MF_ENABLED); + }
/* activate delete menu item, if not already */ if (GetMenuState(hMainMenu, @@ -698,20 +698,20 @@ }
- /* globally set selected service */ + /* set selected service */ Info->SelectedItem = pnmv->iItem; + + /* get pointer to selected service */ + Info->CurrentService = GetSelectedService(Info);
/* alter options for the service */ SetMenuAndButtonStates(Info); - - /* get pointer to selected service */ - Service = GetSelectedService(Info);
/* set current selected service in the status bar */ SendMessage(Info->hStatus, SB_SETTEXT, 1, - (LPARAM)Service->lpDisplayName); + (LPARAM)Info->CurrentService->lpDisplayName);
/* show the properties button */ SendMessage(Info->hTool,
Modified: trunk/reactos/base/applications/servman/misc.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/mi... ============================================================================== --- trunk/reactos/base/applications/servman/misc.c (original) +++ trunk/reactos/base/applications/servman/misc.c Fri Jun 2 20:47:39 2006 @@ -1,3 +1,12 @@ +/* + * PROJECT: ReactOS Services + * LICENSE: GPL - See COPYING in the top level directory + * FILE: base/system/servman/misc.c + * PURPOSE: miscallanous functions + * COPYRIGHT: Copyright 2006 Ged Murphy gedmurphy@gmail.com + * + */ + #include "precomp.h"
static INT @@ -201,7 +210,7 @@
VOID DisplayString(PTCHAR Msg) { - MessageBox(NULL, Msg, _T("Note!"), MB_OK); + MessageBox(NULL, Msg, _T("Note!"), MB_ICONEXCLAMATION|MB_OK); }
Modified: trunk/reactos/base/applications/servman/precomp.h URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/pr... ============================================================================== --- trunk/reactos/base/applications/servman/precomp.h (original) +++ trunk/reactos/base/applications/servman/precomp.h Fri Jun 2 20:47:39 2006 @@ -49,6 +49,7 @@ /* Stores the current selected service */ ENUM_SERVICE_STATUS_PROCESS *CurrentService;
+ /* selection number in the list view */ INT SelectedItem;
struct _PROP_DLG_INFO *PropSheet;
Modified: trunk/reactos/base/applications/servman/propsheet.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/pr... ============================================================================== --- trunk/reactos/base/applications/servman/propsheet.c (original) +++ trunk/reactos/base/applications/servman/propsheet.c Fri Jun 2 20:47:39 2006 @@ -9,42 +9,36 @@
#include "precomp.h"
-HWND hwndGenDlg; - static VOID SetButtonStates(PMAIN_WND_INFO Info) { HWND hButton; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; DWORD Flags, State;
- /* get pointer to selected service */ - Service = GetSelectedService(Info); - - Flags = Service->ServiceStatusProcess.dwControlsAccepted; - State = Service->ServiceStatusProcess.dwCurrentState; + Flags = Info->CurrentService->ServiceStatusProcess.dwControlsAccepted; + State = Info->CurrentService->ServiceStatusProcess.dwCurrentState;
if (State == SERVICE_STOPPED) { - hButton = GetDlgItem(hwndGenDlg, IDC_START); + hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_START); EnableWindow (hButton, TRUE); }
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) ) { - hButton = GetDlgItem(hwndGenDlg, IDC_STOP); + hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_STOP); EnableWindow (hButton, TRUE); }
if ( (Flags & SERVICE_ACCEPT_PAUSE_CONTINUE) && (State == SERVICE_RUNNING) ) { - hButton = GetDlgItem(hwndGenDlg, IDC_PAUSE); + hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_PAUSE); EnableWindow (hButton, TRUE); }
if ( (Flags & SERVICE_ACCEPT_STOP) && (State == SERVICE_RUNNING) ) { - hButton = GetDlgItem(hwndGenDlg, IDC_PAUSE); + hButton = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_PAUSE); EnableWindow (hButton, TRUE); } } @@ -54,7 +48,7 @@ * values and sets it to value of the selected item */ static VOID -SetStartupType(LPTSTR lpServiceName) +SetStartupType(PMAIN_WND_INFO Info) { HWND hList; HKEY hKey; @@ -65,14 +59,18 @@ TCHAR KeyBuf[300];
/* open the registry key for the service */ - _sntprintf(KeyBuf, sizeof(KeyBuf) / sizeof(TCHAR), Path, lpServiceName); + _sntprintf(KeyBuf, + sizeof(KeyBuf) / sizeof(TCHAR), + Path, + Info->CurrentService->lpServiceName); + RegOpenKeyEx(HKEY_LOCAL_MACHINE, KeyBuf, 0, KEY_READ, &hKey);
- hList = GetDlgItem(hwndGenDlg, IDC_START_TYPE); + hList = GetDlgItem(Info->PropSheet->hwndGenDlg, IDC_START_TYPE);
LoadString(hInstance, IDS_SERVICES_AUTO, buf, sizeof(buf) / sizeof(TCHAR)); SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf); @@ -110,30 +108,25 @@ static VOID GetDlgInfo(PMAIN_WND_INFO Info) { - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; - - /* get pointer to selected service */ - Service = GetSelectedService(Info); - /* set the service name */ - Info->PropSheet->lpServiceName = Service->lpServiceName; - SendDlgItemMessage(hwndGenDlg, + Info->PropSheet->lpServiceName = Info->CurrentService->lpServiceName; + SendDlgItemMessage(Info->PropSheet->hwndGenDlg, IDC_SERV_NAME, WM_SETTEXT, 0, (LPARAM)Info->PropSheet->lpServiceName);
/* set the display name */ - Info->PropSheet->lpDisplayName = Service->lpDisplayName; - SendDlgItemMessage(hwndGenDlg, + Info->PropSheet->lpDisplayName = Info->CurrentService->lpDisplayName; + SendDlgItemMessage(Info->PropSheet->hwndGenDlg, IDC_DISP_NAME, WM_SETTEXT, 0, (LPARAM)Info->PropSheet->lpDisplayName);
/* set the description */ - if (GetDescription(Service->lpServiceName, &Info->PropSheet->lpDescription)) - SendDlgItemMessage(hwndGenDlg, + if (GetDescription(Info->CurrentService->lpServiceName, &Info->PropSheet->lpDescription)) + SendDlgItemMessage(Info->PropSheet->hwndGenDlg, IDC_DESCRIPTION, WM_SETTEXT, 0, @@ -141,24 +134,24 @@
/* set the executable path */ if (GetExecutablePath(Info, &Info->PropSheet->lpPathToExe)) - SendDlgItemMessage(hwndGenDlg, + SendDlgItemMessage(Info->PropSheet->hwndGenDlg, IDC_EXEPATH, WM_SETTEXT, 0, (LPARAM)Info->PropSheet->lpPathToExe);
/* set startup type */ - SetStartupType(Service->lpServiceName); + SetStartupType(Info);
/* set service status */ - if (Service->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING) + if (Info->CurrentService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING) { LoadString(hInstance, IDS_SERVICES_STARTED, Info->PropSheet->szServiceStatus, sizeof(Info->PropSheet->szServiceStatus) / sizeof(TCHAR));
- SendDlgItemMessage(hwndGenDlg, + SendDlgItemMessage(Info->PropSheet->hwndGenDlg, IDC_SERV_STATUS, WM_SETTEXT, 0, @@ -171,7 +164,7 @@ Info->PropSheet->szServiceStatus, sizeof(Info->PropSheet->szServiceStatus) / sizeof(TCHAR));
- SendDlgItemMessage(hwndGenDlg, + SendDlgItemMessage(Info->PropSheet->hwndGenDlg, IDC_SERV_STATUS, WM_SETTEXT, 0, @@ -194,11 +187,7 @@ { PMAIN_WND_INFO Info;
- /* FIXME get rid of this */ - hwndGenDlg = hwndDlg; - /* Get the window context */ - /* FIXME: does this get called in time for WM_INITDIALOG */ Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
@@ -214,6 +203,8 @@ Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam); if (Info != NULL) { + Info->PropSheet->hwndGenDlg = hwndDlg; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)Info); @@ -293,9 +284,6 @@ { PMAIN_WND_INFO Info;
- /* FIXME get rid of this */ - hwndGenDlg = hwndDlg; - /* Get the window context */ Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); @@ -312,6 +300,8 @@ Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam); if (Info != NULL) { + Info->PropSheet->hwndDepDlg = hwndDlg; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)Info); @@ -403,9 +393,6 @@ { PROPSHEETHEADER psh; PROPSHEETPAGE psp[2]; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; - - Service = GetSelectedService(Info);
ZeroMemory(&psh, sizeof(PROPSHEETHEADER)); psh.dwSize = sizeof(PROPSHEETHEADER); @@ -413,7 +400,7 @@ psh.hwndParent = Info->hMainWnd; psh.hInstance = hInstance; psh.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON)); - psh.pszCaption = Service->lpDisplayName; + psh.pszCaption = Info->CurrentService->lpDisplayName; psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE); psh.nStartPage = 0; psh.pfnCallback = AddEditButton;
Modified: trunk/reactos/base/applications/servman/query.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/qu... ============================================================================== --- trunk/reactos/base/applications/servman/query.c (original) +++ trunk/reactos/base/applications/servman/query.c Fri Jun 2 20:47:39 2006 @@ -10,11 +10,9 @@ #include "precomp.h"
- ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(PMAIN_WND_INFO Info) { - ENUM_SERVICE_STATUS_PROCESS *pSelectedService = NULL; LVITEM lvItem;
lvItem.mask = LVIF_PARAM; @@ -24,10 +22,8 @@ 0, (LPARAM)&lvItem);
- /* copy pointer to selected service */ - pSelectedService = (ENUM_SERVICE_STATUS_PROCESS *)lvItem.lParam; - - return pSelectedService; + /* return pointer to selected service */ + return (ENUM_SERVICE_STATUS_PROCESS *)lvItem.lParam; }
@@ -100,7 +96,9 @@
if (ret != ERROR_FILE_NOT_FOUND) { - Description = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize); + Description = HeapAlloc(ProcessHeap, + HEAP_ZERO_MEMORY, + dwValueSize); if (Description == NULL) { RegCloseKey(hKey); @@ -114,7 +112,9 @@ (LPBYTE)Description, &dwValueSize)) { - HeapFree(GetProcessHeap(), 0, Description); + HeapFree(ProcessHeap, + 0, + Description); RegCloseKey(hKey); return FALSE; } @@ -135,11 +135,7 @@ SC_HANDLE hSCManager = NULL; SC_HANDLE hSc = NULL; LPQUERY_SERVICE_CONFIG pServiceConfig = NULL; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; DWORD BytesNeeded = 0; - - /* copy pointer to selected service */ - Service = GetSelectedService(Info);
/* open handle to the SCM */ hSCManager = OpenSCManager(NULL, @@ -153,7 +149,7 @@
/* get a handle to the service requested for starting */ hSc = OpenService(hSCManager, - Service->lpServiceName, + Info->CurrentService->lpServiceName, SERVICE_QUERY_CONFIG); if (hSc == NULL) { @@ -170,7 +166,7 @@ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { pServiceConfig = (LPQUERY_SERVICE_CONFIG) - HeapAlloc(GetProcessHeap(), + HeapAlloc(ProcessHeap, 0, BytesNeeded); if (pServiceConfig == NULL)
Modified: trunk/reactos/base/applications/servman/servman.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/se... ============================================================================== --- trunk/reactos/base/applications/servman/servman.c (original) +++ trunk/reactos/base/applications/servman/servman.c Fri Jun 2 20:47:39 2006 @@ -2,7 +2,7 @@ * PROJECT: ReactOS Services * LICENSE: GPL - See COPYING in the top level directory * FILE: base/system/servman/servman.c - * PURPOSE: HQ + * PURPOSE: Program HQ * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com * */ @@ -31,7 +31,9 @@ icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES; InitCommonControlsEx(&icex);
- if (!AllocAndLoadString(&lpAppName, hInstance, IDS_APPNAME)) + if (!AllocAndLoadString(&lpAppName, + hInstance, + IDS_APPNAME)) { return 1; }
Modified: trunk/reactos/base/applications/servman/start.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/st... ============================================================================== --- trunk/reactos/base/applications/servman/start.c (original) +++ trunk/reactos/base/applications/servman/start.c Fri Jun 2 20:47:39 2006 @@ -9,8 +9,6 @@
#include "precomp.h"
-extern HWND hwndGenDlg; - static BOOL DoStartService(PMAIN_WND_INFO Info) { @@ -18,13 +16,10 @@ SC_HANDLE hSCManager; SC_HANDLE hSc; SERVICE_STATUS_PROCESS ServiceStatus; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; /* FIXME: get rid of this */ DWORD BytesNeeded = 0; INT ArgCount = 0; DWORD dwStartTickCount, dwOldCheckPoint;
- /* copy pointer to selected service */ - Service = GetSelectedService(Info);
/* set the progress bar range and step */ hProgBar = GetDlgItem(Info->hProgDlg, @@ -51,7 +46,9 @@ }
/* get a handle to the service requested for starting */ - hSc = OpenService(hSCManager, Service->lpServiceName, SERVICE_ALL_ACCESS); + hSc = OpenService(hSCManager, + Info->CurrentService->lpServiceName, + SERVICE_ALL_ACCESS); if (hSc == NULL) { GetError(); @@ -59,7 +56,9 @@ }
/* start the service opened */ - if (! StartService(hSc, ArgCount, NULL)) + if (! StartService(hSc, + ArgCount, + NULL)) { GetError(); return FALSE; @@ -100,12 +99,11 @@ Sleep(ServiceStatus.dwWaitHint / 8);
/* check status again */ - if (! QueryServiceStatusEx( - hSc, - SC_STATUS_PROCESS_INFO, - (LPBYTE)&ServiceStatus, - sizeof(SERVICE_STATUS_PROCESS), - &BytesNeeded)) + if (! QueryServiceStatusEx(hSc, + SC_STATUS_PROCESS_INFO, + (LPBYTE)&ServiceStatus, + sizeof(SERVICE_STATUS_PROCESS), + &BytesNeeded)) { GetError(); return FALSE; @@ -132,7 +130,10 @@
if (ServiceStatus.dwCurrentState == SERVICE_RUNNING) { - SendMessage(hProgBar, PBM_DELTAPOS, PROGRESSRANGE, 0); + SendMessage(hProgBar, + PBM_DELTAPOS, + PROGRESSRANGE, + 0); Sleep(1000); return TRUE; } @@ -148,7 +149,6 @@ DoStart(PMAIN_WND_INFO Info) { HWND hProgDlg; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; TCHAR ProgDlgBuf[100];
/* open the progress dialog */ @@ -173,15 +173,12 @@ 0, (LPARAM)ProgDlgBuf);
- /* get pointer to selected service */ - Service = GetSelectedService(Info); - /* write the service name to the progress dialog */ SendDlgItemMessage(hProgDlg, IDC_SERVCON_NAME, WM_SETTEXT, 0, - (LPARAM)Service->lpServiceName); + (LPARAM)Info->CurrentService->lpServiceName); }
/* start the service */ @@ -204,13 +201,14 @@ (LPARAM) &item);
/* change dialog status */ - if (hwndGenDlg) + if (Info->PropSheet->hwndGenDlg) { LoadString(hInstance, IDS_SERVICES_STARTED, buf, sizeof(buf) / sizeof(TCHAR)); - SendDlgItemMessageW(hwndGenDlg, + + SendDlgItemMessageW(Info->PropSheet->hwndGenDlg, IDC_SERV_STATUS, WM_SETTEXT, 0,
Modified: trunk/reactos/base/applications/servman/stop.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/base/applications/servman/st... ============================================================================== --- trunk/reactos/base/applications/servman/stop.c (original) +++ trunk/reactos/base/applications/servman/stop.c Fri Jun 2 20:47:39 2006 @@ -1,7 +1,7 @@ /* * PROJECT: ReactOS Services * LICENSE: GPL - See COPYING in the top level directory - * FILE: base/system/servman/start.c + * FILE: base/system/servman/stop.c * PURPOSE: Stops a service * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy gedmurphy@gmail.com * @@ -9,12 +9,9 @@
#include "precomp.h"
-extern HWND hwndGenDlg; - BOOL DoStop(PMAIN_WND_INFO Info) { HWND hProgDlg; - ENUM_SERVICE_STATUS_PROCESS *Service = NULL; TCHAR ProgDlgBuf[100];
/* open the progress dialog */ @@ -32,24 +29,22 @@ IDS_PROGRESS_INFO_STOP, ProgDlgBuf, sizeof(ProgDlgBuf) / sizeof(TCHAR)); + SendDlgItemMessage(hProgDlg, IDC_SERVCON_INFO, WM_SETTEXT, 0, (LPARAM)ProgDlgBuf);
- /* get pointer to selected service */ - Service = GetSelectedService(Info); - /* write the service name to the progress dialog */ SendDlgItemMessage(hProgDlg, IDC_SERVCON_NAME, WM_SETTEXT, 0, - (LPARAM)Service->lpServiceName); + (LPARAM)Info->CurrentService->lpServiceName); }
- if( Control(Info, SERVICE_CONTROL_STOP) ) + if ( Control(Info, SERVICE_CONTROL_STOP) ) { LVITEM item; TCHAR buf[25]; @@ -63,13 +58,14 @@ (LPARAM) &item);
/* change dialog status */ - if (hwndGenDlg) + if (Info->PropSheet->hwndGenDlg) { LoadString(hInstance, IDS_SERVICES_STOPPED, buf, sizeof(buf) / sizeof(TCHAR)); - SendDlgItemMessageW(hwndGenDlg, + + SendDlgItemMessageW(Info->PropSheet->hwndGenDlg, IDC_SERV_STATUS, WM_SETTEXT, 0, (LPARAM)buf);