[Servman] Make the property sheets modeless so users can open multiple services at...
authorGed Murphy <gedmurphy@reactos.org>
Tue, 5 Dec 2017 12:25:14 +0000 (12:25 +0000)
committerGitHub <noreply@github.com>
Tue, 5 Dec 2017 12:25:14 +0000 (12:25 +0000)
[SERVMAN]
- Make the property sheets modeless so users can open multiple services at the same time
- Untested in ros. In fact we have no code or tests cases to check that modeless property sheets work, so please raise a bug if you find any issues with the app.
- Dedicated to reactosfanboy

base/applications/mscutils/servman/precomp.h
base/applications/mscutils/servman/propsheet.c

index 661772f..051634d 100644 (file)
@@ -13,6 +13,7 @@
 #include <shlobj.h>
 #include <commdlg.h>
 #include <strsafe.h>
+#include <process.h>
 
 #include "resource.h"
 
@@ -155,7 +156,7 @@ VOID TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo, HTREEITEM hParent, LPWS
 BOOL TV2_HasDependantServices(LPWSTR lpServiceName);
 LPENUM_SERVICE_STATUS TV2_GetDependants(LPWSTR lpServiceName, LPDWORD lpdwCount);
 
-LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info);
+VOID OpenPropSheet(PMAIN_WND_INFO Info);
 
 /* propsheet window procs */
 INT_PTR CALLBACK DependenciesPageProc(HWND hwndDlg,
index dc978c8..9557420 100644 (file)
@@ -9,32 +9,48 @@
 
 #include "precomp.h"
 
+unsigned int __stdcall PropSheetThread(void* Param);
+
 static VOID
 InitPropSheetPage(PROPSHEETPAGE *psp,
                   PSERVICEPROPSHEET dlgInfo,
                   WORD idDlg,
                   DLGPROC DlgProc)
 {
-  ZeroMemory(psp, sizeof(PROPSHEETPAGE));
-  psp->dwSize = sizeof(PROPSHEETPAGE);
-  psp->dwFlags = PSP_DEFAULT;
-  psp->hInstance = hInstance;
-  psp->pszTemplate = MAKEINTRESOURCE(idDlg);
-  psp->pfnDlgProc = DlgProc;
-  psp->lParam = (LPARAM)dlgInfo;
+    ZeroMemory(psp, sizeof(PROPSHEETPAGE));
+    psp->dwSize = sizeof(PROPSHEETPAGE);
+    psp->dwFlags = PSP_DEFAULT;
+    psp->hInstance = hInstance;
+    psp->pszTemplate = MAKEINTRESOURCE(idDlg);
+    psp->pfnDlgProc = DlgProc;
+    psp->lParam = (LPARAM)dlgInfo;
 }
 
-LONG APIENTRY
+VOID
 OpenPropSheet(PMAIN_WND_INFO Info)
+{
+    HANDLE hThread;
+    hThread = (HANDLE)_beginthreadex(NULL, 0, &PropSheetThread, Info, 0, NULL);
+    if (hThread)
+    {
+        CloseHandle(hThread);
+    }
+}
+
+
+unsigned int __stdcall PropSheetThread(void* Param)
 {
     PROPSHEETHEADER psh;
     PROPSHEETPAGE psp[4];
     PSERVICEPROPSHEET pServicePropSheet;
-    LONG Ret = 0;
+    HWND hDlg = NULL;
+    MSG Msg;
+
+    PMAIN_WND_INFO Info = (PMAIN_WND_INFO)Param;
 
     ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
     psh.dwSize = sizeof(PROPSHEETHEADER);
-    psh.dwFlags =  PSH_PROPSHEETPAGE | PSH_PROPTITLE | PSH_USECALLBACK;// | PSH_MODELESS;
+    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | PSH_MODELESS;
     psh.hwndParent = Info->hMainWnd;
     psh.hInstance = hInstance;
     psh.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));
@@ -58,12 +74,31 @@ OpenPropSheet(PMAIN_WND_INFO Info)
         InitPropSheetPage(&psp[2], pServicePropSheet, IDD_RECOVERY, RecoveryPageProc);
         InitPropSheetPage(&psp[3], pServicePropSheet, IDD_DLG_DEPEND, DependenciesPageProc);
 
-        Ret = (LONG)(PropertySheet(&psh) != -1);
+        hDlg = (HWND)PropertySheetW(&psh);
+        if (hDlg)
+        {
+            /* Pump the message queue */
+            while (GetMessageW(&Msg, NULL, 0, 0))
+            {
+
+                if (PropSheet_GetCurrentPageHwnd(hDlg) == NULL)
+                {
+                    /* The user hit the ok / cancel button, pull it down */
+                    EnableWindow(Info->hMainWnd, TRUE);
+                    DestroyWindow(hDlg);
+                }
 
-        HeapFree(ProcessHeap,
-                 0,
-                 pServicePropSheet);
+                if (PropSheet_IsDialogMessage(hDlg, &Msg) != 0)
+                {
+                    TranslateMessage(&Msg);
+                    DispatchMessageW(&Msg);
+                }
+            }
+        }
+
+        HeapFree(GetProcessHeap(), 0, pServicePropSheet);
     }
 
-    return Ret;
+    return (hDlg != NULL);
 }
+