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

ScrollWindow

関数
ウィンドウのクライアント領域の内容をスクロールする。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL ScrollWindow(
    HWND hWnd,
    INT XAmount,
    INT YAmount,
    const RECT* lpRect,   // optional
    const RECT* lpClipRect   // optional
);

パラメーター

名前方向
hWndHWNDin
XAmountINTin
YAmountINTin
lpRectRECT*inoptional
lpClipRectRECT*inoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

ScrollWindow = ctypes.windll.user32.ScrollWindow
ScrollWindow.restype = wintypes.BOOL
ScrollWindow.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_int,  # XAmount : INT
    ctypes.c_int,  # YAmount : INT
    ctypes.c_void_p,  # lpRect : RECT* optional
    ctypes.c_void_p,  # lpClipRect : RECT* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
ScrollWindow = Fiddle::Function.new(
  lib['ScrollWindow'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    Fiddle::TYPE_INT,  # XAmount : INT
    Fiddle::TYPE_INT,  # YAmount : INT
    Fiddle::TYPE_VOIDP,  # lpRect : RECT* optional
    Fiddle::TYPE_VOIDP,  # lpClipRect : RECT* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn ScrollWindow(
        hWnd: *mut core::ffi::c_void,  // HWND
        XAmount: i32,  // INT
        YAmount: i32,  // INT
        lpRect: *const RECT,  // RECT* optional
        lpClipRect: *const RECT  // RECT* optional
    ) -> 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 ScrollWindow(IntPtr hWnd, int XAmount, int YAmount, IntPtr lpRect, IntPtr lpClipRect);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_ScrollWindow' -Namespace Win32 -PassThru
# $api::ScrollWindow(hWnd, XAmount, YAmount, lpRect, lpClipRect)
#uselib "USER32.dll"
#func global ScrollWindow "ScrollWindow" sptr, sptr, sptr, sptr, sptr
; ScrollWindow hWnd, XAmount, YAmount, varptr(lpRect), varptr(lpClipRect)   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; XAmount : INT -> "sptr"
; YAmount : INT -> "sptr"
; lpRect : RECT* optional -> "sptr"
; lpClipRect : RECT* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global ScrollWindow "ScrollWindow" sptr, int, int, var, var
; res = ScrollWindow(hWnd, XAmount, YAmount, lpRect, lpClipRect)
; hWnd : HWND -> "sptr"
; XAmount : INT -> "int"
; YAmount : INT -> "int"
; lpRect : RECT* optional -> "var"
; lpClipRect : RECT* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL ScrollWindow(HWND hWnd, INT XAmount, INT YAmount, RECT* lpRect, RECT* lpClipRect)
#uselib "USER32.dll"
#cfunc global ScrollWindow "ScrollWindow" intptr, int, int, var, var
; res = ScrollWindow(hWnd, XAmount, YAmount, lpRect, lpClipRect)
; hWnd : HWND -> "intptr"
; XAmount : INT -> "int"
; YAmount : INT -> "int"
; lpRect : RECT* optional -> "var"
; lpClipRect : RECT* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procScrollWindow = user32.NewProc("ScrollWindow")
)

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