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

SetMapperFlags

関数
論理フォントを物理フォントへ対応付ける際のマッパーフラグを設定する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD SetMapperFlags(
    HDC hdc,
    DWORD flags
);

パラメーター

名前方向説明
hdcHDCinフォントマッパーフラグを含むデバイスコンテキストへのハンドル。
flagsDWORDinフォントマッパーがフォントの縦横比を現在のデバイスの縦横比に一致させようとするかどうかを指定します。ビット 0 が設定されている場合、マッパーは一致するフォントのみを選択します。

戻り値の型: DWORD

公式ドキュメント

SetMapperFlags 関数は、論理フォントを物理フォントにマッピングする際にフォントマッパーが使用するアルゴリズムを変更します。

戻り値

関数が成功した場合、戻り値はフォントマッパーフラグの以前の値です。

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

解説(Remarks)

dwFlag パラメーターが設定されていて、一致するフォントが存在しない場合、Windows は新しい縦横比を選択し、この比率に一致するフォントを取得します。

dwFlag パラメーターの残りのビットは 0 でなければなりません。

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

各言語での呼び出し定義

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

DWORD SetMapperFlags(
    HDC hdc,
    DWORD flags
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern uint SetMapperFlags(
    IntPtr hdc,   // HDC
    uint flags   // DWORD
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function SetMapperFlags(
    hdc As IntPtr,   ' HDC
    flags As UInteger   ' DWORD
) As UInteger
End Function
' hdc : HDC
' flags : DWORD
Declare PtrSafe Function SetMapperFlags Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetMapperFlags = ctypes.windll.gdi32.SetMapperFlags
SetMapperFlags.restype = wintypes.DWORD
SetMapperFlags.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.DWORD,  # flags : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procSetMapperFlags = gdi32.NewProc("SetMapperFlags")
)

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

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

typedef SetMapperFlagsNative = Uint32 Function(Pointer<Void>, Uint32);
typedef SetMapperFlagsDart = int Function(Pointer<Void>, int);
final SetMapperFlags = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<SetMapperFlagsNative, SetMapperFlagsDart>('SetMapperFlags');
// hdc : HDC -> Pointer<Void>
// flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetMapperFlags(
  hdc: THandle;   // HDC
  flags: DWORD   // DWORD
): DWORD; stdcall;
  external 'GDI32.dll' name 'SetMapperFlags';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetMapperFlags"
  c_SetMapperFlags :: Ptr () -> Word32 -> IO Word32
-- hdc : HDC -> Ptr ()
-- flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

(cffi:defcfun ("SetMapperFlags" set-mapper-flags :convention :stdcall) :uint32
  (hdc :pointer)   ; HDC
  (flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetMapperFlags = Win32::API::More->new('GDI32',
    'DWORD SetMapperFlags(HANDLE hdc, DWORD flags)');
# my $ret = $SetMapperFlags->Call($hdc, $flags);
# hdc : HDC -> HANDLE
# flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目