How can activate a glass effect (windows Vista/7) in a console application using Delphi
Asked Answered
W

1

8

As I can activate the glass effect on my console applications. I am using Windows 7 and Delphi 2010.

I found this application so it should be possible.

Waterrepellent answered 19/11, 2009 at 21:4 Comment(1)
The console window is a shared resource. It does not belong to your program. Do not make global changes to a window that doesn't belong to you. If your customers want their console windows to look fancy, they can install the program you linked to.Blair
A
16

A couple of weeks ago I published this article on my blog.

The key is use the GetConsoleWindow and DwmEnableBlurBehindWindow functions.

The GetConsoleWindow function retrieves the window handle used by the console associated with the calling process.

The DwmEnableBlurBehindWindow function enables the blur effect (glass) on the provided window handle.

program ConsoleGlassDelphi;

{$APPTYPE CONSOLE}

    uses
  Windows,
  SysUtils;

type
  DWM_BLURBEHIND = record
    dwFlags                 : DWORD;
    fEnable                 : BOOL;
    hRgnBlur                : HRGN;
    fTransitionOnMaximized  : BOOL;
  end;

function DwmEnableBlurBehindWindow(hWnd : HWND; const pBlurBehind : DWM_BLURBEHIND) : HRESULT; stdcall; external  'dwmapi.dll' name 'DwmEnableBlurBehindWindow';//function to enable the glass effect
function GetConsoleWindow: HWND; stdcall; external kernel32 name 'GetConsoleWindow'; //get the handle of the console window

function DWM_EnableBlurBehind(hwnd : HWND; AEnable: Boolean; hRgnBlur : HRGN = 0; ATransitionOnMaximized: Boolean = False; AFlags: Cardinal = 1): HRESULT;
var
  pBlurBehind : DWM_BLURBEHIND;
begin
  pBlurBehind.dwFlags:=AFlags;
  pBlurBehind.fEnable:=AEnable;
  pBlurBehind.hRgnBlur:=hRgnBlur;
  pBlurBehind.fTransitionOnMaximized:=ATransitionOnMaximized;
  Result:=DwmEnableBlurBehindWindow(hwnd, pBlurBehind);
end;

begin
  try
    DWM_EnableBlurBehind(GetConsoleWindow(), True);
    Writeln('See my glass effect');
    Writeln('Go Delphi Go');
    Readln;
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.

This is just a basic example; you must check the Windows OS version to avoid issues.

Screenshot

Alburga answered 19/11, 2009 at 21:8 Comment(1)
This dose not work well if the "window Color and Appearance" is set to frost... white text on a white backgroundConsidering

© 2022 - 2024 — McMap. All rights reserved.