Win32 API 日本語リファレンス
ホームDevices.Display › SetMonitorBrightness

SetMonitorBrightness

関数
モニタの輝度を新しい値に設定する。
DLLdxva2.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// dxva2.dll
#include <windows.h>

INT SetMonitorBrightness(
    HANDLE hMonitor,
    DWORD dwNewBrightness
);

パラメーター

名前方向
hMonitorHANDLEin
dwNewBrightnessDWORDin

戻り値の型: INT

各言語での呼び出し定義

// dxva2.dll
#include <windows.h>

INT SetMonitorBrightness(
    HANDLE hMonitor,
    DWORD dwNewBrightness
);
[DllImport("dxva2.dll", SetLastError = true, ExactSpelling = true)]
static extern int SetMonitorBrightness(
    IntPtr hMonitor,   // HANDLE
    uint dwNewBrightness   // DWORD
);
<DllImport("dxva2.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetMonitorBrightness(
    hMonitor As IntPtr,   ' HANDLE
    dwNewBrightness As UInteger   ' DWORD
) As Integer
End Function
' hMonitor : HANDLE
' dwNewBrightness : DWORD
Declare PtrSafe Function SetMonitorBrightness Lib "dxva2" ( _
    ByVal hMonitor As LongPtr, _
    ByVal dwNewBrightness As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetMonitorBrightness = ctypes.windll.dxva2.SetMonitorBrightness
SetMonitorBrightness.restype = ctypes.c_int
SetMonitorBrightness.argtypes = [
    wintypes.HANDLE,  # hMonitor : HANDLE
    wintypes.DWORD,  # dwNewBrightness : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('dxva2.dll')
SetMonitorBrightness = Fiddle::Function.new(
  lib['SetMonitorBrightness'],
  [
    Fiddle::TYPE_VOIDP,  # hMonitor : HANDLE
    -Fiddle::TYPE_INT,  # dwNewBrightness : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "dxva2")]
extern "system" {
    fn SetMonitorBrightness(
        hMonitor: *mut core::ffi::c_void,  // HANDLE
        dwNewBrightness: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("dxva2.dll", SetLastError = true)]
public static extern int SetMonitorBrightness(IntPtr hMonitor, uint dwNewBrightness);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dxva2_SetMonitorBrightness' -Namespace Win32 -PassThru
# $api::SetMonitorBrightness(hMonitor, dwNewBrightness)
#uselib "dxva2.dll"
#func global SetMonitorBrightness "SetMonitorBrightness" sptr, sptr
; SetMonitorBrightness hMonitor, dwNewBrightness   ; 戻り値は stat
; hMonitor : HANDLE -> "sptr"
; dwNewBrightness : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "dxva2.dll"
#cfunc global SetMonitorBrightness "SetMonitorBrightness" sptr, int
; res = SetMonitorBrightness(hMonitor, dwNewBrightness)
; hMonitor : HANDLE -> "sptr"
; dwNewBrightness : DWORD -> "int"
; INT SetMonitorBrightness(HANDLE hMonitor, DWORD dwNewBrightness)
#uselib "dxva2.dll"
#cfunc global SetMonitorBrightness "SetMonitorBrightness" intptr, int
; res = SetMonitorBrightness(hMonitor, dwNewBrightness)
; hMonitor : HANDLE -> "intptr"
; dwNewBrightness : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dxva2 = windows.NewLazySystemDLL("dxva2.dll")
	procSetMonitorBrightness = dxva2.NewProc("SetMonitorBrightness")
)

// hMonitor (HANDLE), dwNewBrightness (DWORD)
r1, _, err := procSetMonitorBrightness.Call(
	uintptr(hMonitor),
	uintptr(dwNewBrightness),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function SetMonitorBrightness(
  hMonitor: THandle;   // HANDLE
  dwNewBrightness: DWORD   // DWORD
): Integer; stdcall;
  external 'dxva2.dll' name 'SetMonitorBrightness';
result := DllCall("dxva2\SetMonitorBrightness"
    , "Ptr", hMonitor   ; HANDLE
    , "UInt", dwNewBrightness   ; DWORD
    , "Int")   ; return: INT
●SetMonitorBrightness(hMonitor, dwNewBrightness) = DLL("dxva2.dll", "int SetMonitorBrightness(void*, dword)")
# 呼び出し: SetMonitorBrightness(hMonitor, dwNewBrightness)
# hMonitor : HANDLE -> "void*"
# dwNewBrightness : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。