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

SetScrollPos

関数
スクロールバーのつまみ位置を設定する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

INT SetScrollPos(
    HWND hWnd,
    SCROLLBAR_CONSTANTS nBar,
    INT nPos,
    BOOL bRedraw
);

パラメーター

名前方向
hWndHWNDin
nBarSCROLLBAR_CONSTANTSin
nPosINTin
bRedrawBOOLin

戻り値の型: INT

各言語での呼び出し定義

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

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

SetScrollPos = ctypes.windll.user32.SetScrollPos
SetScrollPos.restype = ctypes.c_int
SetScrollPos.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_int,  # nBar : SCROLLBAR_CONSTANTS
    ctypes.c_int,  # nPos : INT
    wintypes.BOOL,  # bRedraw : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procSetScrollPos = user32.NewProc("SetScrollPos")
)

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