[Servman] Make the property sheets modeless so users can open multiple services at...
[reactos.git] / base / applications / mscutils / servman / propsheet.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/propsheet.c
5 * PURPOSE: Property dialog box message handler
6 * COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10 #include "precomp.h"
11
12 unsigned int __stdcall PropSheetThread(void* Param);
13
14 static VOID
15 InitPropSheetPage(PROPSHEETPAGE *psp,
16 PSERVICEPROPSHEET dlgInfo,
17 WORD idDlg,
18 DLGPROC DlgProc)
19 {
20 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
21 psp->dwSize = sizeof(PROPSHEETPAGE);
22 psp->dwFlags = PSP_DEFAULT;
23 psp->hInstance = hInstance;
24 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
25 psp->pfnDlgProc = DlgProc;
26 psp->lParam = (LPARAM)dlgInfo;
27 }
28
29 VOID
30 OpenPropSheet(PMAIN_WND_INFO Info)
31 {
32 HANDLE hThread;
33 hThread = (HANDLE)_beginthreadex(NULL, 0, &PropSheetThread, Info, 0, NULL);
34 if (hThread)
35 {
36 CloseHandle(hThread);
37 }
38 }
39
40
41 unsigned int __stdcall PropSheetThread(void* Param)
42 {
43 PROPSHEETHEADER psh;
44 PROPSHEETPAGE psp[4];
45 PSERVICEPROPSHEET pServicePropSheet;
46 HWND hDlg = NULL;
47 MSG Msg;
48
49 PMAIN_WND_INFO Info = (PMAIN_WND_INFO)Param;
50
51 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
52 psh.dwSize = sizeof(PROPSHEETHEADER);
53 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | PSH_MODELESS;
54 psh.hwndParent = Info->hMainWnd;
55 psh.hInstance = hInstance;
56 psh.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));
57 psh.pszCaption = Info->pCurrentService->lpDisplayName;
58 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
59 psh.nStartPage = 0;
60 psh.ppsp = psp;
61
62
63 pServicePropSheet = HeapAlloc(ProcessHeap,
64 0,
65 sizeof(*pServicePropSheet));
66 if (pServicePropSheet)
67 {
68 /* Save current service, as it could change while the dialog is open */
69 pServicePropSheet->pService = Info->pCurrentService;
70 pServicePropSheet->Info = Info;
71
72 InitPropSheetPage(&psp[0], pServicePropSheet, IDD_DLG_GENERAL, GeneralPageProc);
73 InitPropSheetPage(&psp[1], pServicePropSheet, IDD_LOGON, LogonPageProc);
74 InitPropSheetPage(&psp[2], pServicePropSheet, IDD_RECOVERY, RecoveryPageProc);
75 InitPropSheetPage(&psp[3], pServicePropSheet, IDD_DLG_DEPEND, DependenciesPageProc);
76
77 hDlg = (HWND)PropertySheetW(&psh);
78 if (hDlg)
79 {
80 /* Pump the message queue */
81 while (GetMessageW(&Msg, NULL, 0, 0))
82 {
83
84 if (PropSheet_GetCurrentPageHwnd(hDlg) == NULL)
85 {
86 /* The user hit the ok / cancel button, pull it down */
87 EnableWindow(Info->hMainWnd, TRUE);
88 DestroyWindow(hDlg);
89 }
90
91 if (PropSheet_IsDialogMessage(hDlg, &Msg) != 0)
92 {
93 TranslateMessage(&Msg);
94 DispatchMessageW(&Msg);
95 }
96 }
97 }
98
99 HeapFree(GetProcessHeap(), 0, pServicePropSheet);
100 }
101
102 return (hDlg != NULL);
103 }
104