ホーム › Graphics.Gdi › GetMonitorInfoA
GetMonitorInfoA
関数指定したモニタの情報を取得する(ANSI版)。
シグネチャ
// USER32.dll (ANSI / -A)
#include <windows.h>
BOOL GetMonitorInfoA(
HMONITOR hMonitor,
MONITORINFO* lpmi
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hMonitor | HMONITOR | in | 対象となるディスプレイ モニターへのハンドルです。 |
| lpmi | MONITORINFO* | inout | 指定したディスプレイ モニターに関する情報を受け取る MONITORINFO 構造体または MONITORINFOEX 構造体へのポインターです。 GetMonitorInfo 関数を呼び出す前に、構造体の cbSize メンバーに sizeof(MONITORINFO) または sizeof(MONITORINFOEX) を設定する必要があります。これにより、関数は渡される構造体の種類を判別できます。 MONITORINFOEX 構造体は MONITORINFO 構造体の上位互換であり、ディスプレイ モニターの名前を格納する文字列という追加のメンバーを 1 つ持ちます。ほとんどのアプリケーションはディスプレイ モニター名を必要としないため、MONITORINFO 構造体を使用することで数バイトを節約できます。 |
戻り値の型: BOOL
公式ドキュメント
GetMonitorInfo 関数は、ディスプレイ モニターに関する情報を取得します。(ANSI)
戻り値
関数が成功した場合、戻り値は 0 以外の値になります。
関数が失敗した場合、戻り値は 0 になります。
解説(Remarks)
メモ
winuser.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして GetMonitorInfo を定義します。エンコーディング中立のエイリアスを、エンコーディング中立でないコードと混在させて使用すると、不一致が生じてコンパイル エラーまたは実行時エラーの原因となる場合があります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll (ANSI / -A)
#include <windows.h>
BOOL GetMonitorInfoA(
HMONITOR hMonitor,
MONITORINFO* lpmi
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool GetMonitorInfoA(
IntPtr hMonitor, // HMONITOR
IntPtr lpmi // MONITORINFO* in/out
);<DllImport("USER32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetMonitorInfoA(
hMonitor As IntPtr, ' HMONITOR
lpmi As IntPtr ' MONITORINFO* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hMonitor : HMONITOR
' lpmi : MONITORINFO* in/out
Declare PtrSafe Function GetMonitorInfoA Lib "user32" ( _
ByVal hMonitor As LongPtr, _
ByVal lpmi As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetMonitorInfoA = ctypes.windll.user32.GetMonitorInfoA
GetMonitorInfoA.restype = wintypes.BOOL
GetMonitorInfoA.argtypes = [
wintypes.HANDLE, # hMonitor : HMONITOR
ctypes.c_void_p, # lpmi : MONITORINFO* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GetMonitorInfoA = Fiddle::Function.new(
lib['GetMonitorInfoA'],
[
Fiddle::TYPE_VOIDP, # hMonitor : HMONITOR
Fiddle::TYPE_VOIDP, # lpmi : MONITORINFO* in/out
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn GetMonitorInfoA(
hMonitor: *mut core::ffi::c_void, // HMONITOR
lpmi: *mut MONITORINFO // MONITORINFO* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Ansi)]
public static extern bool GetMonitorInfoA(IntPtr hMonitor, IntPtr lpmi);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetMonitorInfoA' -Namespace Win32 -PassThru
# $api::GetMonitorInfoA(hMonitor, lpmi)#uselib "USER32.dll"
#func global GetMonitorInfoA "GetMonitorInfoA" sptr, sptr
; GetMonitorInfoA hMonitor, varptr(lpmi) ; 戻り値は stat
; hMonitor : HMONITOR -> "sptr"
; lpmi : MONITORINFO* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global GetMonitorInfoA "GetMonitorInfoA" sptr, var ; res = GetMonitorInfoA(hMonitor, lpmi) ; hMonitor : HMONITOR -> "sptr" ; lpmi : MONITORINFO* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global GetMonitorInfoA "GetMonitorInfoA" sptr, sptr ; res = GetMonitorInfoA(hMonitor, varptr(lpmi)) ; hMonitor : HMONITOR -> "sptr" ; lpmi : MONITORINFO* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetMonitorInfoA(HMONITOR hMonitor, MONITORINFO* lpmi) #uselib "USER32.dll" #cfunc global GetMonitorInfoA "GetMonitorInfoA" intptr, var ; res = GetMonitorInfoA(hMonitor, lpmi) ; hMonitor : HMONITOR -> "intptr" ; lpmi : MONITORINFO* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetMonitorInfoA(HMONITOR hMonitor, MONITORINFO* lpmi) #uselib "USER32.dll" #cfunc global GetMonitorInfoA "GetMonitorInfoA" intptr, intptr ; res = GetMonitorInfoA(hMonitor, varptr(lpmi)) ; hMonitor : HMONITOR -> "intptr" ; lpmi : MONITORINFO* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGetMonitorInfoA = user32.NewProc("GetMonitorInfoA")
)
// hMonitor (HMONITOR), lpmi (MONITORINFO* in/out)
r1, _, err := procGetMonitorInfoA.Call(
uintptr(hMonitor),
uintptr(lpmi),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetMonitorInfoA(
hMonitor: THandle; // HMONITOR
lpmi: Pointer // MONITORINFO* in/out
): BOOL; stdcall;
external 'USER32.dll' name 'GetMonitorInfoA';result := DllCall("USER32\GetMonitorInfoA"
, "Ptr", hMonitor ; HMONITOR
, "Ptr", lpmi ; MONITORINFO* in/out
, "Int") ; return: BOOL●GetMonitorInfoA(hMonitor, lpmi) = DLL("USER32.dll", "bool GetMonitorInfoA(void*, void*)")
# 呼び出し: GetMonitorInfoA(hMonitor, lpmi)
# hMonitor : HMONITOR -> "void*"
# lpmi : MONITORINFO* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn GetMonitorInfoA(
hMonitor: ?*anyopaque, // HMONITOR
lpmi: [*c]MONITORINFO // MONITORINFO* in/out
) callconv(std.os.windows.WINAPI) i32;proc GetMonitorInfoA(
hMonitor: pointer, # HMONITOR
lpmi: ptr MONITORINFO # MONITORINFO* in/out
): int32 {.importc: "GetMonitorInfoA", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int GetMonitorInfoA(
void* hMonitor, // HMONITOR
MONITORINFO* lpmi // MONITORINFO* in/out
);ccall((:GetMonitorInfoA, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{MONITORINFO}),
hMonitor, lpmi)
# hMonitor : HMONITOR -> Ptr{Cvoid}
# lpmi : MONITORINFO* in/out -> Ptr{MONITORINFO}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetMonitorInfoA(
void* hMonitor,
void* lpmi);
]]
local user32 = ffi.load("user32")
-- user32.GetMonitorInfoA(hMonitor, lpmi)
-- hMonitor : HMONITOR
-- lpmi : MONITORINFO* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const GetMonitorInfoA = lib.func('__stdcall', 'GetMonitorInfoA', 'int32_t', ['void *', 'void *']);
// GetMonitorInfoA(hMonitor, lpmi)
// hMonitor : HMONITOR -> 'void *'
// lpmi : MONITORINFO* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
GetMonitorInfoA: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetMonitorInfoA(hMonitor, lpmi)
// hMonitor : HMONITOR -> "pointer"
// lpmi : MONITORINFO* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetMonitorInfoA(
void* hMonitor,
void* lpmi);
C, "USER32.dll");
// $ffi->GetMonitorInfoA(hMonitor, lpmi);
// hMonitor : HMONITOR
// lpmi : MONITORINFO* in/out
// 構造体/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 User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.ASCII_OPTIONS);
boolean GetMonitorInfoA(
Pointer hMonitor, // HMONITOR
Pointer lpmi // MONITORINFO* in/out
);
}@[Link("user32")]
lib LibUSER32
fun GetMonitorInfoA = GetMonitorInfoA(
hMonitor : Void*, # HMONITOR
lpmi : MONITORINFO* # MONITORINFO* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetMonitorInfoANative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef GetMonitorInfoADart = int Function(Pointer<Void>, Pointer<Void>);
final GetMonitorInfoA = DynamicLibrary.open('USER32.dll')
.lookupFunction<GetMonitorInfoANative, GetMonitorInfoADart>('GetMonitorInfoA');
// hMonitor : HMONITOR -> Pointer<Void>
// lpmi : MONITORINFO* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetMonitorInfoA(
hMonitor: THandle; // HMONITOR
lpmi: Pointer // MONITORINFO* in/out
): BOOL; stdcall;
external 'USER32.dll' name 'GetMonitorInfoA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetMonitorInfoA"
c_GetMonitorInfoA :: Ptr () -> Ptr () -> IO CInt
-- hMonitor : HMONITOR -> Ptr ()
-- lpmi : MONITORINFO* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getmonitorinfoa =
foreign "GetMonitorInfoA"
((ptr void) @-> (ptr void) @-> returning int32_t)
(* hMonitor : HMONITOR -> (ptr void) *)
(* lpmi : MONITORINFO* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("GetMonitorInfoA" get-monitor-info-a :convention :stdcall) :int32
(h-monitor :pointer) ; HMONITOR
(lpmi :pointer)) ; MONITORINFO* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetMonitorInfoA = Win32::API::More->new('USER32',
'BOOL GetMonitorInfoA(HANDLE hMonitor, LPVOID lpmi)');
# my $ret = $GetMonitorInfoA->Call($hMonitor, $lpmi);
# hMonitor : HMONITOR -> HANDLE
# lpmi : MONITORINFO* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f GetMonitorInfoW (Unicode版) — 指定したモニタの情報を取得する(Unicode版)。
公式の関連項目
使用する型