From 044a7022c513019571be161df99763cc4ad7f697 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Tue, 11 Dec 2018 15:03:09 +0100 Subject: [PATCH] [VCDCONTROLTOOL] Enable driver start/stop buttons depending on the service status --- .../vcdcontroltool/vcdcontroltool.c | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/rosapps/applications/vcdcontroltool/vcdcontroltool.c b/modules/rosapps/applications/vcdcontroltool/vcdcontroltool.c index 542bb1dcbb2..b2245c6cde9 100644 --- a/modules/rosapps/applications/vcdcontroltool/vcdcontroltool.c +++ b/modules/rosapps/applications/vcdcontroltool/vcdcontroltool.c @@ -182,6 +182,20 @@ RefreshDevicesList(WCHAR Letter) } } +VOID +SetServiceState(BOOLEAN Started) +{ + HWND hControl; + + /* If started, disable start button */ + hControl = GetDlgItem(hDriverWnd, IDC_DRIVERSTART); + EnableWindow(hControl, !Started); + + /* If started, enable stop button */ + hControl = GetDlgItem(hDriverWnd, IDC_DRIVERSTOP); + EnableWindow(hControl, Started); +} + INT_PTR QueryDriverInfo(HWND hDlg) { @@ -190,6 +204,7 @@ QueryDriverInfo(HWND hDlg) LPQUERY_SERVICE_CONFIGW pConfig; WCHAR szText[2 * MAX_PATH]; HWND hControl; + SERVICE_STATUS Status; hDriverWnd = hDlg; @@ -198,7 +213,7 @@ QueryDriverInfo(HWND hDlg) if (hMgr != NULL) { /* Open our service */ - hSvc = OpenService(hMgr, L"Vcdrom", SERVICE_QUERY_CONFIG); + hSvc = OpenService(hMgr, L"Vcdrom", SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS); if (hSvc != NULL) { /* Probe its config size */ @@ -219,6 +234,20 @@ QueryDriverInfo(HWND hDlg) HeapFree(GetProcessHeap(), 0, pConfig); } + /* Get its status */ + if (QueryServiceStatus(hSvc, &Status)) + { + if (Status.dwCurrentState != SERVICE_RUNNING && + Status.dwCurrentState != SERVICE_START_PENDING) + { + SetServiceState(FALSE); + } + else + { + SetServiceState(TRUE); + } + } + CloseServiceHandle(hSvc); } @@ -261,6 +290,9 @@ StartDriver(VOID) /* Refresh the list in case there were persistent mounts */ RefreshDevicesList(0); + + /* Update buttons */ + SetServiceState(TRUE); } CloseServiceHandle(hMgr); @@ -290,6 +322,9 @@ StopDriver(VOID) /* Refresh the list to clear it */ RefreshDevicesList(0); + + /* Update buttons */ + SetServiceState(FALSE); } CloseServiceHandle(hMgr);