Source code of Windows XP (NT5)
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.

142 lines
2.9 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 "LegalStr.h"
  23. APIHOOK_ENUM_BEGIN
  24. APIHOOK_ENUM_END
  25. DWORD g_dmPelsWidth = 0;
  26. DWORD g_dmPelsHeight = 0;
  27. DWORD g_dmBitsPerPel = 0;
  28. VOID
  29. ParseCommandLine(
  30. LPCSTR lpCommandLine
  31. )
  32. {
  33. LPSTR szCommandLine = (LPSTR) malloc(strlen(lpCommandLine) + 1);
  34. if (!szCommandLine) {
  35. DPFN( eDbgLevelError,
  36. "[ParseCommandLine] not enough memory\n");
  37. return;
  38. }
  39. strcpy(szCommandLine, lpCommandLine);
  40. char *token, *szCurr = szCommandLine;
  41. if (token = strchr(szCurr, ',')) {
  42. *token = '\0';
  43. g_dmPelsWidth = atol(szCurr);
  44. szCurr = token + 1;
  45. if (token = strchr(szCurr, ',')) {
  46. *token = '\0';
  47. g_dmBitsPerPel = atol(token + 1);
  48. }
  49. g_dmPelsHeight = atol(szCurr);
  50. } else {
  51. g_dmPelsWidth = atol(szCurr);
  52. }
  53. DPFN( eDbgLevelError,
  54. "[ParseCommandLine] width = %d pixels; height = %d pixels; color depth = %d\n", g_dmPelsWidth, g_dmPelsHeight, g_dmBitsPerPel);
  55. free(szCommandLine);
  56. }
  57. VOID
  58. ChangeMode()
  59. {
  60. DEVMODEA dm;
  61. BOOL fNeedChange = FALSE;
  62. __try {
  63. EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &dm);
  64. if (g_dmPelsWidth && g_dmPelsWidth != dm.dmPelsWidth) {
  65. dm.dmPelsWidth = g_dmPelsWidth;
  66. fNeedChange = TRUE;
  67. }
  68. if (g_dmPelsHeight && g_dmPelsHeight != dm.dmPelsHeight) {
  69. dm.dmPelsHeight = g_dmPelsHeight;
  70. fNeedChange = TRUE;
  71. }
  72. if (g_dmBitsPerPel && g_dmBitsPerPel != dm.dmBitsPerPel) {
  73. dm.dmBitsPerPel = g_dmBitsPerPel;
  74. fNeedChange = TRUE;
  75. }
  76. if (fNeedChange) {
  77. ChangeDisplaySettingsA(&dm, CDS_FULLSCREEN);
  78. }
  79. }
  80. __except(1) {
  81. DPFN( eDbgLevelWarning, "Exception trying to change mode");
  82. };
  83. }
  84. /*++
  85. Register hooked functions
  86. --*/
  87. BOOL
  88. NOTIFY_FUNCTION(
  89. DWORD fdwReason)
  90. {
  91. if (fdwReason == SHIM_STATIC_DLLS_INITIALIZED) {
  92. ParseCommandLine(COMMAND_LINE);
  93. ChangeMode();
  94. }
  95. return TRUE;
  96. }
  97. HOOK_BEGIN
  98. CALL_NOTIFY_FUNCTION
  99. HOOK_END
  100. IMPLEMENT_SHIM_END