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

ScaleViewportExtEx

関数
ビューポートの範囲を比率で拡大縮小する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL ScaleViewportExtEx(
    HDC hdc,
    INT xn,
    INT dx,
    INT yn,
    INT yd,
    SIZE* lpsz   // optional
);

パラメーター

名前方向説明
hdcHDCinデバイスコンテキストへのハンドルです。
xnINTin現在の水平方向のエクステントに乗算する値です。
dxINTin現在の水平方向のエクステントを除算する値です。
ynINTin現在の垂直方向のエクステントに乗算する値です。
ydINTin現在の垂直方向のエクステントを除算する値です。
lpszSIZE*outoptional以前のビューポートのエクステント(デバイス単位)を受け取る SIZE 構造体へのポインターです。lpSizeNULL の場合、このパラメーターは使用されません。

戻り値の型: BOOL

公式ドキュメント

ScaleViewportExtEx 関数は、指定された被乗数と除数から求められる比率を使用して、デバイスコンテキストのビューポートを変更します。

戻り値

関数が成功すると、戻り値は 0 以外の値になります。

関数が失敗すると、戻り値は 0 になります。

解説(Remarks)

ビューポートのエクステントは次のように変更されます。


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

各言語での呼び出し定義

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

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

ScaleViewportExtEx = ctypes.windll.gdi32.ScaleViewportExtEx
ScaleViewportExtEx.restype = wintypes.BOOL
ScaleViewportExtEx.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # xn : INT
    ctypes.c_int,  # dx : INT
    ctypes.c_int,  # yn : INT
    ctypes.c_int,  # yd : INT
    ctypes.c_void_p,  # lpsz : SIZE* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procScaleViewportExtEx = gdi32.NewProc("ScaleViewportExtEx")
)

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

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

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

foreign import stdcall safe "ScaleViewportExtEx"
  c_ScaleViewportExtEx :: Ptr () -> Int32 -> Int32 -> Int32 -> Int32 -> Ptr () -> IO CInt
-- hdc : HDC -> Ptr ()
-- xn : INT -> Int32
-- dx : INT -> Int32
-- yn : INT -> Int32
-- yd : INT -> Int32
-- lpsz : SIZE* optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let scaleviewportextex =
  foreign "ScaleViewportExtEx"
    ((ptr void) @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> (ptr void) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* xn : INT -> int32_t *)
(* dx : INT -> int32_t *)
(* yn : INT -> int32_t *)
(* yd : INT -> int32_t *)
(* lpsz : SIZE* optional, 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 ("ScaleViewportExtEx" scale-viewport-ext-ex :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (xn :int32)   ; INT
  (dx :int32)   ; INT
  (yn :int32)   ; INT
  (yd :int32)   ; INT
  (lpsz :pointer))   ; SIZE* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ScaleViewportExtEx = Win32::API::More->new('GDI32',
    'BOOL ScaleViewportExtEx(HANDLE hdc, int xn, int dx, int yn, int yd, LPVOID lpsz)');
# my $ret = $ScaleViewportExtEx->Call($hdc, $xn, $dx, $yn, $yd, $lpsz);
# hdc : HDC -> HANDLE
# xn : INT -> int
# dx : INT -> int
# yn : INT -> int
# yd : INT -> int
# lpsz : SIZE* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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