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

SetMonitorRedGreenOrBlueDrive

関数
モニタのRGBいずれかのドライブ値を設定する。
DLLdxva2.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

INT SetMonitorRedGreenOrBlueDrive(
    HANDLE hMonitor,
    MC_DRIVE_TYPE dtDriveType,
    DWORD dwNewDrive
);

パラメーター

名前方向説明
hMonitorHANDLEin物理モニターへのハンドル。モニターハンドルを取得するには、GetPhysicalMonitorsFromHMONITOR または GetPhysicalMonitorsFromIDirect3DDevice9 を呼び出します。
dtDriveTypeMC_DRIVE_TYPEinMC_DRIVE_TYPE 列挙体のメンバーで、赤、緑、青のいずれのドライブ値を設定するかを指定します。
dwNewDriveDWORDin赤、緑、または青のドライブ値。モニターの最小および最大のドライブ値を取得するには、GetMonitorRedGreenOrBlueDrive を呼び出します。

戻り値の型: INT

公式ドキュメント

モニターの赤、緑、または青のドライブ値を設定します。

戻り値

関数が成功した場合、戻り値は TRUE です。関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

ドライブ設定は、一般的にモニターのホワイトポイントを調整するために使用されます。Drive(ドライブ)と black level(ブラックレベル)は、同じモニター設定の異なる呼称です。

この関数がサポートされている場合、GetMonitorCapabilities 関数は MC_CAPS_RED_GREEN_BLUE_DRIVE フラグを返します。

この関数は、戻るまでに約 50 ミリ秒かかります。

ドライブ設定を変更すると、色温度が変化することがあります。新しい色温度を取得するには、GetMonitorColorTemperature を呼び出します。

ドライブ設定は連続的なモニター設定です。詳細については、Using the High-Level Monitor Configuration Functions を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

SetMonitorRedGreenOrBlueDrive = ctypes.windll.dxva2.SetMonitorRedGreenOrBlueDrive
SetMonitorRedGreenOrBlueDrive.restype = ctypes.c_int
SetMonitorRedGreenOrBlueDrive.argtypes = [
    wintypes.HANDLE,  # hMonitor : HANDLE
    ctypes.c_int,  # dtDriveType : MC_DRIVE_TYPE
    wintypes.DWORD,  # dwNewDrive : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dxva2 = windows.NewLazySystemDLL("dxva2.dll")
	procSetMonitorRedGreenOrBlueDrive = dxva2.NewProc("SetMonitorRedGreenOrBlueDrive")
)

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

extern "dxva2" fn SetMonitorRedGreenOrBlueDrive(
    hMonitor: ?*anyopaque, // HANDLE
    dtDriveType: i32, // MC_DRIVE_TYPE
    dwNewDrive: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SetMonitorRedGreenOrBlueDrive(
    hMonitor: pointer,  # HANDLE
    dtDriveType: int32,  # MC_DRIVE_TYPE
    dwNewDrive: uint32  # DWORD
): int32 {.importc: "SetMonitorRedGreenOrBlueDrive", stdcall, dynlib: "dxva2.dll".}
pragma(lib, "dxva2");
extern(Windows)
int SetMonitorRedGreenOrBlueDrive(
    void* hMonitor,   // HANDLE
    int dtDriveType,   // MC_DRIVE_TYPE
    uint dwNewDrive   // DWORD
);
ccall((:SetMonitorRedGreenOrBlueDrive, "dxva2.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, UInt32),
      hMonitor, dtDriveType, dwNewDrive)
# hMonitor : HANDLE -> Ptr{Cvoid}
# dtDriveType : MC_DRIVE_TYPE -> Int32
# dwNewDrive : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetMonitorRedGreenOrBlueDrive(
    void* hMonitor,
    int32_t dtDriveType,
    uint32_t dwNewDrive);
]]
local dxva2 = ffi.load("dxva2")
-- dxva2.SetMonitorRedGreenOrBlueDrive(hMonitor, dtDriveType, dwNewDrive)
-- hMonitor : HANDLE
-- dtDriveType : MC_DRIVE_TYPE
-- dwNewDrive : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('dxva2.dll');
const SetMonitorRedGreenOrBlueDrive = lib.func('__stdcall', 'SetMonitorRedGreenOrBlueDrive', 'int32_t', ['void *', 'int32_t', 'uint32_t']);
// SetMonitorRedGreenOrBlueDrive(hMonitor, dtDriveType, dwNewDrive)
// hMonitor : HANDLE -> 'void *'
// dtDriveType : MC_DRIVE_TYPE -> 'int32_t'
// dwNewDrive : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("dxva2.dll", {
  SetMonitorRedGreenOrBlueDrive: { parameters: ["pointer", "i32", "u32"], result: "i32" },
});
// lib.symbols.SetMonitorRedGreenOrBlueDrive(hMonitor, dtDriveType, dwNewDrive)
// hMonitor : HANDLE -> "pointer"
// dtDriveType : MC_DRIVE_TYPE -> "i32"
// dwNewDrive : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetMonitorRedGreenOrBlueDrive(
    void* hMonitor,
    int32_t dtDriveType,
    uint32_t dwNewDrive);
C, "dxva2.dll");
// $ffi->SetMonitorRedGreenOrBlueDrive(hMonitor, dtDriveType, dwNewDrive);
// hMonitor : HANDLE
// dtDriveType : MC_DRIVE_TYPE
// dwNewDrive : DWORD
// 構造体/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 Dxva2 extends StdCallLibrary {
    Dxva2 INSTANCE = Native.load("dxva2", Dxva2.class);
    int SetMonitorRedGreenOrBlueDrive(
        Pointer hMonitor,   // HANDLE
        int dtDriveType,   // MC_DRIVE_TYPE
        int dwNewDrive   // DWORD
    );
}
@[Link("dxva2")]
lib Libdxva2
  fun SetMonitorRedGreenOrBlueDrive = SetMonitorRedGreenOrBlueDrive(
    hMonitor : Void*,   # HANDLE
    dtDriveType : Int32,   # MC_DRIVE_TYPE
    dwNewDrive : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetMonitorRedGreenOrBlueDriveNative = Int32 Function(Pointer<Void>, Int32, Uint32);
typedef SetMonitorRedGreenOrBlueDriveDart = int Function(Pointer<Void>, int, int);
final SetMonitorRedGreenOrBlueDrive = DynamicLibrary.open('dxva2.dll')
    .lookupFunction<SetMonitorRedGreenOrBlueDriveNative, SetMonitorRedGreenOrBlueDriveDart>('SetMonitorRedGreenOrBlueDrive');
// hMonitor : HANDLE -> Pointer<Void>
// dtDriveType : MC_DRIVE_TYPE -> Int32
// dwNewDrive : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetMonitorRedGreenOrBlueDrive(
  hMonitor: THandle;   // HANDLE
  dtDriveType: Integer;   // MC_DRIVE_TYPE
  dwNewDrive: DWORD   // DWORD
): Integer; stdcall;
  external 'dxva2.dll' name 'SetMonitorRedGreenOrBlueDrive';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetMonitorRedGreenOrBlueDrive"
  c_SetMonitorRedGreenOrBlueDrive :: Ptr () -> Int32 -> Word32 -> IO Int32
-- hMonitor : HANDLE -> Ptr ()
-- dtDriveType : MC_DRIVE_TYPE -> Int32
-- dwNewDrive : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setmonitorredgreenorbluedrive =
  foreign "SetMonitorRedGreenOrBlueDrive"
    ((ptr void) @-> int32_t @-> uint32_t @-> returning int32_t)
(* hMonitor : HANDLE -> (ptr void) *)
(* dtDriveType : MC_DRIVE_TYPE -> int32_t *)
(* dwNewDrive : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dxva2 (t "dxva2.dll"))
(cffi:use-foreign-library dxva2)

(cffi:defcfun ("SetMonitorRedGreenOrBlueDrive" set-monitor-red-green-or-blue-drive :convention :stdcall) :int32
  (h-monitor :pointer)   ; HANDLE
  (dt-drive-type :int32)   ; MC_DRIVE_TYPE
  (dw-new-drive :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetMonitorRedGreenOrBlueDrive = Win32::API::More->new('dxva2',
    'int SetMonitorRedGreenOrBlueDrive(HANDLE hMonitor, int dtDriveType, DWORD dwNewDrive)');
# my $ret = $SetMonitorRedGreenOrBlueDrive->Call($hMonitor, $dtDriveType, $dwNewDrive);
# hMonitor : HANDLE -> HANDLE
# dtDriveType : MC_DRIVE_TYPE -> int
# dwNewDrive : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型