ホーム › Graphics.Gdi › SetLayout
SetLayout
関数デバイスコンテキストのレイアウト方向(右から左など)を設定する。
シグネチャ
// GDI32.dll
#include <windows.h>
DWORD SetLayout(
HDC hdc,
DC_LAYOUT l
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| hdc | HDC | in | DC へのハンドル。 | ||||||
| l | DC_LAYOUT | in | DC のレイアウト。このパラメーターには、次の値のうち 1 つ以上を指定できます。
|
戻り値の型: DWORD
公式ドキュメント
SetLayout 関数は、デバイスコンテキスト (DC) のレイアウトを変更します。
戻り値
関数が成功した場合は、DC の以前のレイアウトを返します。
関数が失敗した場合は、GDI_ERROR を返します。
解説(Remarks)
レイアウトは、ウィンドウまたはデバイスコンテキスト内でテキストやグラフィックスが表示される順序を指定します。既定は左から右です。SetLayout 関数はこれを右から左に変更します。これはアラビア語やヘブライ語の文化圏における標準です。
LAYOUT_RTL フラグが選択されると、通常は右または左を指定するフラグの意味が反転します。混乱を避けるため、次の表に示すような標準フラグの代替名を定義することを検討してください。
| 標準フラグ | 推奨される代替名 |
|---|---|
| WS_EX_RIGHT | WS_EX_TRAILING |
| WS_EX_RTLREADING | WS_EX_REVERSEREADING |
| WS_EX_LEFTSCROLLBAR | WS_EX_LEADSCROLLBAR |
| ES_LEFT | ES_LEAD |
| ES_RIGHT | ES_TRAIL |
| EC_LEFTMARGIN | EC_LEADMARGIN |
| EC_RIGHTMARGIN | EC_TRAILMARGIN |
SetLayout では、DIB のビットへ直接行う描画を変更することはできません。
詳細については、Window Features の「Window Layout and Mirroring」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
DWORD SetLayout(
HDC hdc,
DC_LAYOUT l
);[DllImport("GDI32.dll", ExactSpelling = true)]
static extern uint SetLayout(
IntPtr hdc, // HDC
uint l // DC_LAYOUT
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function SetLayout(
hdc As IntPtr, ' HDC
l As UInteger ' DC_LAYOUT
) As UInteger
End Function' hdc : HDC
' l : DC_LAYOUT
Declare PtrSafe Function SetLayout Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal l As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetLayout = ctypes.windll.gdi32.SetLayout
SetLayout.restype = wintypes.DWORD
SetLayout.argtypes = [
wintypes.HANDLE, # hdc : HDC
wintypes.DWORD, # l : DC_LAYOUT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
SetLayout = Fiddle::Function.new(
lib['SetLayout'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
-Fiddle::TYPE_INT, # l : DC_LAYOUT
],
-Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn SetLayout(
hdc: *mut core::ffi::c_void, // HDC
l: u32 // DC_LAYOUT
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll")]
public static extern uint SetLayout(IntPtr hdc, uint l);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_SetLayout' -Namespace Win32 -PassThru
# $api::SetLayout(hdc, l)#uselib "GDI32.dll"
#func global SetLayout "SetLayout" sptr, sptr
; SetLayout hdc, l ; 戻り値は stat
; hdc : HDC -> "sptr"
; l : DC_LAYOUT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll"
#cfunc global SetLayout "SetLayout" sptr, int
; res = SetLayout(hdc, l)
; hdc : HDC -> "sptr"
; l : DC_LAYOUT -> "int"; DWORD SetLayout(HDC hdc, DC_LAYOUT l)
#uselib "GDI32.dll"
#cfunc global SetLayout "SetLayout" intptr, int
; res = SetLayout(hdc, l)
; hdc : HDC -> "intptr"
; l : DC_LAYOUT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procSetLayout = gdi32.NewProc("SetLayout")
)
// hdc (HDC), l (DC_LAYOUT)
r1, _, err := procSetLayout.Call(
uintptr(hdc),
uintptr(l),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction SetLayout(
hdc: THandle; // HDC
l: DWORD // DC_LAYOUT
): DWORD; stdcall;
external 'GDI32.dll' name 'SetLayout';result := DllCall("GDI32\SetLayout"
, "Ptr", hdc ; HDC
, "UInt", l ; DC_LAYOUT
, "UInt") ; return: DWORD●SetLayout(hdc, l) = DLL("GDI32.dll", "dword SetLayout(void*, dword)")
# 呼び出し: SetLayout(hdc, l)
# hdc : HDC -> "void*"
# l : DC_LAYOUT -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn SetLayout(
hdc: ?*anyopaque, // HDC
l: u32 // DC_LAYOUT
) callconv(std.os.windows.WINAPI) u32;proc SetLayout(
hdc: pointer, # HDC
l: uint32 # DC_LAYOUT
): uint32 {.importc: "SetLayout", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
uint SetLayout(
void* hdc, // HDC
uint l // DC_LAYOUT
);ccall((:SetLayout, "GDI32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, UInt32),
hdc, l)
# hdc : HDC -> Ptr{Cvoid}
# l : DC_LAYOUT -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t SetLayout(
void* hdc,
uint32_t l);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.SetLayout(hdc, l)
-- hdc : HDC
-- l : DC_LAYOUT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const SetLayout = lib.func('__stdcall', 'SetLayout', 'uint32_t', ['void *', 'uint32_t']);
// SetLayout(hdc, l)
// hdc : HDC -> 'void *'
// l : DC_LAYOUT -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
SetLayout: { parameters: ["pointer", "u32"], result: "u32" },
});
// lib.symbols.SetLayout(hdc, l)
// hdc : HDC -> "pointer"
// l : DC_LAYOUT -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t SetLayout(
void* hdc,
uint32_t l);
C, "GDI32.dll");
// $ffi->SetLayout(hdc, l);
// hdc : HDC
// l : DC_LAYOUT
// 構造体/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 SetLayout(
Pointer hdc, // HDC
int l // DC_LAYOUT
);
}@[Link("gdi32")]
lib LibGDI32
fun SetLayout = SetLayout(
hdc : Void*, # HDC
l : UInt32 # DC_LAYOUT
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetLayoutNative = Uint32 Function(Pointer<Void>, Uint32);
typedef SetLayoutDart = int Function(Pointer<Void>, int);
final SetLayout = DynamicLibrary.open('GDI32.dll')
.lookupFunction<SetLayoutNative, SetLayoutDart>('SetLayout');
// hdc : HDC -> Pointer<Void>
// l : DC_LAYOUT -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetLayout(
hdc: THandle; // HDC
l: DWORD // DC_LAYOUT
): DWORD; stdcall;
external 'GDI32.dll' name 'SetLayout';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetLayout"
c_SetLayout :: Ptr () -> Word32 -> IO Word32
-- hdc : HDC -> Ptr ()
-- l : DC_LAYOUT -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setlayout =
foreign "SetLayout"
((ptr void) @-> uint32_t @-> returning uint32_t)
(* hdc : HDC -> (ptr void) *)
(* l : DC_LAYOUT -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("SetLayout" set-layout :convention :stdcall) :uint32
(hdc :pointer) ; HDC
(l :uint32)) ; DC_LAYOUT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetLayout = Win32::API::More->new('GDI32',
'DWORD SetLayout(HANDLE hdc, DWORD l)');
# my $ret = $SetLayout->Call($hdc, $l);
# hdc : HDC -> HANDLE
# l : DC_LAYOUT -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetLayout — デバイスコンテキストのレイアウト方向を取得する。
使用する型