Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
6.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Fake.c
  3. //
  4. // this code gives OEMs a bogus Settings page to patch/modify
  5. //
  6. // OEM display pages patch the snot out of the Settings page
  7. // the problem is that we have changed the setting page, and
  8. // even if the OEM code could deal with our changes, the
  9. // settings page is not even on the same property sheet
  10. // as the extensions.
  11. //
  12. // some OEMs hook the setting page by hooking the TabContol and
  13. // watching for a mouse click to activate the Settings page
  14. // then they modify the page. NOTE they dont patch the page
  15. // if it is activated via the keyboard only the mouse!
  16. //
  17. // some OEM pages find the Setting page by name.
  18. // we have named the real settings page "Settings " and
  19. // the fake page is "Settings"
  20. //
  21. // some OEM pages assume the last page is the Settings page.
  22. // we make sure the fake settings is always last.
  23. //
  24. ///////////////////////////////////////////////////////////////////////////////
  25. #include "priv.h"
  26. #include "winuser.h"
  27. #pragma hdrstop
  28. #include "cplext.h"
  29. /*
  30. * Global stuff
  31. */
  32. static LONG_PTR TabWndProc; // SysTabControl WndProc
  33. static LONG_PTR DlgWndProc; // Dialog WndProc
  34. /*
  35. * Local Constant Declarations
  36. */
  37. int CALLBACK DeskPropSheetCallback(HWND hDlg, UINT code, LPARAM lParam);
  38. INT_PTR CALLBACK FakeSettingsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  39. IThemeUIPages *g_pThemeUI;
  40. ///////////////////////////////////////////////////////////////////////////////
  41. // AddFakeSettingsPage
  42. ///////////////////////////////////////////////////////////////////////////////
  43. void AddFakeSettingsPage(IThemeUIPages *pThemeUI, PROPSHEETHEADER * ppsh)
  44. {
  45. g_pThemeUI = pThemeUI;
  46. PROPSHEETPAGE psp;
  47. HPROPSHEETPAGE hpsp;
  48. ZeroMemory(&psp, sizeof(psp));
  49. psp.dwSize = sizeof(psp);
  50. psp.dwFlags = PSP_DEFAULT;
  51. psp.hInstance = HINST_THISDLL;
  52. psp.pszTemplate = MAKEINTRESOURCE(DLG_FAKE_SETTINGS);
  53. psp.pfnDlgProc = FakeSettingsDlgProc;
  54. psp.lParam = 0L;
  55. //
  56. // some OEMs find the Property sheet by window title
  57. // so make sure we have the title they expect.
  58. //
  59. hpsp = CreatePropertySheetPage(&psp);
  60. if (hpsp)
  61. {
  62. ppsh->phpage[ppsh->nPages++] = hpsp;
  63. ppsh->pfnCallback = DeskPropSheetCallback;
  64. ppsh->dwFlags |= PSH_USECALLBACK;
  65. }
  66. }
  67. ///////////////////////////////////////////////////////////////////////////////
  68. // FakeSettingsDlgProc
  69. ///////////////////////////////////////////////////////////////////////////////
  70. INT_PTR CALLBACK FakeSettingsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  71. {
  72. if (hDlg && DlgWndProc)
  73. {
  74. if (GetWindowLongPtr(hDlg, GWLP_WNDPROC) != DlgWndProc)
  75. {
  76. SetWindowLongPtr(hDlg, GWLP_WNDPROC, DlgWndProc);
  77. }
  78. if (GetWindowLongPtr(hDlg, DWLP_DLGPROC) != (LONG_PTR)FakeSettingsDlgProc)
  79. {
  80. SetWindowLongPtr(hDlg, DWLP_DLGPROC, (LONG_PTR)FakeSettingsDlgProc);
  81. }
  82. }
  83. switch (message)
  84. {
  85. case WM_INITDIALOG:
  86. return TRUE;
  87. case WM_DESTROY:
  88. break;
  89. case WM_COMMAND:
  90. if (LOWORD(wParam) == IDC_CHANGEDRV)
  91. {
  92. }
  93. break;
  94. }
  95. return FALSE;
  96. }
  97. ///////////////////////////////////////////////////////////////////////////////
  98. // HideFakeSettingsPage
  99. //
  100. // hide the bogus settings page from view so the user cant see it.
  101. //
  102. // this code uses a new TabCtrl item style TCIS_HIDDEN that is only
  103. // in the Win98/NT5/IE4.01 COMMCTRL
  104. //
  105. ///////////////////////////////////////////////////////////////////////////////
  106. void HideFakeSettingsPage(HWND hDlg)
  107. {
  108. HWND hwnd = PropSheet_GetTabControl(hDlg);
  109. if (hwnd)
  110. {
  111. TCITEM tci;
  112. tci.mask = TCIF_STATE;
  113. tci.dwStateMask = TCIS_HIDDEN;
  114. tci.dwState = TCIS_HIDDEN;
  115. TabCtrl_SetItem(hwnd, TabCtrl_GetItemCount(hwnd)-1, &tci);
  116. }
  117. }
  118. ///////////////////////////////////////////////////////////////////////////////
  119. // DeskPropSheetCallback
  120. //
  121. // what this callback does is look for someone subclassing the
  122. // tab control, if we detect this we put the correct WndProc
  123. // back.
  124. //
  125. // we also hide the fake settings page after all the entensions
  126. // have initialized
  127. //
  128. ///////////////////////////////////////////////////////////////////////////////
  129. int CALLBACK DeskPropSheetCallback(HWND hDlg, UINT code, LPARAM lParam)
  130. {
  131. HWND hwnd;
  132. WNDCLASS wc;
  133. switch (code)
  134. {
  135. case PSCB_INITIALIZED:
  136. TraceMsg(TF_GENERAL, "DeskPropSheetCallback: PSCB_INITIALIZED");
  137. hwnd = PropSheet_GetTabControl(hDlg);
  138. if (hwnd && TabWndProc)
  139. {
  140. if (GetWindowLongPtr(hwnd, GWLP_WNDPROC) != TabWndProc)
  141. {
  142. SetWindowLongPtr(hwnd, GWLP_WNDPROC, TabWndProc);
  143. }
  144. }
  145. if (hDlg && DlgWndProc)
  146. {
  147. if (GetWindowLongPtr(hDlg, GWLP_WNDPROC) != DlgWndProc)
  148. {
  149. SetWindowLongPtr(hDlg, GWLP_WNDPROC, DlgWndProc);
  150. }
  151. }
  152. //
  153. // hide the settings page so the user cant see it.
  154. //
  155. HideFakeSettingsPage(hDlg);
  156. break;
  157. case PSCB_PRECREATE:
  158. TraceMsg(TF_GENERAL, "DeskPropSheetCallback: PSCB_PRECREATE");
  159. ZeroMemory(&wc, sizeof(wc));
  160. SHFusionGetClassInfo(NULL, WC_DIALOG, &wc);
  161. DlgWndProc = (LONG_PTR)wc.lpfnWndProc;
  162. ZeroMemory(&wc, sizeof(wc));
  163. SHFusionGetClassInfo(NULL, WC_TABCONTROL, &wc);
  164. TabWndProc = (LONG_PTR)wc.lpfnWndProc;
  165. break;
  166. case PSCB_BUTTONPRESSED:
  167. if ((PSBTN_OK == lParam) || (PSBTN_APPLYNOW == lParam))
  168. {
  169. DWORD dwFlags = ((PSBTN_OK == lParam) ? (TUIAP_WAITFORAPPLY | TUIAP_NONE) : TUIAP_NONE);
  170. if (g_pThemeUI)
  171. {
  172. g_pThemeUI->ApplyPressed(dwFlags);
  173. }
  174. }
  175. break;
  176. }
  177. return 0;
  178. }