SetScrollPos
関数シグネチャ
// USER32.dll
#include <windows.h>
INT SetScrollPos(
HWND hWnd,
SCROLLBAR_CONSTANTS nBar,
INT nPos,
BOOL bRedraw
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| hWnd | HWND | in | nBar パラメーターの値に応じて、スクロールバーコントロールへのハンドル、または標準スクロールバーを持つウィンドウへのハンドルを指定します。 | ||||||||
| nBar | SCROLLBAR_CONSTANTS | in | 設定するスクロールバーを指定します。このパラメーターには、次のいずれかの値を指定できます。
| ||||||||
| nPos | INT | in | スクロールボックスの新しい位置を指定します。位置はスクロール範囲内である必要があります。スクロール範囲の詳細については、SetScrollRange 関数を参照してください。 | ||||||||
| bRedraw | BOOL | in | 新しいスクロールボックスの位置を反映するようにスクロールバーを再描画するかどうかを指定します。このパラメーターが TRUE の場合、スクロールバーが再描画されます。FALSE の場合、スクロールバーは再描画されません。 |
戻り値の型: INT
公式ドキュメント
SetScrollPos 関数は、指定したスクロールバー内のスクロールボックス(つまみ)の位置を設定し、要求された場合は新しいスクロールボックスの位置を反映するようにスクロールバーを再描画します。
戻り値
解説(Remarks)
スクロールバーが後続の別の関数の呼び出しによって再描画される場合、bRedraw パラメーターを FALSE に設定すると便利です。
スクロールバーの位置を示すメッセージ WM_HSCROLL および WM_VSCROLL は位置データが 16 ビットに制限されているため、これらのメッセージのみに位置データを依存するアプリケーションでは、SetScrollPos 関数の nPos パラメーターの実用上の最大値は 65,535 になります。
ただし、SetScrollInfo、SetScrollPos、SetScrollRange、GetScrollInfo、GetScrollPos、および GetScrollRange の各関数は 32 ビットのスクロールバー位置データをサポートしているため、WM_HSCROLL および WM_VSCROLL メッセージの 16 ビットの制約を回避する方法があります。その手法の説明については GetScrollInfo を参照してください。
nBar パラメーターが SB_CTL で、hWnd パラメーターで指定されたウィンドウがシステムのスクロールバーコントロールでない場合、システムはスクロールバー情報を設定するために SBM_SETPOS メッセージをウィンドウに送信します。これにより、SetScrollPos はスクロールバーを模倣したカスタムコントロールに対して動作できます。ウィンドウが SBM_SETPOS メッセージを処理しない場合、SetScrollPos 関数は失敗します。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 // INTfunction 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)。const std = @import("std");
extern "user32" fn SetScrollPos(
hWnd: ?*anyopaque, // HWND
nBar: i32, // SCROLLBAR_CONSTANTS
nPos: i32, // INT
bRedraw: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;proc SetScrollPos(
hWnd: pointer, # HWND
nBar: int32, # SCROLLBAR_CONSTANTS
nPos: int32, # INT
bRedraw: int32 # BOOL
): int32 {.importc: "SetScrollPos", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int SetScrollPos(
void* hWnd, // HWND
int nBar, // SCROLLBAR_CONSTANTS
int nPos, // INT
int bRedraw // BOOL
);ccall((:SetScrollPos, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Int32, Int32),
hWnd, nBar, nPos, bRedraw)
# hWnd : HWND -> Ptr{Cvoid}
# nBar : SCROLLBAR_CONSTANTS -> Int32
# nPos : INT -> Int32
# bRedraw : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetScrollPos(
void* hWnd,
int32_t nBar,
int32_t nPos,
int32_t bRedraw);
]]
local user32 = ffi.load("user32")
-- user32.SetScrollPos(hWnd, nBar, nPos, bRedraw)
-- hWnd : HWND
-- nBar : SCROLLBAR_CONSTANTS
-- nPos : INT
-- bRedraw : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const SetScrollPos = lib.func('__stdcall', 'SetScrollPos', 'int32_t', ['void *', 'int32_t', 'int32_t', 'int32_t']);
// SetScrollPos(hWnd, nBar, nPos, bRedraw)
// hWnd : HWND -> 'void *'
// nBar : SCROLLBAR_CONSTANTS -> 'int32_t'
// nPos : INT -> 'int32_t'
// bRedraw : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
SetScrollPos: { parameters: ["pointer", "i32", "i32", "i32"], result: "i32" },
});
// lib.symbols.SetScrollPos(hWnd, nBar, nPos, bRedraw)
// hWnd : HWND -> "pointer"
// nBar : SCROLLBAR_CONSTANTS -> "i32"
// nPos : INT -> "i32"
// bRedraw : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetScrollPos(
void* hWnd,
int32_t nBar,
int32_t nPos,
int32_t bRedraw);
C, "USER32.dll");
// $ffi->SetScrollPos(hWnd, nBar, nPos, bRedraw);
// hWnd : HWND
// nBar : SCROLLBAR_CONSTANTS
// nPos : INT
// bRedraw : BOOL
// 構造体/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);
int SetScrollPos(
Pointer hWnd, // HWND
int nBar, // SCROLLBAR_CONSTANTS
int nPos, // INT
boolean bRedraw // BOOL
);
}@[Link("user32")]
lib LibUSER32
fun SetScrollPos = SetScrollPos(
hWnd : Void*, # HWND
nBar : Int32, # SCROLLBAR_CONSTANTS
nPos : Int32, # INT
bRedraw : Int32 # BOOL
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetScrollPosNative = Int32 Function(Pointer<Void>, Int32, Int32, Int32);
typedef SetScrollPosDart = int Function(Pointer<Void>, int, int, int);
final SetScrollPos = DynamicLibrary.open('USER32.dll')
.lookupFunction<SetScrollPosNative, SetScrollPosDart>('SetScrollPos');
// hWnd : HWND -> Pointer<Void>
// nBar : SCROLLBAR_CONSTANTS -> Int32
// nPos : INT -> Int32
// bRedraw : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetScrollPos(
hWnd: THandle; // HWND
nBar: Integer; // SCROLLBAR_CONSTANTS
nPos: Integer; // INT
bRedraw: BOOL // BOOL
): Integer; stdcall;
external 'USER32.dll' name 'SetScrollPos';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetScrollPos"
c_SetScrollPos :: Ptr () -> Int32 -> Int32 -> CInt -> IO Int32
-- hWnd : HWND -> Ptr ()
-- nBar : SCROLLBAR_CONSTANTS -> Int32
-- nPos : INT -> Int32
-- bRedraw : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setscrollpos =
foreign "SetScrollPos"
((ptr void) @-> int32_t @-> int32_t @-> int32_t @-> returning int32_t)
(* hWnd : HWND -> (ptr void) *)
(* nBar : SCROLLBAR_CONSTANTS -> int32_t *)
(* nPos : INT -> int32_t *)
(* bRedraw : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("SetScrollPos" set-scroll-pos :convention :stdcall) :int32
(h-wnd :pointer) ; HWND
(n-bar :int32) ; SCROLLBAR_CONSTANTS
(n-pos :int32) ; INT
(b-redraw :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetScrollPos = Win32::API::More->new('USER32',
'int SetScrollPos(HANDLE hWnd, int nBar, int nPos, BOOL bRedraw)');
# my $ret = $SetScrollPos->Call($hWnd, $nBar, $nPos, $bRedraw);
# hWnd : HWND -> HANDLE
# nBar : SCROLLBAR_CONSTANTS -> int
# nPos : INT -> int
# bRedraw : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetScrollInfo — スクロールバーの位置や範囲などの情報を取得する。
- f GetScrollPos — スクロールバーのつまみの現在位置を取得する。
- f GetScrollRange — スクロールバーの最小・最大位置の範囲を取得する。
- f SetScrollInfo — スクロールバーの位置・範囲・ページサイズなどの情報を設定する。
- f SetScrollRange — スクロールバーの最小・最大範囲を設定する。