Ir al contenido


Foto

[TRUCO DELPHI] Cambiar a Pantalla completa una aplicacion de Consola.


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 sir.dev.a.lot

sir.dev.a.lot

    Advanced Member

  • Miembros
  • PipPipPip
  • 545 mensajes
  • Location127.0.0.1

Escrito 29 agosto 2016 - 08:26


delphi
  1. function NT_GetConsoleDisplayMode(var lpdwMode: DWORD): Boolean;
  2. type
  3. TGetConsoleDisplayMode = function(var lpdwMode: DWORD): BOOL;
  4. stdcall;
  5. var
  6. hKernel: THandle;
  7. GetConsoleDisplayMode: TGetConsoleDisplayMode;
  8. begin
  9. Result := False;
  10. hKernel := GetModuleHandle('kernel32.dll');
  11. if (hKernel > 0) then
  12. begin @GetConsoleDisplayMode :=
  13. GetProcAddress(hKernel, 'GetConsoleDisplayMode');
  14. if Assigned(GetConsoleDisplayMode) then
  15. begin
  16. Result := GetConsoleDisplayMode(lpdwMode);
  17. end;
  18. end;
  19. end;
  20.  
  21.  
  22. function NT_SetConsoleDisplayMode(hOut: THandle; dwNewMode: DWORD;
  23. var lpdwOldMode: DWORD): Boolean;
  24. type
  25. TSetConsoleDisplayMode = function(hOut: THandle; dwNewMode: DWORD;
  26. var lpdwOldMode: DWORD): BOOL;
  27. stdcall;
  28. var
  29. hKernel: THandle;
  30. SetConsoleDisplayMode: TSetConsoleDisplayMode;
  31. begin
  32. Result := False;
  33. hKernel := GetModuleHandle('kernel32.dll');
  34. if (hKernel > 0) then
  35. begin @SetConsoleDisplayMode :=
  36. GetProcAddress(hKernel, 'SetConsoleDisplayMode');
  37. if Assigned(SetConsoleDisplayMode) then
  38. begin
  39. Result := SetConsoleDisplayMode(hOut, dwNewMode, lpdwOldMode);
  40. end;
  41. end;
  42. end;
  43.  
  44. function GetConsoleWindow: THandle;
  45. var
  46. S: AnsiString;
  47. C: Char;
  48. begin
  49. Result := 0;
  50. Setlength(S, MAX_PATH + 1);
  51. if GetConsoleTitle(PChar(S), MAX_PATH) <> 0 then
  52. begin
  53. C := S[1];
  54. S[1] := '$';
  55. SetConsoleTitle(PChar(S));
  56. Result := FindWindow(nil, PChar(S));
  57. S[1] := C;
  58. SetConsoleTitle(PChar(S));
  59. end;
  60. end;
  61.  
  62. function SetConsoleFullScreen(bFullScreen: Boolean): Boolean;
  63. const
  64. MAGIC_CONSOLE_TOGGLE = 57359;
  65. var
  66. dwOldMode: DWORD;
  67. dwNewMode: DWORD;
  68. hOut: THandle;
  69. hConsole: THandle;
  70. begin
  71. if Win32Platform = VER_PLATFORM_WIN32_NT then
  72. begin
  73. dwNewMode := Ord(bFullScreen);
  74. NT_GetConsoleDisplayMode(dwOldMode);
  75. hOut := GetStdHandle(STD_OUTPUT_HANDLE);
  76. Result := NT_SetConsoleDisplayMode(hOut, dwNewMode, dwOldMode);
  77. end
  78. else
  79. begin
  80. hConsole := GetConsoleWindow;
  81. Result := hConsole <> 0;
  82. if Result then
  83. begin
  84. if bFullScreen then
  85. begin
  86. SendMessage(GetConsoleWindow, WM_COMMAND, MAGIC_CONSOLE_TOGGLE, 0);
  87. end
  88. else
  89. begin
  90.  
  91. keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
  92. keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
  93. keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP,
  94. 0);
  95. keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
  96. end;
  97. end;
  98. end;
  99. end;

Ejemplo de Uso:


delphi
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3. s: string;
  4. begin
  5. AllocConsole;
  6. try
  7. SetConsoleFullScreen(True);
  8. Write('Entre a Pantalla Completa ');
  9. Readln(s);
  10. SetConsoleFullScreen(False);
  11. finally
  12. FreeConsole;
  13. end;
  14. end;

Saludos!


  • 2




IP.Board spam blocked by CleanTalk.