DwmEnableBlurBehindWindow
関数シグネチャ
// dwmapi.dll
#include <windows.h>
HRESULT DwmEnableBlurBehindWindow(
HWND hWnd,
const DWM_BLURBEHIND* pBlurBehind
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | blur-behind データを適用するウィンドウのハンドル。 |
| pBlurBehind | DWM_BLURBEHIND* | in | blur-behind データを提供する DWM_BLURBEHIND 構造体へのポインター。 |
戻り値の型: HRESULT
公式ドキュメント
指定したウィンドウでぼかし効果を有効にします。
戻り値
この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。
解説(Remarks)
Windows 8 以降では、ウィンドウの描画方法に関するスタイルの変更により、この関数を呼び出してもぼかし効果は適用されません。
ぼかしを有効にするには、DWM_BLURBEHIND 構造体の fEnable メンバーを TRUE に設定します。これにより、以降のウィンドウの合成では、その背後にあるコンテンツがぼかされます。効果を速やかに適用するため、この関数は BeginPaint の呼び出しの直前に呼び出してください。
ウィンドウ内のアルファ値は尊重され、ぼかしの上に行われる描画ではこれらのアルファ値が使用されます。ウィンドウ内のすべてのピクセルのアルファ値が正しいことを保証するのは、アプリケーションの責任です。一部の Windows Graphics Device Interface (GDI) の操作はアルファ値を保持しないため、子ウィンドウを表示する際は注意してください。子ウィンドウが与えるアルファ値は予測できません。
DWM_BLURBEHIND 構造体で指定したリージョンは、呼び出し元が所有します。リージョンを解放するのは呼び出し元の責任であり、関数の呼び出しが完了した時点で解放できます。
この関数はトップレベルウィンドウに対してのみ呼び出すことができます。それ以外の種類のウィンドウに対して呼び出すとエラーが発生します。
この関数は、デスクトップ ウィンドウ マネージャー (DWM) による合成が切り替わるたびに呼び出す必要があります。合成の変更通知を受け取るには、WM_DWMCOMPOSITIONCHANGED メッセージを処理してください。
例
次の例は、ウィンドウ全体にぼかしを適用する方法を示しています。
HRESULT EnableBlurBehind(HWND hwnd)
{
HRESULT hr = S_OK;
// Blur Behind 構造体を作成して値を設定する
DWM_BLURBEHIND bb = {0};
// Blur Behind を有効にし、クライアント領域全体に適用する
bb.dwFlags = DWM_BB_ENABLE;
bb.fEnable = true;
bb.hRgnBlur = NULL;
// Blur Behind を適用する
hr = DwmEnableBlurBehindWindow(hwnd, &bb);
if (SUCCEEDED(hr))
{
// ...
}
return hr;
}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// dwmapi.dll
#include <windows.h>
HRESULT DwmEnableBlurBehindWindow(
HWND hWnd,
const DWM_BLURBEHIND* pBlurBehind
);[DllImport("dwmapi.dll", ExactSpelling = true)]
static extern int DwmEnableBlurBehindWindow(
IntPtr hWnd, // HWND
IntPtr pBlurBehind // DWM_BLURBEHIND*
);<DllImport("dwmapi.dll", ExactSpelling:=True)>
Public Shared Function DwmEnableBlurBehindWindow(
hWnd As IntPtr, ' HWND
pBlurBehind As IntPtr ' DWM_BLURBEHIND*
) As Integer
End Function' hWnd : HWND
' pBlurBehind : DWM_BLURBEHIND*
Declare PtrSafe Function DwmEnableBlurBehindWindow Lib "dwmapi" ( _
ByVal hWnd As LongPtr, _
ByVal pBlurBehind As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DwmEnableBlurBehindWindow = ctypes.windll.dwmapi.DwmEnableBlurBehindWindow
DwmEnableBlurBehindWindow.restype = ctypes.c_int
DwmEnableBlurBehindWindow.argtypes = [
wintypes.HANDLE, # hWnd : HWND
ctypes.c_void_p, # pBlurBehind : DWM_BLURBEHIND*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('dwmapi.dll')
DwmEnableBlurBehindWindow = Fiddle::Function.new(
lib['DwmEnableBlurBehindWindow'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
Fiddle::TYPE_VOIDP, # pBlurBehind : DWM_BLURBEHIND*
],
Fiddle::TYPE_INT)#[link(name = "dwmapi")]
extern "system" {
fn DwmEnableBlurBehindWindow(
hWnd: *mut core::ffi::c_void, // HWND
pBlurBehind: *const DWM_BLURBEHIND // DWM_BLURBEHIND*
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("dwmapi.dll")]
public static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, IntPtr pBlurBehind);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dwmapi_DwmEnableBlurBehindWindow' -Namespace Win32 -PassThru
# $api::DwmEnableBlurBehindWindow(hWnd, pBlurBehind)#uselib "dwmapi.dll"
#func global DwmEnableBlurBehindWindow "DwmEnableBlurBehindWindow" sptr, sptr
; DwmEnableBlurBehindWindow hWnd, varptr(pBlurBehind) ; 戻り値は stat
; hWnd : HWND -> "sptr"
; pBlurBehind : DWM_BLURBEHIND* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "dwmapi.dll" #cfunc global DwmEnableBlurBehindWindow "DwmEnableBlurBehindWindow" sptr, var ; res = DwmEnableBlurBehindWindow(hWnd, pBlurBehind) ; hWnd : HWND -> "sptr" ; pBlurBehind : DWM_BLURBEHIND* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "dwmapi.dll" #cfunc global DwmEnableBlurBehindWindow "DwmEnableBlurBehindWindow" sptr, sptr ; res = DwmEnableBlurBehindWindow(hWnd, varptr(pBlurBehind)) ; hWnd : HWND -> "sptr" ; pBlurBehind : DWM_BLURBEHIND* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; HRESULT DwmEnableBlurBehindWindow(HWND hWnd, DWM_BLURBEHIND* pBlurBehind) #uselib "dwmapi.dll" #cfunc global DwmEnableBlurBehindWindow "DwmEnableBlurBehindWindow" intptr, var ; res = DwmEnableBlurBehindWindow(hWnd, pBlurBehind) ; hWnd : HWND -> "intptr" ; pBlurBehind : DWM_BLURBEHIND* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT DwmEnableBlurBehindWindow(HWND hWnd, DWM_BLURBEHIND* pBlurBehind) #uselib "dwmapi.dll" #cfunc global DwmEnableBlurBehindWindow "DwmEnableBlurBehindWindow" intptr, intptr ; res = DwmEnableBlurBehindWindow(hWnd, varptr(pBlurBehind)) ; hWnd : HWND -> "intptr" ; pBlurBehind : DWM_BLURBEHIND* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dwmapi = windows.NewLazySystemDLL("dwmapi.dll")
procDwmEnableBlurBehindWindow = dwmapi.NewProc("DwmEnableBlurBehindWindow")
)
// hWnd (HWND), pBlurBehind (DWM_BLURBEHIND*)
r1, _, err := procDwmEnableBlurBehindWindow.Call(
uintptr(hWnd),
uintptr(pBlurBehind),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction DwmEnableBlurBehindWindow(
hWnd: THandle; // HWND
pBlurBehind: Pointer // DWM_BLURBEHIND*
): Integer; stdcall;
external 'dwmapi.dll' name 'DwmEnableBlurBehindWindow';result := DllCall("dwmapi\DwmEnableBlurBehindWindow"
, "Ptr", hWnd ; HWND
, "Ptr", pBlurBehind ; DWM_BLURBEHIND*
, "Int") ; return: HRESULT●DwmEnableBlurBehindWindow(hWnd, pBlurBehind) = DLL("dwmapi.dll", "int DwmEnableBlurBehindWindow(void*, void*)")
# 呼び出し: DwmEnableBlurBehindWindow(hWnd, pBlurBehind)
# hWnd : HWND -> "void*"
# pBlurBehind : DWM_BLURBEHIND* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "dwmapi" fn DwmEnableBlurBehindWindow(
hWnd: ?*anyopaque, // HWND
pBlurBehind: [*c]DWM_BLURBEHIND // DWM_BLURBEHIND*
) callconv(std.os.windows.WINAPI) i32;proc DwmEnableBlurBehindWindow(
hWnd: pointer, # HWND
pBlurBehind: ptr DWM_BLURBEHIND # DWM_BLURBEHIND*
): int32 {.importc: "DwmEnableBlurBehindWindow", stdcall, dynlib: "dwmapi.dll".}pragma(lib, "dwmapi");
extern(Windows)
int DwmEnableBlurBehindWindow(
void* hWnd, // HWND
DWM_BLURBEHIND* pBlurBehind // DWM_BLURBEHIND*
);ccall((:DwmEnableBlurBehindWindow, "dwmapi.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{DWM_BLURBEHIND}),
hWnd, pBlurBehind)
# hWnd : HWND -> Ptr{Cvoid}
# pBlurBehind : DWM_BLURBEHIND* -> Ptr{DWM_BLURBEHIND}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t DwmEnableBlurBehindWindow(
void* hWnd,
void* pBlurBehind);
]]
local dwmapi = ffi.load("dwmapi")
-- dwmapi.DwmEnableBlurBehindWindow(hWnd, pBlurBehind)
-- hWnd : HWND
-- pBlurBehind : DWM_BLURBEHIND*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('dwmapi.dll');
const DwmEnableBlurBehindWindow = lib.func('__stdcall', 'DwmEnableBlurBehindWindow', 'int32_t', ['void *', 'void *']);
// DwmEnableBlurBehindWindow(hWnd, pBlurBehind)
// hWnd : HWND -> 'void *'
// pBlurBehind : DWM_BLURBEHIND* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("dwmapi.dll", {
DwmEnableBlurBehindWindow: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.DwmEnableBlurBehindWindow(hWnd, pBlurBehind)
// hWnd : HWND -> "pointer"
// pBlurBehind : DWM_BLURBEHIND* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t DwmEnableBlurBehindWindow(
void* hWnd,
void* pBlurBehind);
C, "dwmapi.dll");
// $ffi->DwmEnableBlurBehindWindow(hWnd, pBlurBehind);
// hWnd : HWND
// pBlurBehind : DWM_BLURBEHIND*
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Dwmapi extends StdCallLibrary {
Dwmapi INSTANCE = Native.load("dwmapi", Dwmapi.class);
int DwmEnableBlurBehindWindow(
Pointer hWnd, // HWND
Pointer pBlurBehind // DWM_BLURBEHIND*
);
}@[Link("dwmapi")]
lib Libdwmapi
fun DwmEnableBlurBehindWindow = DwmEnableBlurBehindWindow(
hWnd : Void*, # HWND
pBlurBehind : DWM_BLURBEHIND* # DWM_BLURBEHIND*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DwmEnableBlurBehindWindowNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef DwmEnableBlurBehindWindowDart = int Function(Pointer<Void>, Pointer<Void>);
final DwmEnableBlurBehindWindow = DynamicLibrary.open('dwmapi.dll')
.lookupFunction<DwmEnableBlurBehindWindowNative, DwmEnableBlurBehindWindowDart>('DwmEnableBlurBehindWindow');
// hWnd : HWND -> Pointer<Void>
// pBlurBehind : DWM_BLURBEHIND* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DwmEnableBlurBehindWindow(
hWnd: THandle; // HWND
pBlurBehind: Pointer // DWM_BLURBEHIND*
): Integer; stdcall;
external 'dwmapi.dll' name 'DwmEnableBlurBehindWindow';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DwmEnableBlurBehindWindow"
c_DwmEnableBlurBehindWindow :: Ptr () -> Ptr () -> IO Int32
-- hWnd : HWND -> Ptr ()
-- pBlurBehind : DWM_BLURBEHIND* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dwmenableblurbehindwindow =
foreign "DwmEnableBlurBehindWindow"
((ptr void) @-> (ptr void) @-> returning int32_t)
(* hWnd : HWND -> (ptr void) *)
(* pBlurBehind : DWM_BLURBEHIND* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dwmapi (t "dwmapi.dll"))
(cffi:use-foreign-library dwmapi)
(cffi:defcfun ("DwmEnableBlurBehindWindow" dwm-enable-blur-behind-window :convention :stdcall) :int32
(h-wnd :pointer) ; HWND
(p-blur-behind :pointer)) ; DWM_BLURBEHIND*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DwmEnableBlurBehindWindow = Win32::API::More->new('dwmapi',
'int DwmEnableBlurBehindWindow(HANDLE hWnd, LPVOID pBlurBehind)');
# my $ret = $DwmEnableBlurBehindWindow->Call($hWnd, $pBlurBehind);
# hWnd : HWND -> HANDLE
# pBlurBehind : DWM_BLURBEHIND* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。