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.

158 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ForceDisplayMode.cpp
  5. Abstract:
  6. This shim is for games that require a specific resolution to run at.
  7. It takes a command line to specify the resolution: width in pixels, height
  8. in pixels,bits per pixel if you don't specify one or more of those, we'll
  9. use the current setting.
  10. eg: 1024,768 will change resolution to 1024x768.
  11. eg: ,,16 will change the color depth to 16 bit.
  12. Notes:
  13. This is a general purpose shim.
  14. History:
  15. 11/08/2000 maonis Created (adopted from Force640x480x8 and Force640x480x16 shims)
  16. 03/13/2001 robkenny Converted to CString
  17. --*/
  18. #include "precomp.h"
  19. IMPLEMENT_SHIM_BEGIN(ForceDisplayMode)
  20. #include "ShimHookMacro.h"
  21. // This module has been given an official blessing to use the str routines.
  22. #include "strsafe.h"
  23. #define MAX_LENGTH 1024
  24. APIHOOK_ENUM_BEGIN
  25. APIHOOK_ENUM_END
  26. DWORD g_dmPelsWidth = 0;
  27. DWORD g_dmPelsHeight = 0;
  28. DWORD g_dmBitsPerPel = 0;
  29. VOID
  30. ParseCommandLine(
  31. LPCSTR lpCommandLine
  32. )
  33. {
  34. size_t slen = 0;
  35. if (FAILED(StringCchLengthA((char *)lpCommandLine, MAX_LENGTH, &slen)))
  36. {
  37. DPFN( eDbgLevelError,
  38. "[ParseCommandLine] Error in StringCchLength \n");
  39. return;
  40. }
  41. LPSTR szCommandLine = (LPSTR) malloc(slen + 1);
  42. if (!szCommandLine) {
  43. DPFN( eDbgLevelError,
  44. "[ParseCommandLine] not enough memory\n");
  45. return;
  46. }
  47. if (FAILED(StringCchCopyA(szCommandLine, (slen + 1), lpCommandLine)))
  48. {
  49. DPFN( eDbgLevelError,
  50. "[ParseCommandLine] Error in StringCchCopyA \n");
  51. return;
  52. }
  53. char *token, *szCurr = szCommandLine;
  54. if (token = strchr(szCurr, ',')) {
  55. *token = '\0';
  56. g_dmPelsWidth = atol(szCurr);
  57. szCurr = token + 1;
  58. if (token = strchr(szCurr, ',')) {
  59. *token = '\0';
  60. g_dmBitsPerPel = atol(token + 1);
  61. }
  62. g_dmPelsHeight = atol(szCurr);
  63. } else {
  64. g_dmPelsWidth = atol(szCurr);
  65. }
  66. DPFN( eDbgLevelError,
  67. "[ParseCommandLine] width = %d pixels; height = %d pixels; color depth = %d\n", g_dmPelsWidth, g_dmPelsHeight, g_dmBitsPerPel);
  68. free(szCommandLine);
  69. }
  70. VOID
  71. ChangeMode()
  72. {
  73. DEVMODEA dm;
  74. BOOL fNeedChange = FALSE;
  75. __try {
  76. EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dm);
  77. if (g_dmPelsWidth && g_dmPelsWidth != dm.dmPelsWidth) {
  78. dm.dmPelsWidth = g_dmPelsWidth;
  79. fNeedChange = TRUE;
  80. }
  81. if (g_dmPelsHeight && g_dmPelsHeight != dm.dmPelsHeight) {
  82. dm.dmPelsHeight = g_dmPelsHeight;
  83. fNeedChange = TRUE;
  84. }
  85. if (g_dmBitsPerPel && g_dmBitsPerPel != dm.dmBitsPerPel) {
  86. dm.dmBitsPerPel = g_dmBitsPerPel;
  87. fNeedChange = TRUE;
  88. }
  89. if (fNeedChange) {
  90. ChangeDisplaySettingsA(&dm, CDS_FULLSCREEN);
  91. }
  92. }
  93. __except(1) {
  94. DPFN( eDbgLevelWarning, "Exception trying to change mode");
  95. };
  96. }
  97. /*++
  98. Register hooked functions
  99. --*/
  100. BOOL
  101. NOTIFY_FUNCTION(
  102. DWORD fdwReason)
  103. {
  104. if (fdwReason == SHIM_STATIC_DLLS_INITIALIZED) {
  105. ParseCommandLine(COMMAND_LINE);
  106. ChangeMode();
  107. }
  108. return TRUE;
  109. }
  110. HOOK_BEGIN
  111. CALL_NOTIFY_FUNCTION
  112. HOOK_END
  113. IMPLEMENT_SHIM_END