Display Mode: Как определить, что приложение запущено в консольном режиме?
Написал Ярослав Гасов   
20.01.2010

Share this!

{
function GetConsoleDisplayMode(var lpdwMode: DWORD): BOOL; stdcall;
   external 'kernel32.dll';
  // lpdwMode: address of variable for current value of display mode
}


function NT_GetConsoleDisplayMode(var lpdwMode: DWORD): Boolean;
type
  TGetConsoleDisplayMode = function(var lpdwMode: DWORD): BOOL;
  stdcall;
var
  hKernel: THandle;
  GetConsoleDisplayMode: TGetConsoleDisplayMode;
begin
  Result := False;
  hKernel := GetModuleHandle('kernel32.dll');
  if (hKernel > 0) then
  begin @GetConsoleDisplayMode :=
      GetProcAddress(hKernel, 'GetConsoleDisplayMode');
    if Assigned(GetConsoleDisplayMode) then
    begin
      Result := GetConsoleDisplayMode(lpdwMode);
    end;
  end;
end;

 

Пример использования:

 

Var

   MODE: DWORD;

 

begin

   if ( NT_GetConsoleDisplayMode(MODE) AND (MODE > 0) ) then

      ...