2004. november 16., kedd

Check if a console application is running in full screen mode


Problem/Question/Abstract:

I made a console application that at some point needs to know if it's running in a window or in full screen mode. I looked at Console API calls, but cannot find anything distinctive.

Answer:

The function IsConsoleFullscreen() works fine with W98 and ME, but not with 2000 (and XP, I presume). The GetConsoleDisplayMode function is also in Win2000 (not documented), at least with service pack 1 and up. To get the test to work on both series of platforms, you have to use LoadLibrary and GetProcAddress:

function IsConsoleFullscreen: Boolean;
type
  TGetConsoleDisplayMode = function(var lpdwMode: DWORD): Boolean; stdcall;
var
  Handle: THandle;
  DisplayMode: TGetConsoleDisplayMode;
  W: HWND;
  PID: Cardinal;
  R: TRect;
  CurMode: DWORD;
  PlatFormXP2000: Boolean;
begin
  Result := False;
  PlatFormXP2000 := False;
  Handle := LoadLibrary('kernel32.dll');
  if Handle <> 0 then
  begin
    @DisplayMode := GetProcAddress(Handle, 'GetConsoleDisplayMode');
    if @DisplayMode <> nil then
    begin
      PlatFormXP2000 := DisplayMode(CurMode);
      if PlatFormXP2000 then
        Result := (CurMode <> 0);
    end;
    FreeLibrary(Handle);
  end;
  if not PlatFormXP2000 then
  begin
    W := GetForegroundWindow;
    GetWindowThreadProcessId(W, @PID);
    if PID <> GetCurrentProcessID then
      exit;
    if not IsIconic(W) then
      exit;
    GetClientRect(W, R);
    Result := (R.Right = 0) and (R.Bottom = 0);
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése