2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/msconfig_new/systempage.c
5 * PURPOSE: System page message handler
6 * COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de>
7 * 2011 Gregor Schneider <Gregor.Schneider@reactos.org>
8 * Copyright 2011-2012 Hermes BELUSCA - MAITO <hermes.belusca@sfr.fr>
15 #include "uxthemesupp.h"
23 LPCWSTR lpszSystemIni
= L
"%SystemRoot%\\system.ini"; // or: %windir%\\... ?
24 LPCWSTR lpszWinIni
= L
"%SystemRoot%\\win.ini"; // or: %windir%\\... ?
28 static LPCWSTR szMSConfigTok
= L
";msconfig "; // Note the trailing whitespace
29 static const size_t MSConfigTokLen
= 10;
34 DWORD
GetSystemIniActivation(VOID
)
36 DWORD dwSystemIni
= 0;
37 RegGetDWORDValue(HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\state", L
"system.ini", &dwSystemIni
);
41 DWORD
GetWinIniActivation(VOID
)
44 RegGetDWORDValue(HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\state", L
"win.ini", &dwWinIni
);
52 static HWND hTree
= NULL
;
53 static WCHAR szSearchString
[MAX_VALUE_NAME
] = L
"";
54 static BOOL bMatchExactText
= FALSE
;
55 static BOOL bSearchSense
= TRUE
; // TRUE == down, FALSE == up.
56 static BOOL bCaseSensitive
= FALSE
;
59 ToLower(LPWSTR lpszString
)
66 *lpszString
= towlower(*lpszString
);
72 FindDialogWndProc(HWND hDlg
,
77 UNREFERENCED_PARAMETER(lParam
);
85 Button_SetCheck(GetDlgItem(hDlg
, IDC_CBX_FIND_WHOLE_WORD_ONLY
), (bMatchExactText
? BST_CHECKED
: BST_UNCHECKED
));
86 Button_SetCheck(GetDlgItem(hDlg
, IDC_RB_FIND_DOWN
), (bSearchSense
? BST_CHECKED
: BST_UNCHECKED
)); // TRUE == down, FALSE == up.
87 Button_SetCheck(GetDlgItem(hDlg
, IDC_RB_FIND_UP
), (bSearchSense
? BST_UNCHECKED
: BST_CHECKED
)); // TRUE == down, FALSE == up.
88 Button_SetCheck(GetDlgItem(hDlg
, IDC_CBX_FIND_MATCH_CASE
), (bCaseSensitive
? BST_CHECKED
: BST_UNCHECKED
));
90 Edit_SetText(GetDlgItem(hDlg
, IDC_TXT_FIND_TEXT
), szSearchString
);
91 SetFocus(GetDlgItem(hDlg
, IDC_TXT_FIND_TEXT
));
92 Edit_SetSel(GetDlgItem(hDlg
, IDC_TXT_FIND_TEXT
), 0, -1);
99 switch (LOWORD(wParam
))
104 HTREEITEM htiIterator
;
105 WCHAR label
[MAX_VALUE_NAME
] = L
"";
106 WCHAR szTemp
[MAX_VALUE_NAME
];
108 bMatchExactText
= (Button_GetCheck(GetDlgItem(hDlg
, IDC_CBX_FIND_WHOLE_WORD_ONLY
)) == BST_CHECKED
);
109 bSearchSense
= ((Button_GetCheck(GetDlgItem(hDlg
, IDC_RB_FIND_DOWN
)) == BST_CHECKED
) &&
110 (Button_GetCheck(GetDlgItem(hDlg
, IDC_RB_FIND_UP
)) == BST_UNCHECKED
)); // TRUE == down, FALSE == up.
111 bCaseSensitive
= (Button_GetCheck(GetDlgItem(hDlg
, IDC_CBX_FIND_MATCH_CASE
)) == BST_CHECKED
);
113 Edit_GetText(GetDlgItem(hDlg
, IDC_TXT_FIND_TEXT
), szSearchString
, _ARRAYSIZE(szSearchString
));
114 wcscpy(szTemp
, szSearchString
);
118 for (htiIterator
= ((Button_GetCheck(GetDlgItem(hDlg
, IDC_CBX_FIND_FROM_BEGINNING
)) == BST_CHECKED
) ? (bSearchSense
? TreeView_GetFirst(hTree
)
119 : TreeView_GetLast(hTree
))
120 : (bSearchSense
? TreeView_GetNext(hTree
, TreeView_GetSelection(hTree
))
121 : TreeView_GetPrev(hTree
, TreeView_GetSelection(hTree
))));
123 htiIterator
= (bSearchSense
? TreeView_GetNext(hTree
, htiIterator
)
124 : TreeView_GetPrev(hTree
, htiIterator
)))
126 SecureZeroMemory(&tvItemEx
, sizeof(tvItemEx
));
128 tvItemEx
.hItem
= htiIterator
; // Handle of the item to be retrieved
129 tvItemEx
.mask
= TVIF_HANDLE
| TVIF_TEXT
;
130 tvItemEx
.pszText
= label
;
131 tvItemEx
.cchTextMax
= MAX_VALUE_NAME
;
132 TreeView_GetItem(hTree
, &tvItemEx
);
136 if (bMatchExactText
? (_tcscmp(label
, szTemp
) == 0) : !!_tcsstr(label
, szTemp
)) // <-- hackish. A arranger.
138 TreeView_SelectItem(hTree
, htiIterator
);
139 EndDialog(hDlg
, LOWORD(wParam
));
142 //MessageBox(NULL, label, _T("Info"), MB_ICONINFORMATION | MB_OK);
146 MessageBoxW(hDlg
, L
"No correspondence found.", szAppName
, MB_ICONINFORMATION
| MB_OK
);
147 SetFocus(GetDlgItem(hDlg
, IDC_TXT_FIND_TEXT
));
148 Edit_SetSel(GetDlgItem(hDlg
, IDC_TXT_FIND_TEXT
), 0, -1);
149 //EndDialog(hDlg, LOWORD(wParam));
154 EndDialog(hDlg
, LOWORD(wParam
));
170 TreeView_SetBOOLCheck(HWND hTree
, HTREEITEM htiItem
, BOOL bState
, BOOL bPropagateStateToParent
)
172 if (!hTree
|| !htiItem
)
175 TreeView_SetCheckState(hTree
, htiItem
, bState
);
178 * Add or remove the token for tree leaves only.
180 if (!TreeView_GetChild(hTree
, htiItem
))
182 /* 1- Retrieve properties */
184 SecureZeroMemory(&tvItemEx
, sizeof(tvItemEx
));
186 tvItemEx
.hItem
= htiItem
; // Handle of the item to be retrieved.
187 tvItemEx
.mask
= TVIF_HANDLE
| TVIF_TEXT
;
188 WCHAR label
[MAX_VALUE_NAME
] = L
"";
189 tvItemEx
.pszText
= label
;
190 tvItemEx
.cchTextMax
= MAX_VALUE_NAME
;
191 TreeView_GetItem(hTree
, &tvItemEx
);
195 /* 2- Add the token IF NEEDED */
196 if ((wcslen(tvItemEx
.pszText
) < MSConfigTokLen
) || (_wcsnicmp(tvItemEx
.pszText
, szMSConfigTok
, MSConfigTokLen
) != 0))
198 LPWSTR newLabel
= (LPWSTR
)MemAlloc(0, (_tcslen(tvItemEx
.pszText
) + MSConfigTokLen
+ 1) * sizeof(WCHAR
));
199 wcscpy(newLabel
, szMSConfigTok
);
200 wcscat(newLabel
, tvItemEx
.pszText
);
201 tvItemEx
.pszText
= newLabel
;
203 TreeView_SetItem(hTree
, &tvItemEx
);
210 /* 2- Remove the token IF NEEDED */
211 if ((wcslen(tvItemEx
.pszText
) >= MSConfigTokLen
) && (_wcsnicmp(tvItemEx
.pszText
, szMSConfigTok
, MSConfigTokLen
) == 0))
213 LPWSTR newLabel
= (LPWSTR
)MemAlloc(0, (_tcslen(tvItemEx
.pszText
) - MSConfigTokLen
+ 1) * sizeof(WCHAR
));
214 wcscpy(newLabel
, tvItemEx
.pszText
+ MSConfigTokLen
);
215 tvItemEx
.pszText
= newLabel
;
217 TreeView_SetItem(hTree
, &tvItemEx
);
219 // TODO: if one finds tvItemEx.pszText == L"", one can
220 // directly remove the item (cf. message TVN_ENDLABELEDIT).
226 ////////////////////////
228 for (HTREEITEM htiIterator
= TreeView_GetChild(hTree
, htiItem
) ; htiIterator
; htiIterator
= TreeView_GetNextSibling(hTree
, htiIterator
))
229 TreeView_SetBOOLCheck(hTree
, htiIterator
, bState
, FALSE
);
231 if (bPropagateStateToParent
)
232 TreeView_PropagateStateOfItemToParent(hTree
, htiItem
);
238 LoadIniFile(HWND hTree
, LPCWSTR lpszIniFile
)
240 // Ouverture en lecture (sans création de fichier si celui-ci n'esistait pas déjà )
241 // d'un flux en mode texte, avec permission de lecture seule.
242 DWORD dwNumOfChars
= ExpandEnvironmentStringsW(lpszIniFile
, NULL
, 0);
243 LPWSTR lpszFileName
= (LPWSTR
)MemAlloc(0, dwNumOfChars
* sizeof(WCHAR
));
244 ExpandEnvironmentStringsW(lpszIniFile
, lpszFileName
, dwNumOfChars
);
246 FILE* ini_file
= _wfsopen(lpszFileName
, L
"rt", _SH_DENYWR
); // r+t <-- read write text ; rt <-- read text
247 MemFree(lpszFileName
);
252 WCHAR szLine
[MAX_VALUE_NAME
] = L
"";
254 HTREEITEM hParent
= TVI_ROOT
;
255 BOOL bIsSection
= FALSE
;
259 while (!feof(ini_file
) && fgetws(szLine
, _ARRAYSIZE(szLine
), ini_file
))
261 /* Skip hypothetical starting spaces or newline characters */
263 while (*lpsz1
== L
' ' || *lpsz1
== L
'\r' || *lpsz1
== L
'\n')
266 /* Skip empty lines */
270 /* Find the last newline character (if exists) and replace it by the NULL terminator */
274 if (*lpsz2
== L
'\r' || *lpsz2
== L
'\n')
283 /* Check for new sections. They should be parent of ROOT. */
290 SecureZeroMemory(&tvis
, sizeof(tvis
));
291 tvis
.hParent
= hParent
;
292 tvis
.hInsertAfter
= TVI_LAST
;
293 tvis
.itemex
.mask
= TVIF_TEXT
; // TVIF_HANDLE | TVIF_TEXT;
294 tvis
.itemex
.pszText
= lpsz1
;
295 tvis
.itemex
.hItem
= TreeView_InsertItem(hTree
, &tvis
);
297 /* The special ";msconfig " token disables the line */
298 if (!bIsSection
&& _wcsnicmp(lpsz1
, szMSConfigTok
, MSConfigTokLen
) == 0)
299 TreeView_SetBOOLCheck(hTree
, tvis
.itemex
.hItem
, FALSE
, TRUE
);
301 TreeView_SetBOOLCheck(hTree
, tvis
.itemex
.hItem
, TRUE
, TRUE
);
304 * Now, all the elements will be children of this section,
305 * until we create a new one.
310 hParent
= tvis
.itemex
.hItem
;
317 //// Test code for the TreeView ////
321 hItem[0] = InsertItem(hTree, _T("B"),TVI_ROOT,TVI_LAST);
322 hItem[1] = InsertItem(hTree, _T("C"),TVI_ROOT,TVI_LAST);
323 hItem[2] = InsertItem(hTree, _T("A"),TVI_ROOT,TVI_LAST);
324 hItem[3] = InsertItem(hTree, _T("D"),TVI_ROOT,TVI_LAST);
325 hItem[4] = InsertItem(hTree, _T("D-1"),hItem[3] ,TVI_LAST);
326 hItem[5] = InsertItem(hTree, _T("D-2"),hItem[3] ,TVI_LAST);
327 hItem[9] = InsertItem(hTree, _T("D-2-1"),hItem[5],TVI_LAST);
328 hItem[6] = InsertItem(hTree, _T("D-3"),hItem[3] ,TVI_LAST);
329 hItem[7] = InsertItem(hTree, _T("D-3-1"),hItem[6],TVI_LAST);
330 hItem[10] = InsertItem(hTree, _T("D-3-1-1"),hItem[7],TVI_LAST);
331 hItem[11] = InsertItem(hTree, _T("D-3-1-2"),hItem[7],TVI_LAST);
332 hItem[12] = InsertItem(hTree, _T("D-3-1-3"),hItem[7],TVI_LAST);
333 hItem[13] = InsertItem(hTree, _T("D-3-1-4"),hItem[7],TVI_LAST);
334 hItem[14] = InsertItem(hTree, _T("D-3-1-5"),hItem[7],TVI_LAST);
335 hItem[15] = InsertItem(hTree, _T("D-3-1-6"),hItem[7],TVI_LAST);
336 hItem[13] = InsertItem(hTree, _T("E"),TVI_ROOT,TVI_LAST);
338 ////////////////////////////////////
343 WriteIniFile(HWND hTree
, LPCWSTR lpszIniFile
)
345 // Ouverture en écriture (avec création de fichier si celui-ci n'esistait pas déjà )
346 // d'un flux en mode texte, avec permission de lecture seule.
348 DWORD dwNumOfChars
= ExpandEnvironmentStringsW(lpszIniFile
, NULL
, 0);
349 LPWSTR lpszFileName
= MemAlloc(0, dwNumOfChars
* sizeof(WCHAR
));
350 ExpandEnvironmentStringsW(lpszIniFile
, lpszFileName
, dwNumOfChars
);
352 // HACK: delete these following lines when the program will be ready.
353 DWORD dwNumOfChars
= ExpandEnvironmentStringsW(lpszIniFile
, NULL
, 0) + 11;
354 LPWSTR lpszFileName
= (LPWSTR
)MemAlloc(0, dwNumOfChars
* sizeof(WCHAR
));
355 ExpandEnvironmentStringsW(lpszIniFile
, lpszFileName
, dwNumOfChars
);
356 wcscat(lpszFileName
, L
"__tests.ini");
360 FILE* ini_file
= _wfsopen(lpszFileName
, L
"wt", _SH_DENYRW
); // w+t <-- write read text ; wt <-- write text
361 MemFree(lpszFileName
);
368 WCHAR label
[MAX_VALUE_NAME
] = L
"";
369 // WCHAR szLine[MAX_VALUE_NAME] = L"";
371 // for (HTREEITEM htiIterator = TreeView_GetRoot(hTree) ; htiIterator ; htiIterator = TreeView_GetNextSibling(hTree, htiIterator))
372 for (HTREEITEM htiIterator
= TreeView_GetFirst(hTree
) ; htiIterator
; htiIterator
= TreeView_GetNext(hTree
, htiIterator
))
374 SecureZeroMemory(&tvItemEx
, sizeof(tvItemEx
));
376 tvItemEx
.hItem
= htiIterator
; // Handle of the item to be retrieved.
377 tvItemEx
.mask
= TVIF_HANDLE
| TVIF_TEXT
;
378 tvItemEx
.pszText
= label
;
379 tvItemEx
.cchTextMax
= MAX_VALUE_NAME
;
380 TreeView_GetItem(hTree
, &tvItemEx
);
382 // Write into the file.
383 wcscat(label
, L
"\n");
384 fputws(label
, ini_file
);
392 Update_Btn_States(HWND hDlg
)
394 HWND hTree
= GetDlgItem(hDlg
, IDC_SYSTEM_TREE
);
396 HTREEITEM hti
= TreeView_GetSelection(hTree
);
397 HTREEITEM htiPrev
= TreeView_GetPrevSibling(hTree
, hti
);
398 HTREEITEM htiNext
= TreeView_GetNextSibling(hTree
, hti
);
401 // "Up" / "Down" buttons.
404 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_UP
), TRUE
);
406 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_UP
), FALSE
);
409 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DOWN
), TRUE
);
411 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DOWN
), FALSE
);
414 // "Enable" / "Disable" buttons.
416 UINT uCheckState
= TreeView_GetCheckState(hTree
, hti
);
417 if (uCheckState
== 0)
419 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_ENABLE
) , TRUE
);
420 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DISABLE
), FALSE
);
422 else if (uCheckState
== 1)
424 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_ENABLE
) , FALSE
);
425 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DISABLE
), TRUE
);
427 else if (uCheckState
== 2)
429 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_ENABLE
) , TRUE
);
430 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DISABLE
), TRUE
);
434 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_ENABLE
) , FALSE
);
435 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DISABLE
), FALSE
);
439 // "Enable all" / "Disable all" buttons.
441 UINT uRootCheckState
= TreeView_GetRealSubtreeState(hTree
, TVI_ROOT
);
442 if (uRootCheckState
== 0)
444 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_ENABLE_ALL
) , TRUE
);
445 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DISABLE_ALL
), FALSE
);
447 else if (uRootCheckState
== 1)
449 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_ENABLE_ALL
) , FALSE
);
450 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DISABLE_ALL
), TRUE
);
452 else if (uRootCheckState
== 2)
454 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_ENABLE_ALL
) , TRUE
);
455 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DISABLE_ALL
), TRUE
);
459 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_ENABLE_ALL
) , FALSE
);
460 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DISABLE_ALL
), FALSE
);
464 // "Search" / "Edit" / "Delete" buttons.
466 if (TreeView_GetRoot(hTree
))
468 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_FIND
) , TRUE
);
469 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_EDIT
) , TRUE
);
470 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DELETE
), TRUE
);
474 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_FIND
) , FALSE
);
475 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_EDIT
) , FALSE
);
476 EnableWindow(GetDlgItem(hDlg
, IDC_BTN_SYSTEM_DELETE
), FALSE
);
484 CommonWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
486 UNREFERENCED_PARAMETER(lParam
);
487 UNREFERENCED_PARAMETER(wParam
);
493 HWND hSystemTree
= GetDlgItem(hDlg
, IDC_SYSTEM_TREE
);
496 // Initialize the styles.
498 TreeView_Set3StateCheck(hSystemTree
);
499 SetWindowTheme(hSystemTree
, L
"Explorer", NULL
);
501 TreeView_SetIndent(hSystemTree
, TreeView_GetIndent(hSystemTree
) + 2);
504 LoadIniFile(hSystemTree
, (LPCWSTR
)((LPPROPSHEETPAGE
)lParam
)->lParam
);
506 /* Select the first item */
507 TreeView_SelectItem(hSystemTree
, TreeView_GetRoot(hSystemTree
)); // Is it really necessary?
508 SetFocus(hSystemTree
);
510 Update_Btn_States(hDlg
);
517 TreeView_Cleanup(GetDlgItem(hDlg
, IDC_SYSTEM_TREE
));
523 HWND hSystemTree
= GetDlgItem(hDlg
, IDC_SYSTEM_TREE
);
525 switch (LOWORD(wParam
))
527 case IDC_BTN_SYSTEM_UP
:
529 TreeView_UpItem(hSystemTree
, TreeView_GetSelection(hSystemTree
));
530 PropSheet_Changed(GetParent(hDlg
), hDlg
);
534 case IDC_BTN_SYSTEM_DOWN
:
536 TreeView_DownItem(hSystemTree
, TreeView_GetSelection(hSystemTree
));
537 PropSheet_Changed(GetParent(hDlg
), hDlg
);
541 case IDC_BTN_SYSTEM_ENABLE
:
543 HTREEITEM hItem
= TreeView_GetSelection(hSystemTree
);
544 TreeView_SetBOOLCheck(hSystemTree
, hItem
, TRUE
, TRUE
);
545 TreeView_SelectItem(hSystemTree
, hItem
);
546 Update_Btn_States(hDlg
);
548 PropSheet_Changed(GetParent(hDlg
), hDlg
);
553 case IDC_BTN_SYSTEM_ENABLE_ALL
:
555 for (HTREEITEM htiIterator
= TreeView_GetRoot(hSystemTree
) ; htiIterator
; htiIterator
= TreeView_GetNextSibling(hSystemTree
, htiIterator
))
556 TreeView_SetBOOLCheck(hSystemTree
, htiIterator
, TRUE
, TRUE
);
558 Update_Btn_States(hDlg
);
560 PropSheet_Changed(GetParent(hDlg
), hDlg
);
565 case IDC_BTN_SYSTEM_DISABLE
:
567 HTREEITEM hItem
= TreeView_GetSelection(hSystemTree
);
568 TreeView_SetBOOLCheck(hSystemTree
, hItem
, FALSE
, TRUE
);
569 TreeView_SelectItem(hSystemTree
, hItem
);
571 Update_Btn_States(hDlg
);
573 PropSheet_Changed(GetParent(hDlg
), hDlg
);
578 case IDC_BTN_SYSTEM_DISABLE_ALL
:
580 for (HTREEITEM htiIterator
= TreeView_GetRoot(hSystemTree
) ; htiIterator
; htiIterator
= TreeView_GetNextSibling(hSystemTree
, htiIterator
))
581 TreeView_SetBOOLCheck(hSystemTree
, htiIterator
, FALSE
, TRUE
);
583 Update_Btn_States(hDlg
);
585 PropSheet_Changed(GetParent(hDlg
), hDlg
);
590 case IDC_BTN_SYSTEM_FIND
:
592 DialogBoxParamW(hInst
, MAKEINTRESOURCEW(IDD_FIND_DIALOG
), hDlg
/* hMainWnd */, FindDialogWndProc
, (LPARAM
)hSystemTree
);
596 case IDC_BTN_SYSTEM_NEW
:
598 HTREEITEM hInsertAfter
= TreeView_GetSelection(hSystemTree
);
599 HTREEITEM hNewItem
= InsertItem(hSystemTree
, L
"", TreeView_GetParent(hSystemTree
, hInsertAfter
), hInsertAfter
);
600 TreeView_EditLabel(hSystemTree
, hNewItem
);
601 TreeView_SelectItem(hSystemTree
, hNewItem
);
603 PropSheet_Changed(GetParent(hDlg
), hDlg
);
608 case IDC_BTN_SYSTEM_EDIT
:
610 TreeView_EditLabel(hSystemTree
, TreeView_GetSelection(hSystemTree
));
614 case IDC_BTN_SYSTEM_DELETE
:
616 TreeView_DeleteItem(hSystemTree
, TreeView_GetSelection(hSystemTree
));
617 Update_Btn_States(hDlg
);
618 PropSheet_Changed(GetParent(hDlg
), hDlg
);
628 case UM_CHECKSTATECHANGE
:
630 HWND hSystemTree
= GetDlgItem(hDlg
, IDC_SYSTEM_TREE
);
632 /* Retrieve the new checked state of the item and handle the notification */
633 HTREEITEM hItemChanged
= (HTREEITEM
)lParam
;
636 // State before | State after
637 // -------------------------------
638 // 0 (unchecked) | 1 (checked)
639 // 1 (checked) | 0 (unchecked)
640 // 2 (grayed) | 1 (checked) --> this case corresponds to the former
641 // | with 0 == 2 mod 2.
643 UINT uiCheckState
= TreeView_GetCheckState(hSystemTree
, hItemChanged
) % 2;
644 TreeView_SetBOOLCheck(hSystemTree
, hItemChanged
, uiCheckState
? FALSE
: TRUE
, TRUE
);
645 TreeView_SelectItem(hSystemTree
, hItemChanged
);
646 Update_Btn_States(hDlg
);
648 PropSheet_Changed(GetParent(hDlg
), hDlg
);
655 if (((LPNMHDR
)lParam
)->idFrom
== IDC_SYSTEM_TREE
)
657 switch (((LPNMHDR
)lParam
)->code
)
661 HWND hSystemTree
= GetDlgItem(hDlg
, IDC_SYSTEM_TREE
);
663 DWORD dwpos
= GetMessagePos();
664 TVHITTESTINFO ht
= {};
665 ht
.pt
.x
= GET_X_LPARAM(dwpos
);
666 ht
.pt
.y
= GET_Y_LPARAM(dwpos
);
667 MapWindowPoints(HWND_DESKTOP
/*NULL*/, hSystemTree
, &ht
.pt
, 1);
669 TreeView_HitTest(hSystemTree
, &ht
);
671 if (TVHT_ONITEMSTATEICON
& ht
.flags
)
673 PostMessage(hDlg
, UM_CHECKSTATECHANGE
, 0, (LPARAM
)ht
.hItem
);
675 // Disable default behaviour. Needed for the UM_CHECKSTATECHANGE
676 // custom notification to work as expected.
677 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, TRUE
);
681 SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
689 if (((LPNMTVKEYDOWN
)lParam
)->wVKey
== VK_SPACE
)
691 HWND hSystemTree
= GetDlgItem(hDlg
, IDC_SYSTEM_TREE
);
693 HTREEITEM hti
= TreeView_GetSelection(hSystemTree
);
695 // Hack the tree item state. This is needed because whether or not
696 // TRUE is being returned, the default implementation of SysTreeView32
697 // is always being processed for a key down !
698 if (GetWindowLongPtr(hSystemTree
, GWL_STYLE
) & TVS_CHECKBOXES
)
700 TreeView_SetItemState(hSystemTree
, hti
, INDEXTOSTATEIMAGEMASK(TreeView_GetCheckState(hSystemTree
, hti
)), TVIS_STATEIMAGEMASK
);
703 PostMessage(hDlg
, UM_CHECKSTATECHANGE
, 0, (LPARAM
)hti
);
705 // Disable default behaviour. Needed for the UM_CHECKSTATECHANGE
706 // custom notification to work as expected.
707 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, TRUE
);
713 case TVN_ENDLABELEDIT
:
715 HWND hSystemTree
= GetDlgItem(hDlg
, IDC_SYSTEM_TREE
);
718 * Ehh yes, we have to deal with a "dialog proc", which is quite different from a "window proc":
720 * (excerpt from: MSDN library http://msdn.microsoft.com/en-us/library/ms645469(VS.85).aspx)
726 * Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not.
727 * If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response
730 * If the dialog box procedure processes a message that requires a specific return value, the dialog box procedure
731 * should set the desired return value by calling SetWindowLong(hwndDlg, DWL_MSGRESULT, lResult) immediately before
732 * returning TRUE. Note that you must call SetWindowLong immediately before returning TRUE; doing so earlier may result
733 * in the DWL_MSGRESULT value being overwritten by a nested dialog box message.
739 * You should use the dialog box procedure only if you use the dialog box class for the dialog box. This is the default
740 * class and is used when no explicit class is specified in the dialog box template. Although the dialog box procedure
741 * is similar to a window procedure, it must not call the DefWindowProc function to process unwanted messages. Unwanted
742 * messages are processed internally by the dialog box window procedure.
746 // A arranger un peu ???? Certainement.
747 TVITEMW truc
= ((LPNMTVDISPINFO
)lParam
)->item
;
751 TreeView_DeleteItem(hSystemTree
, truc
.hItem
);
753 PropSheet_Changed(GetParent(hDlg
), hDlg
);
755 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, TRUE
);
758 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
760 Update_Btn_States(hDlg
);
765 Update_Btn_States(hDlg
);
774 switch (((LPNMHDR
)lParam
)->code
)
778 // TODO: Enum the items.
779 // HWND hSystemTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
781 PropSheet_CancelToClose(GetParent(hDlg
));
785 * dll/win32/devmgr/advprop.c: PropSheet_RebootSystem(hwndDlg);
786 * include/psdk/prsht.h:#define PropSheet_RebootSystem(d) SendMessage(d,PSM_REBOOTSYSTEM,0,0)
788 * dll/shellext/deskadp/deskadp.c: PropSheet_RestartWindows(GetParent(This->hwndDlg));
789 * dll/shellext/deskmon/deskmon.c: PropSheet_RestartWindows(GetParent(This->hwndDlg));
790 * include/psdk/prsht.h:#define PropSheet_RestartWindows(d) SendMessage(d,PSM_RESTARTWINDOWS,0,0)
794 PropSheet_RebootSystem(GetParent(hDlg
));
795 //PropSheet_RestartWindows(GetParent(hDlg));
797 WriteIniFile(GetDlgItem(hDlg
, IDC_SYSTEM_TREE
), (LPCWSTR
)wParam
);
799 // Since there are nothing to modify, applying modifications
800 // cannot return any error.
801 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
802 //PropSheet_UnChanged(GetParent(hDlg) /*hMainWnd*/, hDlg);
808 MessageBox(hDlg
, _T("Help not implemented yet!"), _T("Help"), MB_ICONINFORMATION
| MB_OK
);
812 case PSN_KILLACTIVE
: // Is going to lose activation.
814 // Changes are always valid of course.
815 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
819 case PSN_QUERYCANCEL
:
821 // Allows cancellation since there are nothing to cancel...
822 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, FALSE
);
826 case PSN_QUERYINITIALFOCUS
:
828 HWND hSystemTree
= GetDlgItem(hDlg
, IDC_SYSTEM_TREE
);
830 // Give the focus on and select the first item.
831 ListView_SetItemState(hSystemTree
, 0, LVIS_FOCUSED
| LVIS_SELECTED
, LVIS_FOCUSED
| LVIS_SELECTED
);
833 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, (LONG_PTR
)hSystemTree
);
838 // DO NOT TOUCH THESE NEXT MESSAGES, THEY ARE OK LIKE THIS...
840 case PSN_RESET
: // Perform final cleaning, called before WM_DESTROY.
843 case PSN_SETACTIVE
: // Is going to gain activation.
845 SetWindowLongPtr(hDlg
, DWLP_MSGRESULT
, 0);
868 SystemPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
870 static LPCWSTR lpszIniFile
= NULL
;
872 if (message
== WM_INITDIALOG
)
873 lpszIniFile
= (LPCWSTR
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
875 if ( (message
== WM_NOTIFY
) && (((LPNMHDR
)lParam
)->code
== PSN_APPLY
) )
876 wParam
= (WPARAM
)lpszIniFile
;
878 return CommonWndProc(hDlg
, message
, wParam
, lParam
);
882 WinPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
884 static LPCWSTR lpszIniFile
= NULL
;
886 if (message
== WM_INITDIALOG
)
887 lpszIniFile
= (LPCWSTR
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
889 if ( (message
== WM_NOTIFY
) && (((LPNMHDR
)lParam
)->code
== PSN_APPLY
) )
890 wParam
= (WPARAM
)lpszIniFile
;
892 return CommonWndProc(hDlg
, message
, wParam
, lParam
);