Win32 API 日本語リファレンス
ホームGraphics.Gdi › GetViewportExtEx

GetViewportExtEx

関数
DCのビューポートの範囲を取得する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL GetViewportExtEx(
    HDC hdc,
    SIZE* lpsize
);

パラメーター

名前方向説明
hdcHDCinデバイスコンテキストへのハンドル。
lpsizeSIZE*outx 方向および y 方向の範囲をデバイス単位で受け取る SIZE 構造体へのポインター。

戻り値の型: BOOL

公式ドキュメント

GetViewportExtEx 関数は、指定されたデバイスコンテキストの現在のビューポートの x 方向の範囲と y 方向の範囲を取得します。

戻り値

関数が成功した場合、戻り値は 0 以外の値です。

関数が失敗した場合、戻り値は 0 です。

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

各言語での呼び出し定義

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

BOOL GetViewportExtEx(
    HDC hdc,
    SIZE* lpsize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern bool GetViewportExtEx(
    IntPtr hdc,   // HDC
    IntPtr lpsize   // SIZE* out
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetViewportExtEx(
    hdc As IntPtr,   ' HDC
    lpsize As IntPtr   ' SIZE* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hdc : HDC
' lpsize : SIZE* out
Declare PtrSafe Function GetViewportExtEx Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal lpsize As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetViewportExtEx = ctypes.windll.gdi32.GetViewportExtEx
GetViewportExtEx.restype = wintypes.BOOL
GetViewportExtEx.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_void_p,  # lpsize : SIZE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
GetViewportExtEx = Fiddle::Function.new(
  lib['GetViewportExtEx'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # lpsize : SIZE* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn GetViewportExtEx(
        hdc: *mut core::ffi::c_void,  // HDC
        lpsize: *mut SIZE  // SIZE* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll")]
public static extern bool GetViewportExtEx(IntPtr hdc, IntPtr lpsize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetViewportExtEx' -Namespace Win32 -PassThru
# $api::GetViewportExtEx(hdc, lpsize)
#uselib "GDI32.dll"
#func global GetViewportExtEx "GetViewportExtEx" sptr, sptr
; GetViewportExtEx hdc, varptr(lpsize)   ; 戻り値は stat
; hdc : HDC -> "sptr"
; lpsize : SIZE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global GetViewportExtEx "GetViewportExtEx" sptr, var
; res = GetViewportExtEx(hdc, lpsize)
; hdc : HDC -> "sptr"
; lpsize : SIZE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetViewportExtEx(HDC hdc, SIZE* lpsize)
#uselib "GDI32.dll"
#cfunc global GetViewportExtEx "GetViewportExtEx" intptr, var
; res = GetViewportExtEx(hdc, lpsize)
; hdc : HDC -> "intptr"
; lpsize : SIZE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetViewportExtEx = gdi32.NewProc("GetViewportExtEx")
)

// hdc (HDC), lpsize (SIZE* out)
r1, _, err := procGetViewportExtEx.Call(
	uintptr(hdc),
	uintptr(lpsize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetViewportExtEx(
  hdc: THandle;   // HDC
  lpsize: Pointer   // SIZE* out
): BOOL; stdcall;
  external 'GDI32.dll' name 'GetViewportExtEx';
result := DllCall("GDI32\GetViewportExtEx"
    , "Ptr", hdc   ; HDC
    , "Ptr", lpsize   ; SIZE* out
    , "Int")   ; return: BOOL
●GetViewportExtEx(hdc, lpsize) = DLL("GDI32.dll", "bool GetViewportExtEx(void*, void*)")
# 呼び出し: GetViewportExtEx(hdc, lpsize)
# hdc : HDC -> "void*"
# lpsize : SIZE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef GetViewportExtExNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef GetViewportExtExDart = int Function(Pointer<Void>, Pointer<Void>);
final GetViewportExtEx = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<GetViewportExtExNative, GetViewportExtExDart>('GetViewportExtEx');
// hdc : HDC -> Pointer<Void>
// lpsize : SIZE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetViewportExtEx(
  hdc: THandle;   // HDC
  lpsize: Pointer   // SIZE* out
): BOOL; stdcall;
  external 'GDI32.dll' name 'GetViewportExtEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetViewportExtEx"
  c_GetViewportExtEx :: Ptr () -> Ptr () -> IO CInt
-- hdc : HDC -> Ptr ()
-- lpsize : SIZE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getviewportextex =
  foreign "GetViewportExtEx"
    ((ptr void) @-> (ptr void) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* lpsize : SIZE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("GetViewportExtEx" get-viewport-ext-ex :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (lpsize :pointer))   ; SIZE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetViewportExtEx = Win32::API::More->new('GDI32',
    'BOOL GetViewportExtEx(HANDLE hdc, LPVOID lpsize)');
# my $ret = $GetViewportExtEx->Call($hdc, $lpsize);
# hdc : HDC -> HANDLE
# lpsize : SIZE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型