ReactOS  0.4.12-dev-75-g00dd17e
systempage.cpp
Go to the documentation of this file.
1 /*
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>
9  */
10 
11 #include "precomp.h"
12 #include <share.h>
13 
14 #include "treeview.h"
15 #include "uxthemesupp.h"
16 
17 #include "regutils.h"
18 #include "utils.h"
19 
20 
21 extern "C" {
22 
23 LPCWSTR lpszSystemIni = L"%SystemRoot%\\system.ini"; // or: %windir%\\... ?
24 LPCWSTR lpszWinIni = L"%SystemRoot%\\win.ini"; // or: %windir%\\... ?
25 
26 }
27 
28 static LPCWSTR szMSConfigTok = L";msconfig "; // Note the trailing whitespace
29 static const size_t MSConfigTokLen = 10;
30 
31 
32 extern "C" {
33 
35 {
36  DWORD dwSystemIni = 0;
37  RegGetDWORDValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\state", L"system.ini", &dwSystemIni);
38  return dwSystemIni;
39 }
40 
42 {
43  DWORD dwWinIni = 0;
44  RegGetDWORDValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\state", L"win.ini", &dwWinIni);
45  return dwWinIni;
46 }
47 
48 }
49 
50 
51 
52 static HWND hTree = NULL;
55 static BOOL bSearchSense = TRUE; // TRUE == down, FALSE == up.
57 
58 static void
59 ToLower(LPWSTR lpszString)
60 {
61  if (!lpszString)
62  return;
63 
64  while (*lpszString)
65  {
66  *lpszString = towlower(*lpszString);
67  ++lpszString;
68  }
69 }
70 
73  UINT message,
74  WPARAM wParam,
75  LPARAM lParam)
76 {
77  UNREFERENCED_PARAMETER(lParam);
78 
79  switch (message)
80  {
81  case WM_INITDIALOG:
82  {
83  hTree = (HWND)lParam;
84 
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));
89 
93 
94  return TRUE;
95  }
96 
97  case WM_COMMAND:
98  {
99  switch (LOWORD(wParam))
100  {
101  case IDOK:
102  {
103  TVITEMEXW tvItemEx;
104  HTREEITEM htiIterator;
106  WCHAR szTemp[MAX_VALUE_NAME];
107 
110  (Button_GetCheck(GetDlgItem(hDlg, IDC_RB_FIND_UP )) == BST_UNCHECKED)); // TRUE == down, FALSE == up.
112 
114  wcscpy(szTemp, szSearchString);
115  if (!bCaseSensitive)
116  ToLower(szTemp);
117 
119  : TreeView_GetLast(hTree))
121  : TreeView_GetPrev(hTree, TreeView_GetSelection(hTree))));
122  htiIterator ;
123  htiIterator = (bSearchSense ? TreeView_GetNext(hTree, htiIterator)
124  : TreeView_GetPrev(hTree, htiIterator)))
125  {
126  SecureZeroMemory(&tvItemEx, sizeof(tvItemEx));
127 
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);
133  if (!bCaseSensitive)
134  ToLower(label);
135 
136  if (bMatchExactText ? (_tcscmp(label, szTemp) == 0) : !!_tcsstr(label, szTemp)) // <-- hackish. A arranger.
137  {
138  TreeView_SelectItem(hTree, htiIterator);
139  EndDialog(hDlg, LOWORD(wParam));
140  return TRUE;
141  }
142  //MessageBox(NULL, label, _T("Info"), MB_ICONINFORMATION | MB_OK);
143  }
144 
145  // FIXME: Localize!
146  MessageBoxW(hDlg, L"No correspondence found.", szAppName, MB_ICONINFORMATION | MB_OK);
149  //EndDialog(hDlg, LOWORD(wParam));
150  return TRUE;
151  }
152 
153  case IDCANCEL:
154  EndDialog(hDlg, LOWORD(wParam));
155  return TRUE;
156 
157  default:
158  //break;
159  return FALSE;
160  }
161  }
162  }
163 
164  return FALSE;
165 }
166 
167 
168 
169 static void
170 TreeView_SetBOOLCheck(HWND hTree, HTREEITEM htiItem, BOOL bState, BOOL bPropagateStateToParent)
171 {
172  if (!hTree || !htiItem)
173  return;
174 
175  TreeView_SetCheckState(hTree, htiItem, bState);
176 
177  /*
178  * Add or remove the token for tree leaves only.
179  */
180  if (!TreeView_GetChild(hTree, htiItem))
181  {
182  /* 1- Retrieve properties */
183  TVITEMEXW tvItemEx;
184  SecureZeroMemory(&tvItemEx, sizeof(tvItemEx));
185 
186  tvItemEx.hItem = htiItem; // Handle of the item to be retrieved.
187  tvItemEx.mask = TVIF_HANDLE | TVIF_TEXT;
189  tvItemEx.pszText = label;
190  tvItemEx.cchTextMax = MAX_VALUE_NAME;
191  TreeView_GetItem(hTree, &tvItemEx);
192 
193  if (!bState)
194  {
195  /* 2- Add the token IF NEEDED */
196  if ((wcslen(tvItemEx.pszText) < MSConfigTokLen) || (_wcsnicmp(tvItemEx.pszText, szMSConfigTok, MSConfigTokLen) != 0))
197  {
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;
202 
203  TreeView_SetItem(hTree, &tvItemEx);
204 
205  MemFree(newLabel);
206  }
207  }
208  else
209  {
210  /* 2- Remove the token IF NEEDED */
211  if ((wcslen(tvItemEx.pszText) >= MSConfigTokLen) && (_wcsnicmp(tvItemEx.pszText, szMSConfigTok, MSConfigTokLen) == 0))
212  {
213  LPWSTR newLabel = (LPWSTR)MemAlloc(0, (_tcslen(tvItemEx.pszText) - MSConfigTokLen + 1) * sizeof(WCHAR));
214  wcscpy(newLabel, tvItemEx.pszText + MSConfigTokLen);
215  tvItemEx.pszText = newLabel;
216 
217  TreeView_SetItem(hTree, &tvItemEx);
218 
219  // TODO: if one finds tvItemEx.pszText == L"", one can
220  // directly remove the item (cf. message TVN_ENDLABELEDIT).
221 
222  MemFree(newLabel);
223  }
224  }
225  }
227 
228  for (HTREEITEM htiIterator = TreeView_GetChild(hTree, htiItem) ; htiIterator ; htiIterator = TreeView_GetNextSibling(hTree, htiIterator))
229  TreeView_SetBOOLCheck(hTree, htiIterator, bState, FALSE);
230 
231  if (bPropagateStateToParent)
233 
234  return;
235 }
236 
237 static void
238 LoadIniFile(HWND hTree, LPCWSTR lpszIniFile)
239 {
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);
245 
246  FILE* ini_file = _wfsopen(lpszFileName, L"rt", _SH_DENYWR); // r+t <-- read write text ; rt <-- read text
247  MemFree(lpszFileName);
248 
249  if (!ini_file)
250  return; // error
251 
253  TVINSERTSTRUCT tvis;
255  BOOL bIsSection = FALSE;
256  LPWSTR lpsz1 = NULL;
257  LPWSTR lpsz2 = NULL;
258 
259  while (!feof(ini_file) && fgetws(szLine, _ARRAYSIZE(szLine), ini_file))
260  {
261  /* Skip hypothetical starting spaces or newline characters */
262  lpsz1 = szLine;
263  while (*lpsz1 == L' ' || *lpsz1 == L'\r' || *lpsz1 == L'\n')
264  ++lpsz1;
265 
266  /* Skip empty lines */
267  if (!*lpsz1)
268  continue;
269 
270  /* Find the last newline character (if exists) and replace it by the NULL terminator */
271  lpsz2 = lpsz1;
272  while (*lpsz2)
273  {
274  if (*lpsz2 == L'\r' || *lpsz2 == L'\n')
275  {
276  *lpsz2 = L'\0';
277  break;
278  }
279 
280  ++lpsz2;
281  }
282 
283  /* Check for new sections. They should be parent of ROOT. */
284  if (*lpsz1 == L'[')
285  {
286  bIsSection = TRUE;
287  hParent = TVI_ROOT;
288  }
289 
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);
296 
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);
300  else
301  TreeView_SetBOOLCheck(hTree, tvis.itemex.hItem, TRUE, TRUE);
302 
303  /*
304  * Now, all the elements will be children of this section,
305  * until we create a new one.
306  */
307  if (bIsSection)
308  {
309  bIsSection = FALSE;
310  hParent = tvis.itemex.hItem;
311  }
312  }
313 
314  fclose(ini_file);
315  return;
316 
318  /*
319  HTREEITEM hItem[16];
320 
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);
337  */
339 
340 }
341 
342 static void
343 WriteIniFile(HWND hTree, LPCWSTR lpszIniFile)
344 {
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.
347 #if 0
348  DWORD dwNumOfChars = ExpandEnvironmentStringsW(lpszIniFile, NULL, 0);
349  LPWSTR lpszFileName = MemAlloc(0, dwNumOfChars * sizeof(WCHAR));
350  ExpandEnvironmentStringsW(lpszIniFile, lpszFileName, dwNumOfChars);
351 #else
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");
357  // END HACK.
358 #endif
359 
360  FILE* ini_file = _wfsopen(lpszFileName, L"wt", _SH_DENYRW); // w+t <-- write read text ; wt <-- write text
361  MemFree(lpszFileName);
362 
363  if (!ini_file)
364  return; // error
365 
366 
367  TVITEMEXW tvItemEx;
369  // WCHAR szLine[MAX_VALUE_NAME] = L"";
370 
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))
373  {
374  SecureZeroMemory(&tvItemEx, sizeof(tvItemEx));
375 
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);
381 
382  // Write into the file.
383  wcscat(label, L"\n");
384  fputws(label, ini_file);
385  }
386 
387  fclose(ini_file);
388  return;
389 }
390 
391 static void
393 {
394  HWND hTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
395 
396  HTREEITEM hti = TreeView_GetSelection(hTree);
397  HTREEITEM htiPrev = TreeView_GetPrevSibling(hTree, hti);
398  HTREEITEM htiNext = TreeView_GetNextSibling(hTree, hti);
399 
400  //
401  // "Up" / "Down" buttons.
402  //
403  if (htiPrev)
405  else
407 
408  if (htiNext)
410  else
412 
413  //
414  // "Enable" / "Disable" buttons.
415  //
416  UINT uCheckState = TreeView_GetCheckState(hTree, hti);
417  if (uCheckState == 0)
418  {
421  }
422  else if (uCheckState == 1)
423  {
426  }
427  else if (uCheckState == 2)
428  {
431  }
432  else
433  {
436  }
437 
438  //
439  // "Enable all" / "Disable all" buttons.
440  //
441  UINT uRootCheckState = TreeView_GetRealSubtreeState(hTree, TVI_ROOT);
442  if (uRootCheckState == 0)
443  {
446  }
447  else if (uRootCheckState == 1)
448  {
451  }
452  else if (uRootCheckState == 2)
453  {
456  }
457  else
458  {
461  }
462 
463  //
464  // "Search" / "Edit" / "Delete" buttons.
465  //
466  if (TreeView_GetRoot(hTree))
467  {
471  }
472  else
473  {
477  }
478 
479  return;
480 }
481 
482 
483 INT_PTR
485 {
486  UNREFERENCED_PARAMETER(lParam);
487  UNREFERENCED_PARAMETER(wParam);
488 
489  switch (message)
490  {
491  case WM_INITDIALOG:
492  {
493  HWND hSystemTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
494 
495  //
496  // Initialize the styles.
497  //
498  TreeView_Set3StateCheck(hSystemTree);
499  SetWindowTheme(hSystemTree, L"Explorer", NULL);
500 
501  TreeView_SetIndent(hSystemTree, TreeView_GetIndent(hSystemTree) + 2);
502 
503  /* Load data */
504  LoadIniFile(hSystemTree, (LPCWSTR)((LPPROPSHEETPAGE)lParam)->lParam);
505 
506  /* Select the first item */
507  TreeView_SelectItem(hSystemTree, TreeView_GetRoot(hSystemTree)); // Is it really necessary?
508  SetFocus(hSystemTree);
509 
510  Update_Btn_States(hDlg);
511 
512  return TRUE;
513  }
514 
515  case WM_DESTROY:
516  {
518  return FALSE;
519  }
520 
521  case WM_COMMAND:
522  {
523  HWND hSystemTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
524 
525  switch (LOWORD(wParam))
526  {
527  case IDC_BTN_SYSTEM_UP:
528  {
529  TreeView_UpItem(hSystemTree, TreeView_GetSelection(hSystemTree));
530  PropSheet_Changed(GetParent(hDlg), hDlg);
531  return TRUE;
532  }
533 
534  case IDC_BTN_SYSTEM_DOWN:
535  {
536  TreeView_DownItem(hSystemTree, TreeView_GetSelection(hSystemTree));
537  PropSheet_Changed(GetParent(hDlg), hDlg);
538  return TRUE;
539  }
540 
542  {
543  HTREEITEM hItem = TreeView_GetSelection(hSystemTree);
544  TreeView_SetBOOLCheck(hSystemTree, hItem, TRUE, TRUE);
545  TreeView_SelectItem(hSystemTree, hItem);
546  Update_Btn_States(hDlg);
547 
548  PropSheet_Changed(GetParent(hDlg), hDlg);
549 
550  return TRUE;
551  }
552 
554  {
555  for (HTREEITEM htiIterator = TreeView_GetRoot(hSystemTree) ; htiIterator ; htiIterator = TreeView_GetNextSibling(hSystemTree, htiIterator))
556  TreeView_SetBOOLCheck(hSystemTree, htiIterator, TRUE, TRUE);
557 
558  Update_Btn_States(hDlg);
559 
560  PropSheet_Changed(GetParent(hDlg), hDlg);
561 
562  return TRUE;
563  }
564 
566  {
567  HTREEITEM hItem = TreeView_GetSelection(hSystemTree);
568  TreeView_SetBOOLCheck(hSystemTree, hItem, FALSE, TRUE);
569  TreeView_SelectItem(hSystemTree, hItem);
570 
571  Update_Btn_States(hDlg);
572 
573  PropSheet_Changed(GetParent(hDlg), hDlg);
574 
575  return TRUE;
576  }
577 
579  {
580  for (HTREEITEM htiIterator = TreeView_GetRoot(hSystemTree) ; htiIterator ; htiIterator = TreeView_GetNextSibling(hSystemTree, htiIterator))
581  TreeView_SetBOOLCheck(hSystemTree, htiIterator, FALSE, TRUE);
582 
583  Update_Btn_States(hDlg);
584 
585  PropSheet_Changed(GetParent(hDlg), hDlg);
586 
587  return TRUE;
588  }
589 
590  case IDC_BTN_SYSTEM_FIND:
591  {
592  DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_FIND_DIALOG), hDlg /* hMainWnd */, FindDialogWndProc, (LPARAM)hSystemTree);
593  return TRUE;
594  }
595 
596  case IDC_BTN_SYSTEM_NEW:
597  {
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);
602 
603  PropSheet_Changed(GetParent(hDlg), hDlg);
604 
605  return TRUE;
606  }
607 
608  case IDC_BTN_SYSTEM_EDIT:
609  {
610  TreeView_EditLabel(hSystemTree, TreeView_GetSelection(hSystemTree));
611  return TRUE;
612  }
613 
615  {
616  TreeView_DeleteItem(hSystemTree, TreeView_GetSelection(hSystemTree));
617  Update_Btn_States(hDlg);
618  PropSheet_Changed(GetParent(hDlg), hDlg);
619  return TRUE;
620  }
621 
622  default:
623  return FALSE;
624  }
625  // return FALSE;
626  }
627 
628  case UM_CHECKSTATECHANGE:
629  {
630  HWND hSystemTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
631 
632  /* Retrieve the new checked state of the item and handle the notification */
633  HTREEITEM hItemChanged = (HTREEITEM)lParam;
634 
635  //
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.
642  //
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);
647 
648  PropSheet_Changed(GetParent(hDlg), hDlg);
649 
650  return TRUE;
651  }
652 
653  case WM_NOTIFY:
654  {
655  if (((LPNMHDR)lParam)->idFrom == IDC_SYSTEM_TREE)
656  {
657  switch (((LPNMHDR)lParam)->code)
658  {
659  case NM_CLICK:
660  {
661  HWND hSystemTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
662 
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);
668 
669  TreeView_HitTest(hSystemTree, &ht);
670 
671  if (TVHT_ONITEMSTATEICON & ht.flags)
672  {
674 
675  // Disable default behaviour. Needed for the UM_CHECKSTATECHANGE
676  // custom notification to work as expected.
678  }
679  /*
680  else
681  SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
682  */
683 
684  return TRUE;
685  }
686 
687  case TVN_KEYDOWN:
688  {
689  if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_SPACE)
690  {
691  HWND hSystemTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
692 
693  HTREEITEM hti = TreeView_GetSelection(hSystemTree);
694 
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)
699  {
701  }
702 
703  PostMessage(hDlg, UM_CHECKSTATECHANGE, 0, (LPARAM)hti);
704 
705  // Disable default behaviour. Needed for the UM_CHECKSTATECHANGE
706  // custom notification to work as expected.
708  }
709 
710  return TRUE;
711  }
712 
713  case TVN_ENDLABELEDIT:
714  {
715  HWND hSystemTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
716 
717  /*
718  * Ehh yes, we have to deal with a "dialog proc", which is quite different from a "window proc":
719  *
720  * (excerpt from: MSDN library http://msdn.microsoft.com/en-us/library/ms645469(VS.85).aspx)
721  *
722  * Return Value
723  * ============
724  * INT_PTR
725  *
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
728  * to the message.
729  *
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, DWLP_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 DWLP_MSGRESULT value being overwritten by a nested dialog box message.
734  *
735  * [...]
736  *
737  * Remarks
738  * =======
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.
743  *
744  */
745 
746  // A arranger un peu ???? Certainement.
747  TVITEMW truc = ((LPNMTVDISPINFO)lParam)->item;
748  if (truc.pszText)
749  {
750  if (!*truc.pszText)
751  TreeView_DeleteItem(hSystemTree, truc.hItem);
752 
753  PropSheet_Changed(GetParent(hDlg), hDlg);
754 
756  }
757  else
759 
760  Update_Btn_States(hDlg);
761  return TRUE;
762  }
763 
764  case TVN_SELCHANGED:
765  Update_Btn_States(hDlg);
766  return TRUE;
767 
768  default:
769  return FALSE;
770  }
771  }
772  else
773  {
774  switch (((LPNMHDR)lParam)->code)
775  {
776  case PSN_APPLY:
777  {
778  // TODO: Enum the items.
779  // HWND hSystemTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
780  //
782 
783  /* TODO: see :
784  *
785  * dll/win32/devmgr/advprop.c: PropSheet_RebootSystem(hwndDlg);
786  * include/psdk/prsht.h:#define PropSheet_RebootSystem(d) SendMessage(d,PSM_REBOOTSYSTEM,0,0)
787  *
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)
791  *
792  * for their usage.
793  */
795  //PropSheet_RestartWindows(GetParent(hDlg));
796 
798 
799  // Since there are nothing to modify, applying modifications
800  // cannot return any error.
802  //PropSheet_UnChanged(GetParent(hDlg) /*hMainWnd*/, hDlg);
803  return TRUE;
804  }
805 
806  case PSN_HELP:
807  {
808  MessageBox(hDlg, _T("Help not implemented yet!"), _T("Help"), MB_ICONINFORMATION | MB_OK);
809  return TRUE;
810  }
811 
812  case PSN_KILLACTIVE: // Is going to lose activation.
813  {
814  // Changes are always valid of course.
816  return TRUE;
817  }
818 
819  case PSN_QUERYCANCEL:
820  {
821  // Allows cancellation since there are nothing to cancel...
823  return TRUE;
824  }
825 
827  {
828  HWND hSystemTree = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
829 
830  // Give the focus on and select the first item.
832 
833  SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)hSystemTree);
834  return TRUE;
835  }
836 
837  //
838  // DO NOT TOUCH THESE NEXT MESSAGES, THEY ARE OK LIKE THIS...
839  //
840  case PSN_RESET: // Perform final cleaning, called before WM_DESTROY.
841  return TRUE;
842 
843  case PSN_SETACTIVE: // Is going to gain activation.
844  {
846  return TRUE;
847  }
848 
849  default:
850  break;
851  }
852  }
853 
854  return FALSE;
855  }
856 
857  default:
858  return FALSE;
859  }
860 
861  // return FALSE;
862 }
863 
864 
865 extern "C" {
866 
869 {
870  static LPCWSTR lpszIniFile = NULL;
871 
872  if (message == WM_INITDIALOG)
873  lpszIniFile = (LPCWSTR)((LPPROPSHEETPAGE)lParam)->lParam;
874 
875  if ( (message == WM_NOTIFY) && (((LPNMHDR)lParam)->code == PSN_APPLY) )
876  wParam = (WPARAM)lpszIniFile;
877 
878  return CommonWndProc(hDlg, message, wParam, lParam);
879 }
880 
883 {
884  static LPCWSTR lpszIniFile = NULL;
885 
886  if (message == WM_INITDIALOG)
887  lpszIniFile = (LPCWSTR)((LPPROPSHEETPAGE)lParam)->lParam;
888 
889  if ( (message == WM_NOTIFY) && (((LPNMHDR)lParam)->code == PSN_APPLY) )
890  wParam = (WPARAM)lpszIniFile;
891 
892  return CommonWndProc(hDlg, message, wParam, lParam);
893 }
894 
895 }
#define TVHT_ONITEMSTATEICON
Definition: commctrl.h:3498
#define Edit_GetText(hwndCtl, lpch, cchMax)
Definition: windowsx.h:69
static void WriteIniFile(HWND hTree, LPCWSTR lpszIniFile)
Definition: systempage.cpp:343
static BOOL bCaseSensitive
Definition: systempage.cpp:56
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
long y
Definition: polytest.cpp:48
HTREEITEM TreeView_GetPrev(HWND hTree, HTREEITEM hItem)
Definition: treeview.c:245
int WINAPI MapWindowPoints(_In_opt_ HWND hWndFrom, _In_opt_ HWND hWndTo, _Inout_updates_(cPoints) LPPOINT lpPoints, _In_ UINT cPoints)
void TreeView_Cleanup(HWND hTree)
Definition: treeview.c:87
long x
Definition: polytest.cpp:48
#define IDC_BTN_SYSTEM_DISABLE
Definition: resource.h:64
static void TreeView_SetBOOLCheck(HWND hTree, HTREEITEM htiItem, BOOL bState, BOOL bPropagateStateToParent)
Definition: systempage.cpp:170
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define PSN_HELP
Definition: prsht.h:119
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SecureZeroMemory
Definition: winbase.h:1636
static void LoadIniFile(HWND hTree, LPCWSTR lpszIniFile)
Definition: systempage.cpp:238
PVOID MemAlloc(IN DWORD dwFlags, IN DWORD dwBytes)
Definition: utils.c:33
#define TreeView_EditLabel(hwnd, hitem)
Definition: commctrl.h:3471
#define TreeView_GetChild(hwnd, hitem)
Definition: commctrl.h:3433
#define _ARRAYSIZE(A)
Definition: ntbasedef.h:708
LPWSTR pszText
Definition: commctrl.h:3317
struct _TREEITEM * HTREEITEM
Definition: commctrl.h:3231
#define IDC_BTN_SYSTEM_DISABLE_ALL
Definition: resource.h:45
#define CALLBACK
Definition: compat.h:27
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
static BOOL bSearchSense
Definition: systempage.cpp:55
#define IDC_RB_FIND_UP
Definition: resource.h:104
#define PropSheet_CancelToClose(d)
Definition: prsht.h:325
HANDLE HWND
Definition: compat.h:13
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define UM_CHECKSTATECHANGE
Definition: comctl32supp.h:20
HWND WINAPI SetFocus(_In_opt_ HWND)
#define IDC_TXT_FIND_TEXT
Definition: resource.h:100
HTREEITEM InsertItem(HWND hTree, LPCWSTR szName, HTREEITEM hParent, HTREEITEM hInsertAfter)
Definition: treeview.c:95
DWORD WINAPI GetMessagePos(void)
Definition: message.c:1326
#define TreeView_GetNextSibling(hwnd, hitem)
Definition: commctrl.h:3434
#define PSN_APPLY
Definition: prsht.h:117
int32_t INT_PTR
Definition: typedefs.h:62
#define IDC_SYSTEM_TREE
Definition: resource.h:68
#define WCHAR
Definition: msvc.h:43
LPWSTR pszText
Definition: commctrl.h:3287
#define PSN_SETACTIVE
Definition: prsht.h:115
#define SetWindowLongPtr
Definition: treelist.c:70
HTREEITEM TreeView_GetLast(HWND hTree)
Definition: treeview.c:240
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
void TreeView_PropagateStateOfItemToParent(HWND hTree, HTREEITEM htiItem)
Definition: treeview.c:135
#define DWLP_MSGRESULT
Definition: winuser.h:864
struct tagNMHDR * LPNMHDR
#define IDC_BTN_SYSTEM_NEW
Definition: resource.h:66
UINT_PTR WPARAM
Definition: windef.h:207
_Check_return_ _CRTIMP FILE *__cdecl _wfsopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode, _In_ int _ShFlag)
#define PSN_QUERYCANCEL
Definition: prsht.h:123
#define TreeView_InsertItem(hwnd, lpis)
Definition: commctrl.h:3379
#define TreeView_SetCheckState(hwndTV, hti, fCheck)
Definition: commctrl.h:3560
#define PSN_KILLACTIVE
Definition: prsht.h:116
#define TVN_ENDLABELEDIT
Definition: commctrl.h:3711
#define ListView_SetItemState(hwndLV, i, data, mask)
Definition: commctrl.h:2643
_Check_return_opt_ _CRTIMP int __cdecl fputws(_In_z_ const wchar_t *_Str, _Inout_ FILE *_File)
LONG_PTR LPARAM
Definition: windef.h:208
static BOOL bMatchExactText
Definition: systempage.cpp:54
#define IDC_BTN_SYSTEM_UP
Definition: resource.h:61
HRESULT WINAPI SetWindowTheme(_In_ HWND hwnd, _In_ LPCWSTR pszSubAppName, _In_ LPCWSTR pszSubIdList)
Definition: uxthemesupp.c:69
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
#define LPPROPSHEETPAGE
Definition: prsht.h:372
smooth NULL
Definition: ftsmooth.c:416
#define LVIS_SELECTED
Definition: commctrl.h:2289
#define IDC_CBX_FIND_FROM_BEGINNING
Definition: resource.h:103
#define MAX_VALUE_NAME
Definition: control.c:23
static const WCHAR szLine[]
Definition: dialog.c:141
DWORD GetWinIniActivation(VOID)
Definition: systempage.cpp:41
INT_PTR CommonWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: systempage.cpp:484
#define GET_X_LPARAM(lp)
Definition: precomp.h:67
#define TreeView_GetCheckState(hwndTV, hti)
Definition: commctrl.h:3563
#define TVI_LAST
Definition: commctrl.h:3337
#define _SH_DENYWR
Definition: share.h:15
#define WM_DESTROY
Definition: winuser.h:1591
HTREEITEM hItem
Definition: commctrl.h:3488
#define PostMessage
Definition: winuser.h:5698
#define _tcsstr
Definition: xmlstorage.h:199
#define TreeView_DeleteItem(hwnd, hitem)
Definition: commctrl.h:3382
#define IDC_BTN_SYSTEM_EDIT
Definition: resource.h:67
static LPCWSTR szMSConfigTok
Definition: systempage.cpp:28
void TreeView_Set3StateCheck(HWND hTree)
Definition: treeview.c:24
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
#define TreeView_SetIndent(hwnd, indent)
Definition: commctrl.h:3405
#define _T(x)
Definition: vfdio.h:22
static WCHAR szSearchString[MAX_VALUE_NAME]
Definition: systempage.cpp:53
#define TreeView_GetSelection(hwnd)
Definition: commctrl.h:3440
unsigned int BOOL
Definition: ntddk_ex.h:94
#define _SH_DENYRW
Definition: share.h:14
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
#define TreeView_HitTest(hwnd, lpht)
Definition: commctrl.h:3480
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define PropSheet_Changed(d, w)
Definition: prsht.h:326
#define IDC_CBX_FIND_WHOLE_WORD_ONLY
Definition: resource.h:101
#define TVN_SELCHANGED
Definition: commctrl.h:3702
#define INDEXTOSTATEIMAGEMASK(i)
Definition: commctrl.h:2298
#define PropSheet_RebootSystem(d)
Definition: prsht.h:332
unsigned int UINT
Definition: ndis.h:50
#define Button_GetCheck(hwndCtl)
Definition: windowsx.h:6
LONG RegGetDWORDValue(IN HKEY hKey, IN LPCWSTR lpSubKey OPTIONAL, IN LPCWSTR lpValue OPTIONAL, OUT LPDWORD lpData OPTIONAL)
Definition: regutils.c:95
static HWND hTree
Definition: systempage.cpp:52
#define IDC_BTN_SYSTEM_DELETE
Definition: resource.h:46
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD GetSystemIniActivation(VOID)
Definition: systempage.cpp:34
#define IDC_RB_FIND_DOWN
Definition: resource.h:105
#define TVS_CHECKBOXES
Definition: commctrl.h:3222
void TreeView_UpItem(HWND hTree, HTREEITEM htiItemToUp)
Definition: treeview.c:204
#define TVI_ROOT
Definition: commctrl.h:3335
#define PSNRET_NOERROR
Definition: prsht.h:129
#define MB_ICONINFORMATION
Definition: winuser.h:796
INT_PTR CALLBACK WinPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: systempage.cpp:882
#define IDC_BTN_SYSTEM_ENABLE_ALL
Definition: resource.h:44
static void Update_Btn_States(HWND hDlg)
Definition: systempage.cpp:392
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define WPARAM
Definition: msvc.h:37
int cchTextMax
Definition: commctrl.h:3318
static const WCHAR L[]
Definition: oid.c:1087
#define TreeView_SetItemState(hwndTV, hti, data, _mask)
Definition: commctrl.h:3559
const DOCKBAR PVOID HWND hParent
Definition: tooldock.h:22
#define TreeView_GetParent(hwnd, hitem)
Definition: commctrl.h:3436
#define MessageBox
Definition: winuser.h:5688
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define WM_COMMAND
Definition: winuser.h:1716
#define BST_UNCHECKED
Definition: winuser.h:199
#define NM_CLICK
Definition: commctrl.h:130
uint8_t label[11]
Definition: fsck.fat.h:65
#define TVIF_HANDLE
Definition: commctrl.h:3237
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
TCHAR szAppName[128]
Definition: solitaire.cpp:16
#define GWL_STYLE
Definition: winuser.h:846
HWND WINAPI GetParent(_In_ HWND)
#define IDC_BTN_SYSTEM_DOWN
Definition: resource.h:62
HTREEITEM hItem
Definition: commctrl.h:3314
HINSTANCE hInst
Definition: dxdiag.c:13
#define TreeView_GetRoot(hwnd)
Definition: commctrl.h:3442
LPCWSTR lpszWinIni
Definition: systempage.cpp:24
INT_PTR CALLBACK SystemPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: systempage.cpp:868
#define TVIF_TEXT
Definition: commctrl.h:3233
#define PSN_RESET
Definition: prsht.h:118
#define TreeView_SelectItem(hwnd, hitem)
Definition: commctrl.h:3448
UINT TreeView_GetRealSubtreeState(HWND hTree, HTREEITEM htiSubtreeItem)
Definition: treeview.c:111
#define Edit_SetSel(hwndCtl, ichStart, ichEnd)
Definition: windowsx.h:85
#define TVINSERTSTRUCT
Definition: commctrl.h:3369
static const struct newhuff ht[]
Definition: huffman.h:296
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define HWND_DESKTOP
Definition: winuser.h:1195
#define VK_SPACE
Definition: winuser.h:2173
#define MB_OK
Definition: winuser.h:784
HTREEITEM hItem
Definition: commctrl.h:3284
#define IDC_CBX_FIND_MATCH_CASE
Definition: resource.h:102
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
#define TreeView_SetItem(hwnd, pitem)
Definition: commctrl.h:3464
#define GET_Y_LPARAM(lp)
Definition: precomp.h:68
#define BST_CHECKED
Definition: winuser.h:197
INT_PTR CALLBACK FindDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: systempage.cpp:72
#define LPNMTVDISPINFO
Definition: commctrl.h:3643
#define Button_SetCheck(hwndCtl, check)
Definition: windowsx.h:10
LPCWSTR lpszSystemIni
Definition: systempage.cpp:23
HTREEITEM TreeView_GetNext(HWND hTree, HTREEITEM hItem)
Definition: treeview.c:263
void TreeView_DownItem(HWND hTree, HTREEITEM htiItemToDown)
Definition: treeview.c:186
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
#define IDC_BTN_SYSTEM_ENABLE
Definition: resource.h:63
#define towlower(c)
Definition: wctype.h:97
static const size_t MSConfigTokLen
Definition: systempage.cpp:29
#define IDD_FIND_DIALOG
Definition: resource.h:17
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDCANCEL
Definition: winuser.h:825
#define TreeView_GetPrevSibling(hwnd, hitem)
Definition: commctrl.h:3435
static void ToLower(LPWSTR lpszString)
Definition: systempage.cpp:59
#define Edit_SetText(hwndCtl, lpsz)
Definition: windowsx.h:87
#define TreeView_GetIndent(hwnd)
Definition: commctrl.h:3402
HTREEITEM TreeView_GetFirst(HWND hTree)
Definition: treeview.c:224
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define TVN_KEYDOWN
Definition: commctrl.h:3680
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define PSN_QUERYINITIALFOCUS
Definition: settings.cpp:98
#define TreeView_GetItem(hwnd, pitem)
Definition: commctrl.h:3457
#define LVIS_FOCUSED
Definition: commctrl.h:2288
#define WM_NOTIFY
Definition: richedit.h:61
#define IDC_BTN_SYSTEM_FIND
Definition: resource.h:65
#define TVIS_STATEIMAGEMASK
Definition: commctrl.h:3255
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define LPCWSTR
Definition: msvc.h:45