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

GetScrollPos

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

シグネチャ

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

INT GetScrollPos(
    HWND hWnd,
    SCROLLBAR_CONSTANTS nBar
);

パラメーター

名前方向
hWndHWNDin
nBarSCROLLBAR_CONSTANTSin

戻り値の型: INT

各言語での呼び出し定義

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

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

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

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetScrollPos = user32.NewProc("GetScrollPos")
)

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