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

SetMonitorDisplayAreaPosition

関数
モニタの表示領域の位置を設定する。
DLLdxva2.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

INT SetMonitorDisplayAreaPosition(
    HANDLE hMonitor,
    MC_POSITION_TYPE ptPositionType,
    DWORD dwNewPosition
);

パラメーター

名前方向説明
hMonitorHANDLEin物理モニターへのハンドル。モニターハンドルを取得するには、GetPhysicalMonitorsFromHMONITOR または GetPhysicalMonitorsFromIDirect3DDevice9 を呼び出します。
ptPositionTypeMC_POSITION_TYPEinMC_POSITION_TYPE 列挙体のメンバーで、水平方向の位置を設定するか垂直方向の位置を設定するかを指定します。
dwNewPositionDWORDin水平方向または垂直方向の位置。位置の最小値と最大値を取得するには、GetMonitorDisplayAreaPosition を呼び出します。

戻り値の型: INT

公式ドキュメント

モニターの表示領域の水平方向または垂直方向の位置を設定します。

戻り値

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

解説(Remarks)

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

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

水平方向および垂直方向の位置は連続的なモニター設定です。詳細については、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 SetMonitorDisplayAreaPosition(
    HANDLE hMonitor,
    MC_POSITION_TYPE ptPositionType,
    DWORD dwNewPosition
);
[DllImport("dxva2.dll", SetLastError = true, ExactSpelling = true)]
static extern int SetMonitorDisplayAreaPosition(
    IntPtr hMonitor,   // HANDLE
    int ptPositionType,   // MC_POSITION_TYPE
    uint dwNewPosition   // DWORD
);
<DllImport("dxva2.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetMonitorDisplayAreaPosition(
    hMonitor As IntPtr,   ' HANDLE
    ptPositionType As Integer,   ' MC_POSITION_TYPE
    dwNewPosition As UInteger   ' DWORD
) As Integer
End Function
' hMonitor : HANDLE
' ptPositionType : MC_POSITION_TYPE
' dwNewPosition : DWORD
Declare PtrSafe Function SetMonitorDisplayAreaPosition Lib "dxva2" ( _
    ByVal hMonitor As LongPtr, _
    ByVal ptPositionType As Long, _
    ByVal dwNewPosition As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	dxva2 = windows.NewLazySystemDLL("dxva2.dll")
	procSetMonitorDisplayAreaPosition = dxva2.NewProc("SetMonitorDisplayAreaPosition")
)

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

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

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

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

関連項目

使用する型