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

SetMonitorRedGreenOrBlueGain

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

シグネチャ

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

INT SetMonitorRedGreenOrBlueGain(
    HANDLE hMonitor,
    MC_GAIN_TYPE gtGainType,
    DWORD dwNewGain
);

パラメーター

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

戻り値の型: INT

公式ドキュメント

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

戻り値

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

解説(Remarks)

ゲイン設定は通常、モニターのホワイトポイントを調整するために使用されます。

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

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

ゲイン設定を変更すると、色温度が変化する場合があります。新しい色温度を取得するには、GetMonitorColorTemperature を呼び出します。

ゲイン設定は連続的なモニター設定です。詳細については、高レベルモニター構成関数の使用を参照してください。

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

各言語での呼び出し定義

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

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

SetMonitorRedGreenOrBlueGain = ctypes.windll.dxva2.SetMonitorRedGreenOrBlueGain
SetMonitorRedGreenOrBlueGain.restype = ctypes.c_int
SetMonitorRedGreenOrBlueGain.argtypes = [
    wintypes.HANDLE,  # hMonitor : HANDLE
    ctypes.c_int,  # gtGainType : MC_GAIN_TYPE
    wintypes.DWORD,  # dwNewGain : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dxva2 = windows.NewLazySystemDLL("dxva2.dll")
	procSetMonitorRedGreenOrBlueGain = dxva2.NewProc("SetMonitorRedGreenOrBlueGain")
)

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

extern "dxva2" fn SetMonitorRedGreenOrBlueGain(
    hMonitor: ?*anyopaque, // HANDLE
    gtGainType: i32, // MC_GAIN_TYPE
    dwNewGain: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SetMonitorRedGreenOrBlueGain(
    hMonitor: pointer,  # HANDLE
    gtGainType: int32,  # MC_GAIN_TYPE
    dwNewGain: uint32  # DWORD
): int32 {.importc: "SetMonitorRedGreenOrBlueGain", stdcall, dynlib: "dxva2.dll".}
pragma(lib, "dxva2");
extern(Windows)
int SetMonitorRedGreenOrBlueGain(
    void* hMonitor,   // HANDLE
    int gtGainType,   // MC_GAIN_TYPE
    uint dwNewGain   // DWORD
);
ccall((:SetMonitorRedGreenOrBlueGain, "dxva2.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, UInt32),
      hMonitor, gtGainType, dwNewGain)
# hMonitor : HANDLE -> Ptr{Cvoid}
# gtGainType : MC_GAIN_TYPE -> Int32
# dwNewGain : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetMonitorRedGreenOrBlueGain(
    void* hMonitor,
    int32_t gtGainType,
    uint32_t dwNewGain);
]]
local dxva2 = ffi.load("dxva2")
-- dxva2.SetMonitorRedGreenOrBlueGain(hMonitor, gtGainType, dwNewGain)
-- hMonitor : HANDLE
-- gtGainType : MC_GAIN_TYPE
-- dwNewGain : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('dxva2.dll');
const SetMonitorRedGreenOrBlueGain = lib.func('__stdcall', 'SetMonitorRedGreenOrBlueGain', 'int32_t', ['void *', 'int32_t', 'uint32_t']);
// SetMonitorRedGreenOrBlueGain(hMonitor, gtGainType, dwNewGain)
// hMonitor : HANDLE -> 'void *'
// gtGainType : MC_GAIN_TYPE -> 'int32_t'
// dwNewGain : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("dxva2.dll", {
  SetMonitorRedGreenOrBlueGain: { parameters: ["pointer", "i32", "u32"], result: "i32" },
});
// lib.symbols.SetMonitorRedGreenOrBlueGain(hMonitor, gtGainType, dwNewGain)
// hMonitor : HANDLE -> "pointer"
// gtGainType : MC_GAIN_TYPE -> "i32"
// dwNewGain : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetMonitorRedGreenOrBlueGain(
    void* hMonitor,
    int32_t gtGainType,
    uint32_t dwNewGain);
C, "dxva2.dll");
// $ffi->SetMonitorRedGreenOrBlueGain(hMonitor, gtGainType, dwNewGain);
// hMonitor : HANDLE
// gtGainType : MC_GAIN_TYPE
// dwNewGain : 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 SetMonitorRedGreenOrBlueGain(
        Pointer hMonitor,   // HANDLE
        int gtGainType,   // MC_GAIN_TYPE
        int dwNewGain   // DWORD
    );
}
@[Link("dxva2")]
lib Libdxva2
  fun SetMonitorRedGreenOrBlueGain = SetMonitorRedGreenOrBlueGain(
    hMonitor : Void*,   # HANDLE
    gtGainType : Int32,   # MC_GAIN_TYPE
    dwNewGain : 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 SetMonitorRedGreenOrBlueGainNative = Int32 Function(Pointer<Void>, Int32, Uint32);
typedef SetMonitorRedGreenOrBlueGainDart = int Function(Pointer<Void>, int, int);
final SetMonitorRedGreenOrBlueGain = DynamicLibrary.open('dxva2.dll')
    .lookupFunction<SetMonitorRedGreenOrBlueGainNative, SetMonitorRedGreenOrBlueGainDart>('SetMonitorRedGreenOrBlueGain');
// hMonitor : HANDLE -> Pointer<Void>
// gtGainType : MC_GAIN_TYPE -> Int32
// dwNewGain : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetMonitorRedGreenOrBlueGain(
  hMonitor: THandle;   // HANDLE
  gtGainType: Integer;   // MC_GAIN_TYPE
  dwNewGain: DWORD   // DWORD
): Integer; stdcall;
  external 'dxva2.dll' name 'SetMonitorRedGreenOrBlueGain';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let setmonitorredgreenorbluegain =
  foreign "SetMonitorRedGreenOrBlueGain"
    ((ptr void) @-> int32_t @-> uint32_t @-> returning int32_t)
(* hMonitor : HANDLE -> (ptr void) *)
(* gtGainType : MC_GAIN_TYPE -> int32_t *)
(* dwNewGain : 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 ("SetMonitorRedGreenOrBlueGain" set-monitor-red-green-or-blue-gain :convention :stdcall) :int32
  (h-monitor :pointer)   ; HANDLE
  (gt-gain-type :int32)   ; MC_GAIN_TYPE
  (dw-new-gain :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetMonitorRedGreenOrBlueGain = Win32::API::More->new('dxva2',
    'int SetMonitorRedGreenOrBlueGain(HANDLE hMonitor, int gtGainType, DWORD dwNewGain)');
# my $ret = $SetMonitorRedGreenOrBlueGain->Call($hMonitor, $gtGainType, $dwNewGain);
# hMonitor : HANDLE -> HANDLE
# gtGainType : MC_GAIN_TYPE -> int
# dwNewGain : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型