Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › MoveWindow

MoveWindow

関数
ウィンドウの位置とサイズを変更する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL MoveWindow(
    HWND hWnd,
    INT X,
    INT Y,
    INT nWidth,
    INT nHeight,
    BOOL bRepaint
);

パラメーター

名前方向
hWndHWNDin
XINTin
YINTin
nWidthINTin
nHeightINTin
bRepaintBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL MoveWindow(
    HWND hWnd,
    INT X,
    INT Y,
    INT nWidth,
    INT nHeight,
    BOOL bRepaint
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool MoveWindow(
    IntPtr hWnd,   // HWND
    int X,   // INT
    int Y,   // INT
    int nWidth,   // INT
    int nHeight,   // INT
    bool bRepaint   // BOOL
);
<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function MoveWindow(
    hWnd As IntPtr,   ' HWND
    X As Integer,   ' INT
    Y As Integer,   ' INT
    nWidth As Integer,   ' INT
    nHeight As Integer,   ' INT
    bRepaint As Boolean   ' BOOL
) As Boolean
End Function
' hWnd : HWND
' X : INT
' Y : INT
' nWidth : INT
' nHeight : INT
' bRepaint : BOOL
Declare PtrSafe Function MoveWindow Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal X As Long, _
    ByVal Y As Long, _
    ByVal nWidth As Long, _
    ByVal nHeight As Long, _
    ByVal bRepaint As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MoveWindow = ctypes.windll.user32.MoveWindow
MoveWindow.restype = wintypes.BOOL
MoveWindow.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_int,  # X : INT
    ctypes.c_int,  # Y : INT
    ctypes.c_int,  # nWidth : INT
    ctypes.c_int,  # nHeight : INT
    wintypes.BOOL,  # bRepaint : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
MoveWindow = Fiddle::Function.new(
  lib['MoveWindow'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    Fiddle::TYPE_INT,  # X : INT
    Fiddle::TYPE_INT,  # Y : INT
    Fiddle::TYPE_INT,  # nWidth : INT
    Fiddle::TYPE_INT,  # nHeight : INT
    Fiddle::TYPE_INT,  # bRepaint : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn MoveWindow(
        hWnd: *mut core::ffi::c_void,  // HWND
        X: i32,  // INT
        Y: i32,  // INT
        nWidth: i32,  // INT
        nHeight: i32,  // INT
        bRepaint: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true)]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_MoveWindow' -Namespace Win32 -PassThru
# $api::MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint)
#uselib "USER32.dll"
#func global MoveWindow "MoveWindow" sptr, sptr, sptr, sptr, sptr, sptr
; MoveWindow hWnd, X, Y, nWidth, nHeight, bRepaint   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; X : INT -> "sptr"
; Y : INT -> "sptr"
; nWidth : INT -> "sptr"
; nHeight : INT -> "sptr"
; bRepaint : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global MoveWindow "MoveWindow" sptr, int, int, int, int, int
; res = MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint)
; hWnd : HWND -> "sptr"
; X : INT -> "int"
; Y : INT -> "int"
; nWidth : INT -> "int"
; nHeight : INT -> "int"
; bRepaint : BOOL -> "int"
; BOOL MoveWindow(HWND hWnd, INT X, INT Y, INT nWidth, INT nHeight, BOOL bRepaint)
#uselib "USER32.dll"
#cfunc global MoveWindow "MoveWindow" intptr, int, int, int, int, int
; res = MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint)
; hWnd : HWND -> "intptr"
; X : INT -> "int"
; Y : INT -> "int"
; nWidth : INT -> "int"
; nHeight : INT -> "int"
; bRepaint : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procMoveWindow = user32.NewProc("MoveWindow")
)

// hWnd (HWND), X (INT), Y (INT), nWidth (INT), nHeight (INT), bRepaint (BOOL)
r1, _, err := procMoveWindow.Call(
	uintptr(hWnd),
	uintptr(X),
	uintptr(Y),
	uintptr(nWidth),
	uintptr(nHeight),
	uintptr(bRepaint),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function MoveWindow(
  hWnd: THandle;   // HWND
  X: Integer;   // INT
  Y: Integer;   // INT
  nWidth: Integer;   // INT
  nHeight: Integer;   // INT
  bRepaint: BOOL   // BOOL
): BOOL; stdcall;
  external 'USER32.dll' name 'MoveWindow';
result := DllCall("USER32\MoveWindow"
    , "Ptr", hWnd   ; HWND
    , "Int", X   ; INT
    , "Int", Y   ; INT
    , "Int", nWidth   ; INT
    , "Int", nHeight   ; INT
    , "Int", bRepaint   ; BOOL
    , "Int")   ; return: BOOL
●MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint) = DLL("USER32.dll", "bool MoveWindow(void*, int, int, int, int, bool)")
# 呼び出し: MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint)
# hWnd : HWND -> "void*"
# X : INT -> "int"
# Y : INT -> "int"
# nWidth : INT -> "int"
# nHeight : INT -> "int"
# bRepaint : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。