ホーム › Devices.Display › SetMonitorColorTemperature
SetMonitorColorTemperature
関数モニタの色温度を新しい値に設定する。
シグネチャ
// dxva2.dll
#include <windows.h>
INT SetMonitorColorTemperature(
HANDLE hMonitor,
MC_COLOR_TEMPERATURE ctCurrentColorTemperature
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hMonitor | HANDLE | in | 物理モニターへのハンドル。モニターハンドルを取得するには、GetPhysicalMonitorsFromHMONITOR または GetPhysicalMonitorsFromIDirect3DDevice9 を呼び出します。 |
| ctCurrentColorTemperature | MC_COLOR_TEMPERATURE | in | 色温度。MC_COLOR_TEMPERATURE 列挙型のメンバーとして指定します。 |
戻り値の型: INT
公式ドキュメント
モニターの色温度を設定します。
戻り値
関数が成功した場合、戻り値は TRUE です。関数が失敗した場合、戻り値は FALSE です。拡張エラー情報を取得するには、GetLastError を呼び出します。
解説(Remarks)
この関数がサポートされている場合、GetMonitorCapabilities 関数は MC_CAPS_COLOR_TEMPERATURE フラグを返します。GetMonitorCapabilities 関数は、モニターがサポートする色温度の範囲も返します。ctCurrentColorTemperature パラメーターは、これらの値のいずれかに対応している必要があります。
色温度を変更すると、モニターのホワイトポイントが変化します。また、現在のドライブおよびゲインの設定も変化する場合があります。新しいドライブおよびゲインの設定を取得するには、それぞれ GetMonitorRedGreenOrBlueDrive および GetMonitorRedGreenOrBlueGain を呼び出します。
この関数が戻るまでに 50 ~ 90 ミリ秒かかります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// dxva2.dll
#include <windows.h>
INT SetMonitorColorTemperature(
HANDLE hMonitor,
MC_COLOR_TEMPERATURE ctCurrentColorTemperature
);[DllImport("dxva2.dll", SetLastError = true, ExactSpelling = true)]
static extern int SetMonitorColorTemperature(
IntPtr hMonitor, // HANDLE
int ctCurrentColorTemperature // MC_COLOR_TEMPERATURE
);<DllImport("dxva2.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetMonitorColorTemperature(
hMonitor As IntPtr, ' HANDLE
ctCurrentColorTemperature As Integer ' MC_COLOR_TEMPERATURE
) As Integer
End Function' hMonitor : HANDLE
' ctCurrentColorTemperature : MC_COLOR_TEMPERATURE
Declare PtrSafe Function SetMonitorColorTemperature Lib "dxva2" ( _
ByVal hMonitor As LongPtr, _
ByVal ctCurrentColorTemperature As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetMonitorColorTemperature = ctypes.windll.dxva2.SetMonitorColorTemperature
SetMonitorColorTemperature.restype = ctypes.c_int
SetMonitorColorTemperature.argtypes = [
wintypes.HANDLE, # hMonitor : HANDLE
ctypes.c_int, # ctCurrentColorTemperature : MC_COLOR_TEMPERATURE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('dxva2.dll')
SetMonitorColorTemperature = Fiddle::Function.new(
lib['SetMonitorColorTemperature'],
[
Fiddle::TYPE_VOIDP, # hMonitor : HANDLE
Fiddle::TYPE_INT, # ctCurrentColorTemperature : MC_COLOR_TEMPERATURE
],
Fiddle::TYPE_INT)#[link(name = "dxva2")]
extern "system" {
fn SetMonitorColorTemperature(
hMonitor: *mut core::ffi::c_void, // HANDLE
ctCurrentColorTemperature: i32 // MC_COLOR_TEMPERATURE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("dxva2.dll", SetLastError = true)]
public static extern int SetMonitorColorTemperature(IntPtr hMonitor, int ctCurrentColorTemperature);
"@
$api = Add-Type -MemberDefinition $sig -Name 'dxva2_SetMonitorColorTemperature' -Namespace Win32 -PassThru
# $api::SetMonitorColorTemperature(hMonitor, ctCurrentColorTemperature)#uselib "dxva2.dll"
#func global SetMonitorColorTemperature "SetMonitorColorTemperature" sptr, sptr
; SetMonitorColorTemperature hMonitor, ctCurrentColorTemperature ; 戻り値は stat
; hMonitor : HANDLE -> "sptr"
; ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "dxva2.dll"
#cfunc global SetMonitorColorTemperature "SetMonitorColorTemperature" sptr, int
; res = SetMonitorColorTemperature(hMonitor, ctCurrentColorTemperature)
; hMonitor : HANDLE -> "sptr"
; ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> "int"; INT SetMonitorColorTemperature(HANDLE hMonitor, MC_COLOR_TEMPERATURE ctCurrentColorTemperature)
#uselib "dxva2.dll"
#cfunc global SetMonitorColorTemperature "SetMonitorColorTemperature" intptr, int
; res = SetMonitorColorTemperature(hMonitor, ctCurrentColorTemperature)
; hMonitor : HANDLE -> "intptr"
; ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dxva2 = windows.NewLazySystemDLL("dxva2.dll")
procSetMonitorColorTemperature = dxva2.NewProc("SetMonitorColorTemperature")
)
// hMonitor (HANDLE), ctCurrentColorTemperature (MC_COLOR_TEMPERATURE)
r1, _, err := procSetMonitorColorTemperature.Call(
uintptr(hMonitor),
uintptr(ctCurrentColorTemperature),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SetMonitorColorTemperature(
hMonitor: THandle; // HANDLE
ctCurrentColorTemperature: Integer // MC_COLOR_TEMPERATURE
): Integer; stdcall;
external 'dxva2.dll' name 'SetMonitorColorTemperature';result := DllCall("dxva2\SetMonitorColorTemperature"
, "Ptr", hMonitor ; HANDLE
, "Int", ctCurrentColorTemperature ; MC_COLOR_TEMPERATURE
, "Int") ; return: INT●SetMonitorColorTemperature(hMonitor, ctCurrentColorTemperature) = DLL("dxva2.dll", "int SetMonitorColorTemperature(void*, int)")
# 呼び出し: SetMonitorColorTemperature(hMonitor, ctCurrentColorTemperature)
# hMonitor : HANDLE -> "void*"
# ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "dxva2" fn SetMonitorColorTemperature(
hMonitor: ?*anyopaque, // HANDLE
ctCurrentColorTemperature: i32 // MC_COLOR_TEMPERATURE
) callconv(std.os.windows.WINAPI) i32;proc SetMonitorColorTemperature(
hMonitor: pointer, # HANDLE
ctCurrentColorTemperature: int32 # MC_COLOR_TEMPERATURE
): int32 {.importc: "SetMonitorColorTemperature", stdcall, dynlib: "dxva2.dll".}pragma(lib, "dxva2");
extern(Windows)
int SetMonitorColorTemperature(
void* hMonitor, // HANDLE
int ctCurrentColorTemperature // MC_COLOR_TEMPERATURE
);ccall((:SetMonitorColorTemperature, "dxva2.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32),
hMonitor, ctCurrentColorTemperature)
# hMonitor : HANDLE -> Ptr{Cvoid}
# ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetMonitorColorTemperature(
void* hMonitor,
int32_t ctCurrentColorTemperature);
]]
local dxva2 = ffi.load("dxva2")
-- dxva2.SetMonitorColorTemperature(hMonitor, ctCurrentColorTemperature)
-- hMonitor : HANDLE
-- ctCurrentColorTemperature : MC_COLOR_TEMPERATURE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('dxva2.dll');
const SetMonitorColorTemperature = lib.func('__stdcall', 'SetMonitorColorTemperature', 'int32_t', ['void *', 'int32_t']);
// SetMonitorColorTemperature(hMonitor, ctCurrentColorTemperature)
// hMonitor : HANDLE -> 'void *'
// ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("dxva2.dll", {
SetMonitorColorTemperature: { parameters: ["pointer", "i32"], result: "i32" },
});
// lib.symbols.SetMonitorColorTemperature(hMonitor, ctCurrentColorTemperature)
// hMonitor : HANDLE -> "pointer"
// ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetMonitorColorTemperature(
void* hMonitor,
int32_t ctCurrentColorTemperature);
C, "dxva2.dll");
// $ffi->SetMonitorColorTemperature(hMonitor, ctCurrentColorTemperature);
// hMonitor : HANDLE
// ctCurrentColorTemperature : MC_COLOR_TEMPERATURE
// 構造体/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 SetMonitorColorTemperature(
Pointer hMonitor, // HANDLE
int ctCurrentColorTemperature // MC_COLOR_TEMPERATURE
);
}@[Link("dxva2")]
lib Libdxva2
fun SetMonitorColorTemperature = SetMonitorColorTemperature(
hMonitor : Void*, # HANDLE
ctCurrentColorTemperature : Int32 # MC_COLOR_TEMPERATURE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetMonitorColorTemperatureNative = Int32 Function(Pointer<Void>, Int32);
typedef SetMonitorColorTemperatureDart = int Function(Pointer<Void>, int);
final SetMonitorColorTemperature = DynamicLibrary.open('dxva2.dll')
.lookupFunction<SetMonitorColorTemperatureNative, SetMonitorColorTemperatureDart>('SetMonitorColorTemperature');
// hMonitor : HANDLE -> Pointer<Void>
// ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetMonitorColorTemperature(
hMonitor: THandle; // HANDLE
ctCurrentColorTemperature: Integer // MC_COLOR_TEMPERATURE
): Integer; stdcall;
external 'dxva2.dll' name 'SetMonitorColorTemperature';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetMonitorColorTemperature"
c_SetMonitorColorTemperature :: Ptr () -> Int32 -> IO Int32
-- hMonitor : HANDLE -> Ptr ()
-- ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setmonitorcolortemperature =
foreign "SetMonitorColorTemperature"
((ptr void) @-> int32_t @-> returning int32_t)
(* hMonitor : HANDLE -> (ptr void) *)
(* ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library dxva2 (t "dxva2.dll"))
(cffi:use-foreign-library dxva2)
(cffi:defcfun ("SetMonitorColorTemperature" set-monitor-color-temperature :convention :stdcall) :int32
(h-monitor :pointer) ; HANDLE
(ct-current-color-temperature :int32)) ; MC_COLOR_TEMPERATURE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetMonitorColorTemperature = Win32::API::More->new('dxva2',
'int SetMonitorColorTemperature(HANDLE hMonitor, int ctCurrentColorTemperature)');
# my $ret = $SetMonitorColorTemperature->Call($hMonitor, $ctCurrentColorTemperature);
# hMonitor : HANDLE -> HANDLE
# ctCurrentColorTemperature : MC_COLOR_TEMPERATURE -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。