www.pudn.com > TMS.Component.Pack.v5.0.rar > AdvDWM.pas, change:2009-01-24,size:3540b


unit AdvDWM; 
 
{$HPPEMIT ''} 
{$HPPEMIT '#include "dwmapi.h"'} 
{$HPPEMIT ''} 
 
{$I TMSDEFS.INC} 
{$T-} 
 
interface 
 
uses Windows 
  {$IFDEF DELPHI2007_LVL} 
  , UxTheme 
  {$ELSE} 
  , AdvuxTheme 
  {$ENDIF} 
  ; 
 
{$EXTERNALSYM DwmDefWindowProc} 
function DwmDefWindowProc(hWnd: HWND; msg: UINT; wParam: WPARAM; lParam: LPARAM; 
  var plResult: LRESULT): BOOL; 
 
{$EXTERNALSYM DwmExtendFrameIntoClientArea} 
function DwmExtendFrameIntoClientArea(hWnd: HWND; const pMarInset: TMargins): HResult; 
 
{$EXTERNALSYM DwmIsCompositionEnabled} 
function DwmIsCompositionEnabled(out pfEnabled: BOOL): HResult; 
 
function DwmCompositionEnabled: Boolean; 
 
implementation 
 
uses 
  SysUtils; 
 
const 
  ModName = 'DWMAPI.DLL'; 
 
var 
  hDWMAPI: HMODULE; 
 
var 
  _DwmDefWindowProc: function(hWnd: HWND; msg: UINT; wParam: WPARAM; 
    lParam: LPARAM; var plResult: LRESULT): BOOL; stdcall; 
 
  _DwmExtendFrameIntoClientArea: function(hWnd: HWND; 
    const pMarInset: TMargins): HResult; stdcall; 
 
  _DwmIsCompositionEnabled: function(out pfEnabled: BOOL): HResult; stdcall; 
 
//------------------------------------------------------------------------------ 
 
procedure InitDwmApi; //inline; 
begin 
  if hDWMAPI = 0 then 
    hDWMAPI := LoadLibrary(ModName); 
end; 
 
//------------------------------------------------------------------------------ 
 
function DwmDefWindowProc(hWnd: HWND; msg: UINT; wParam: WPARAM; 
  lParam: LPARAM; var plResult: LRESULT): BOOL; 
begin 
  if Assigned(_DwmDefWindowProc) then 
    Result := _DwmDefWindowProc(hWnd, msg, wParam, lParam, plResult) 
  else 
  begin 
    InitDwmApi; 
    Result := False; 
    if hDWMAPI > 0 then 
    begin 
      _DwmDefWindowProc := GetProcAddress(hDWMAPI, 'DwmDefWindowProc'); 
      if Assigned(_DwmDefWindowProc) then 
        Result := _DwmDefWindowProc(hWnd, msg, wParam, lParam, plResult); 
    end; 
  end; 
end; 
 
//------------------------------------------------------------------------------ 
 
function DwmExtendFrameIntoClientArea(hWnd: HWND; const pMarInset: TMargins): HResult; 
begin 
  if Assigned(_DwmExtendFrameIntoClientArea) then 
    Result := _DwmExtendFrameIntoClientArea(hWnd, pMarInset) 
  else 
  begin 
    InitDwmApi; 
    Result := E_NOTIMPL; 
    if hDWMAPI > 0 then 
    begin 
      _DwmExtendFrameIntoClientArea := GetProcAddress(hDWMAPI, 'DwmExtendFrameIntoClientArea'); 
      if Assigned(_DwmExtendFrameIntoClientArea) then 
        Result := _DwmExtendFrameIntoClientArea(hWnd, pMarInset); 
    end; 
  end; 
end; 
 
//------------------------------------------------------------------------------ 
 
function DwmCompositionEnabled: Boolean; 
var 
  LEnabled: BOOL; 
begin 
  Result := (Win32MajorVersion >= 6) and (DwmIsCompositionEnabled(LEnabled) = S_OK) and LEnabled; 
end; 
 
//------------------------------------------------------------------------------ 
 
function DwmIsCompositionEnabled(out pfEnabled: BOOL): HResult; 
begin 
  if Assigned(_DwmIsCompositionEnabled) then 
    Result := _DwmIsCompositionEnabled(pfEnabled) 
  else 
  begin 
    InitDwmApi; 
    Result := E_NOTIMPL; 
    if hDWMAPI > 0 then 
    begin 
      _DwmIsCompositionEnabled := GetProcAddress(hDWMAPI, 'DwmIsCompositionEnabled'); 
      if Assigned(_DwmIsCompositionEnabled) then 
        Result := _DwmIsCompositionEnabled(pfEnabled); 
    end; 
  end; 
end; 
 
//------------------------------------------------------------------------------ 
 
initialization 
 
finalization 
  if hDWMAPI > 0 then 
    FreeLibrary(hDWMAPI); 
end.