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.

226 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ForceSimpleWindow.cpp
  5. Abstract:
  6. Make the simplest possible full-screen window.
  7. Notes:
  8. This is a general purpose shim, but should not be used in a layer.
  9. History:
  10. 06/01/2000 linstev Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(ForceSimpleWindow)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY(CreateWindowExA)
  17. APIHOOK_ENUM_ENTRY(CreateWindowExW)
  18. APIHOOK_ENUM_ENTRY(SetWindowLongA)
  19. APIHOOK_ENUM_ENTRY(SetWindowLongW)
  20. APIHOOK_ENUM_END
  21. BOOL g_bFullScreen = TRUE;
  22. /*++
  23. Simplify window if it's not a child.
  24. --*/
  25. HWND
  26. APIHOOK(CreateWindowExA)(
  27. DWORD dwExStyle,
  28. LPCSTR lpClassName,
  29. LPCSTR lpWindowName,
  30. DWORD dwStyle,
  31. int x,
  32. int y,
  33. int nWidth,
  34. int nHeight,
  35. HWND hWndParent,
  36. HMENU hMenu,
  37. HINSTANCE hInstance,
  38. LPVOID lpParam
  39. )
  40. {
  41. if (!(dwStyle & WS_CHILD))
  42. {
  43. DPFN( eDbgLevelWarning, "Window \"%s\" style simplified: WS_STYLE=%08lx, WS_EXSTYLE=%08lx", lpWindowName, dwStyle, dwExStyle);
  44. dwStyle &= WS_VISIBLE;
  45. dwStyle |= WS_OVERLAPPED|WS_POPUP;
  46. dwExStyle = 0;
  47. if (g_bFullScreen)
  48. {
  49. DPFN( eDbgLevelWarning, "Window \"%s\" maximized", lpWindowName);
  50. x = y = 0;
  51. nWidth = GetSystemMetrics(SM_CXSCREEN);
  52. nHeight = GetSystemMetrics(SM_CYSCREEN);
  53. dwExStyle = WS_EX_TOPMOST;
  54. }
  55. }
  56. return ORIGINAL_API(CreateWindowExA)(
  57. dwExStyle,
  58. lpClassName,
  59. lpWindowName,
  60. dwStyle,
  61. x,
  62. y,
  63. nWidth,
  64. nHeight,
  65. hWndParent,
  66. hMenu,
  67. hInstance,
  68. lpParam);
  69. }
  70. /*++
  71. Simplify window if it's not a child.
  72. --*/
  73. HWND
  74. APIHOOK(CreateWindowExW)(
  75. DWORD dwExStyle,
  76. LPCWSTR lpClassName,
  77. LPCWSTR lpWindowName,
  78. DWORD dwStyle,
  79. int x,
  80. int y,
  81. int nWidth,
  82. int nHeight,
  83. HWND hWndParent,
  84. HMENU hMenu,
  85. HINSTANCE hInstance,
  86. LPVOID lpParam
  87. )
  88. {
  89. if (!(dwStyle & WS_CHILD))
  90. {
  91. DPFN( eDbgLevelWarning, "Window \"%S\" style simplified: WS_STYLE=%08lx, WS_EXSTYLE=%08lx", lpWindowName, dwStyle, dwExStyle);
  92. dwStyle &= WS_VISIBLE;
  93. dwStyle |= WS_OVERLAPPED|WS_POPUP;
  94. dwExStyle = 0;
  95. if (g_bFullScreen)
  96. {
  97. DPFN( eDbgLevelWarning, "Window \"%S\" maximized", lpWindowName);
  98. x = y = 0;
  99. nWidth = GetSystemMetrics(SM_CXSCREEN);
  100. nHeight = GetSystemMetrics(SM_CYSCREEN);
  101. dwExStyle = WS_EX_TOPMOST;
  102. }
  103. }
  104. return ORIGINAL_API(CreateWindowExW)(
  105. dwExStyle,
  106. lpClassName,
  107. lpWindowName,
  108. dwStyle,
  109. x,
  110. y,
  111. nWidth,
  112. nHeight,
  113. hWndParent,
  114. hMenu,
  115. hInstance,
  116. lpParam);
  117. }
  118. LONG
  119. APIHOOK(SetWindowLongA)(
  120. HWND hWnd,
  121. int nIndex,
  122. LONG dwNewLong
  123. )
  124. {
  125. if ((nIndex == GWL_STYLE) || (nIndex == GWL_EXSTYLE))
  126. {
  127. CHAR szName[MAX_PATH];
  128. GetWindowTextA(hWnd, szName, MAX_PATH);
  129. DPFN( eDbgLevelWarning, "Window \"%s\": ignoring style change", szName);
  130. return GetWindowLongA(hWnd, nIndex);
  131. }
  132. else
  133. {
  134. return ORIGINAL_API(SetWindowLongA)(
  135. hWnd,
  136. nIndex,
  137. dwNewLong);
  138. }
  139. }
  140. LONG
  141. APIHOOK(SetWindowLongW)(
  142. HWND hWnd,
  143. int nIndex,
  144. LONG dwNewLong
  145. )
  146. {
  147. if ((nIndex == GWL_STYLE) || (nIndex == GWL_EXSTYLE))
  148. {
  149. CHAR szName[MAX_PATH];
  150. GetWindowTextA(hWnd, szName, MAX_PATH);
  151. DPFN( eDbgLevelWarning, "Window \"%s\": ignoring style change", szName);
  152. return GetWindowLongW(hWnd, nIndex);
  153. }
  154. else
  155. {
  156. return ORIGINAL_API(SetWindowLongW)(
  157. hWnd,
  158. nIndex,
  159. dwNewLong);
  160. }
  161. }
  162. /*++
  163. Register hooked functions
  164. --*/
  165. BOOL
  166. NOTIFY_FUNCTION(
  167. DWORD fdwReason
  168. )
  169. {
  170. if (fdwReason == DLL_PROCESS_ATTACH)
  171. {
  172. CString csCl(COMMAND_LINE);
  173. g_bFullScreen = csCl.CompareNoCase(L"FULLSCREEN") == 0;
  174. }
  175. return TRUE;
  176. }
  177. HOOK_BEGIN
  178. CALL_NOTIFY_FUNCTION
  179. APIHOOK_ENTRY(USER32.DLL, CreateWindowExA)
  180. APIHOOK_ENTRY(USER32.DLL, CreateWindowExW)
  181. APIHOOK_ENTRY(USER32.DLL, SetWindowLongA)
  182. APIHOOK_ENTRY(USER32.DLL, SetWindowLongW)
  183. HOOK_END
  184. IMPLEMENT_SHIM_END