7

因为我可以在控制台应用程序上激活玻璃效果。我正在使用Windows 7和德尔福2010年。如何在使用Delphi的控制台应用程序中激活玻璃效果(Windows Vista/7)

我发现this应用程序,所以它应该是可能的。

+1

控制台窗口是共享资源。它不属于你的程序。不要对不属于您的窗口进行全局更改。如果您的客户希望他们的控制台窗口看起来很花哨,他们可以安装您链接的程序。 – 2009-11-19 22:54:00

回答

15

几个星期前,我在我的博客上发布了this article

关键是使用GetConsoleWindowDwmEnableBlurBehindWindow函数。

GetConsoleWindow函数检索与调用进程关联的控制台使用的窗口句柄。

DwmEnableBlurBehindWindow函数使所提供的窗口句柄上的模糊效果(玻璃)。

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. 

这只是一个基本的例子;您必须检查Windows操作系统版本以避免问题。

Screenshot

+0

如果将“窗口颜色和外观”设置为霜冻,这种方法效果不佳...白色背景上的白色文字 – 2011-02-16 03:22:50