ホーム › Graphics.Gdi › SetRect
SetRect
関数RECT構造体に指定した座標を設定する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL SetRect(
RECT* lprc,
INT xLeft,
INT yTop,
INT xRight,
INT yBottom
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lprc | RECT* | out | 設定する四角形を格納する RECT 構造体へのポインター。 |
| xLeft | INT | in | 四角形の左上隅の x 座標を指定します。 |
| yTop | INT | in | 四角形の左上隅の y 座標を指定します。 |
| xRight | INT | in | 四角形の右下隅の x 座標を指定します。 |
| yBottom | INT | in | 四角形の右下隅の y 座標を指定します。 |
戻り値の型: BOOL
公式ドキュメント
SetRect 関数は、指定された四角形の座標を設定します。これは、left、top、right、bottom の各引数を RECT 構造体の対応するメンバーに代入することと同等です。
戻り値
関数が成功すると、戻り値は 0 以外の値になります。
関数が失敗すると、戻り値は 0 になります。
解説(Remarks)
アプリケーションは四角形をさまざまな目的に使用できるため、四角形を扱う関数は明示的な測定単位を使用しません。代わりに、すべての四角形の座標と寸法は、符号付きの論理値で指定されます。測定単位は、マッピングモードと四角形が使用される関数によって決まります。
例
例については、Using Rectangles を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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
#include <windows.h>
BOOL SetRect(
RECT* lprc,
INT xLeft,
INT yTop,
INT xRight,
INT yBottom
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", ExactSpelling = true)]
static extern bool SetRect(
IntPtr lprc, // RECT* out
int xLeft, // INT
int yTop, // INT
int xRight, // INT
int yBottom // INT
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function SetRect(
lprc As IntPtr, ' RECT* out
xLeft As Integer, ' INT
yTop As Integer, ' INT
xRight As Integer, ' INT
yBottom As Integer ' INT
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' lprc : RECT* out
' xLeft : INT
' yTop : INT
' xRight : INT
' yBottom : INT
Declare PtrSafe Function SetRect Lib "user32" ( _
ByVal lprc As LongPtr, _
ByVal xLeft As Long, _
ByVal yTop As Long, _
ByVal xRight As Long, _
ByVal yBottom As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetRect = ctypes.windll.user32.SetRect
SetRect.restype = wintypes.BOOL
SetRect.argtypes = [
ctypes.c_void_p, # lprc : RECT* out
ctypes.c_int, # xLeft : INT
ctypes.c_int, # yTop : INT
ctypes.c_int, # xRight : INT
ctypes.c_int, # yBottom : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
SetRect = Fiddle::Function.new(
lib['SetRect'],
[
Fiddle::TYPE_VOIDP, # lprc : RECT* out
Fiddle::TYPE_INT, # xLeft : INT
Fiddle::TYPE_INT, # yTop : INT
Fiddle::TYPE_INT, # xRight : INT
Fiddle::TYPE_INT, # yBottom : INT
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn SetRect(
lprc: *mut RECT, // RECT* out
xLeft: i32, // INT
yTop: i32, // INT
xRight: i32, // INT
yBottom: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll")]
public static extern bool SetRect(IntPtr lprc, int xLeft, int yTop, int xRight, int yBottom);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetRect' -Namespace Win32 -PassThru
# $api::SetRect(lprc, xLeft, yTop, xRight, yBottom)#uselib "USER32.dll"
#func global SetRect "SetRect" sptr, sptr, sptr, sptr, sptr
; SetRect varptr(lprc), xLeft, yTop, xRight, yBottom ; 戻り値は stat
; lprc : RECT* out -> "sptr"
; xLeft : INT -> "sptr"
; yTop : INT -> "sptr"
; xRight : INT -> "sptr"
; yBottom : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "USER32.dll" #cfunc global SetRect "SetRect" var, int, int, int, int ; res = SetRect(lprc, xLeft, yTop, xRight, yBottom) ; lprc : RECT* out -> "var" ; xLeft : INT -> "int" ; yTop : INT -> "int" ; xRight : INT -> "int" ; yBottom : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USER32.dll" #cfunc global SetRect "SetRect" sptr, int, int, int, int ; res = SetRect(varptr(lprc), xLeft, yTop, xRight, yBottom) ; lprc : RECT* out -> "sptr" ; xLeft : INT -> "int" ; yTop : INT -> "int" ; xRight : INT -> "int" ; yBottom : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetRect(RECT* lprc, INT xLeft, INT yTop, INT xRight, INT yBottom) #uselib "USER32.dll" #cfunc global SetRect "SetRect" var, int, int, int, int ; res = SetRect(lprc, xLeft, yTop, xRight, yBottom) ; lprc : RECT* out -> "var" ; xLeft : INT -> "int" ; yTop : INT -> "int" ; xRight : INT -> "int" ; yBottom : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetRect(RECT* lprc, INT xLeft, INT yTop, INT xRight, INT yBottom) #uselib "USER32.dll" #cfunc global SetRect "SetRect" intptr, int, int, int, int ; res = SetRect(varptr(lprc), xLeft, yTop, xRight, yBottom) ; lprc : RECT* out -> "intptr" ; xLeft : INT -> "int" ; yTop : INT -> "int" ; xRight : INT -> "int" ; yBottom : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procSetRect = user32.NewProc("SetRect")
)
// lprc (RECT* out), xLeft (INT), yTop (INT), xRight (INT), yBottom (INT)
r1, _, err := procSetRect.Call(
uintptr(lprc),
uintptr(xLeft),
uintptr(yTop),
uintptr(xRight),
uintptr(yBottom),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetRect(
lprc: Pointer; // RECT* out
xLeft: Integer; // INT
yTop: Integer; // INT
xRight: Integer; // INT
yBottom: Integer // INT
): BOOL; stdcall;
external 'USER32.dll' name 'SetRect';result := DllCall("USER32\SetRect"
, "Ptr", lprc ; RECT* out
, "Int", xLeft ; INT
, "Int", yTop ; INT
, "Int", xRight ; INT
, "Int", yBottom ; INT
, "Int") ; return: BOOL●SetRect(lprc, xLeft, yTop, xRight, yBottom) = DLL("USER32.dll", "bool SetRect(void*, int, int, int, int)")
# 呼び出し: SetRect(lprc, xLeft, yTop, xRight, yBottom)
# lprc : RECT* out -> "void*"
# xLeft : INT -> "int"
# yTop : INT -> "int"
# xRight : INT -> "int"
# yBottom : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "user32" fn SetRect(
lprc: [*c]RECT, // RECT* out
xLeft: i32, // INT
yTop: i32, // INT
xRight: i32, // INT
yBottom: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc SetRect(
lprc: ptr RECT, # RECT* out
xLeft: int32, # INT
yTop: int32, # INT
xRight: int32, # INT
yBottom: int32 # INT
): int32 {.importc: "SetRect", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int SetRect(
RECT* lprc, // RECT* out
int xLeft, // INT
int yTop, // INT
int xRight, // INT
int yBottom // INT
);ccall((:SetRect, "USER32.dll"), stdcall, Int32,
(Ptr{RECT}, Int32, Int32, Int32, Int32),
lprc, xLeft, yTop, xRight, yBottom)
# lprc : RECT* out -> Ptr{RECT}
# xLeft : INT -> Int32
# yTop : INT -> Int32
# xRight : INT -> Int32
# yBottom : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetRect(
void* lprc,
int32_t xLeft,
int32_t yTop,
int32_t xRight,
int32_t yBottom);
]]
local user32 = ffi.load("user32")
-- user32.SetRect(lprc, xLeft, yTop, xRight, yBottom)
-- lprc : RECT* out
-- xLeft : INT
-- yTop : INT
-- xRight : INT
-- yBottom : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const SetRect = lib.func('__stdcall', 'SetRect', 'int32_t', ['void *', 'int32_t', 'int32_t', 'int32_t', 'int32_t']);
// SetRect(lprc, xLeft, yTop, xRight, yBottom)
// lprc : RECT* out -> 'void *'
// xLeft : INT -> 'int32_t'
// yTop : INT -> 'int32_t'
// xRight : INT -> 'int32_t'
// yBottom : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
SetRect: { parameters: ["pointer", "i32", "i32", "i32", "i32"], result: "i32" },
});
// lib.symbols.SetRect(lprc, xLeft, yTop, xRight, yBottom)
// lprc : RECT* out -> "pointer"
// xLeft : INT -> "i32"
// yTop : INT -> "i32"
// xRight : INT -> "i32"
// yBottom : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetRect(
void* lprc,
int32_t xLeft,
int32_t yTop,
int32_t xRight,
int32_t yBottom);
C, "USER32.dll");
// $ffi->SetRect(lprc, xLeft, yTop, xRight, yBottom);
// lprc : RECT* out
// xLeft : INT
// yTop : INT
// xRight : INT
// yBottom : INT
// 構造体/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);
boolean SetRect(
Pointer lprc, // RECT* out
int xLeft, // INT
int yTop, // INT
int xRight, // INT
int yBottom // INT
);
}@[Link("user32")]
lib LibUSER32
fun SetRect = SetRect(
lprc : RECT*, # RECT* out
xLeft : Int32, # INT
yTop : Int32, # INT
xRight : Int32, # INT
yBottom : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetRectNative = Int32 Function(Pointer<Void>, Int32, Int32, Int32, Int32);
typedef SetRectDart = int Function(Pointer<Void>, int, int, int, int);
final SetRect = DynamicLibrary.open('USER32.dll')
.lookupFunction<SetRectNative, SetRectDart>('SetRect');
// lprc : RECT* out -> Pointer<Void>
// xLeft : INT -> Int32
// yTop : INT -> Int32
// xRight : INT -> Int32
// yBottom : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetRect(
lprc: Pointer; // RECT* out
xLeft: Integer; // INT
yTop: Integer; // INT
xRight: Integer; // INT
yBottom: Integer // INT
): BOOL; stdcall;
external 'USER32.dll' name 'SetRect';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetRect"
c_SetRect :: Ptr () -> Int32 -> Int32 -> Int32 -> Int32 -> IO CInt
-- lprc : RECT* out -> Ptr ()
-- xLeft : INT -> Int32
-- yTop : INT -> Int32
-- xRight : INT -> Int32
-- yBottom : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setrect =
foreign "SetRect"
((ptr void) @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> returning int32_t)
(* lprc : RECT* out -> (ptr void) *)
(* xLeft : INT -> int32_t *)
(* yTop : INT -> int32_t *)
(* xRight : INT -> int32_t *)
(* yBottom : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("SetRect" set-rect :convention :stdcall) :int32
(lprc :pointer) ; RECT* out
(x-left :int32) ; INT
(y-top :int32) ; INT
(x-right :int32) ; INT
(y-bottom :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetRect = Win32::API::More->new('USER32',
'BOOL SetRect(LPVOID lprc, int xLeft, int yTop, int xRight, int yBottom)');
# my $ret = $SetRect->Call($lprc, $xLeft, $yTop, $xRight, $yBottom);
# lprc : RECT* out -> LPVOID
# xLeft : INT -> int
# yTop : INT -> int
# xRight : INT -> int
# yBottom : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f CopyRect — ある矩形の内容を別の矩形へコピーする。
- f SetRectEmpty — RECT構造体を空の矩形に設定する。
使用する型