Author: Tomas Rutkauskas
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:
1 2 function IsConsoleFullscreen: Boolean;
3 type4 TGetConsoleDisplayMode = function(var lpdwMode: DWORD): Boolean; stdcall;
5 var6 Handle: THandle;
7 DisplayMode: TGetConsoleDisplayMode;
8 W: HWND;
9 PID: Cardinal;
10 R: TRect;
11 CurMode: DWORD;
12 PlatFormXP2000: Boolean;
13 begin14 Result := False;
15 PlatFormXP2000 := False;
16 Handle := LoadLibrary('kernel32.dll');
17 if Handle <> 0 then18 begin19 @DisplayMode := GetProcAddress(Handle, 'GetConsoleDisplayMode');
20 if @DisplayMode <> nilthen21 begin22 PlatFormXP2000 := DisplayMode(CurMode);
23 if PlatFormXP2000 then24 Result := (CurMode <> 0);
25 end;
26 FreeLibrary(Handle);
27 end;
28 ifnot PlatFormXP2000 then29 begin30 W := GetForegroundWindow;
31 GetWindowThreadProcessId(W, @PID);
32 if PID <> GetCurrentProcessID then33 exit;
34 ifnot IsIconic(W) then35 exit;
36 GetClientRect(W, R);
37 Result := (R.Right = 0) and (R.Bottom = 0);
38 end;
39 end;