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

ShowScrollBar

関数
スクロールバーの表示・非表示を切り替える。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL ShowScrollBar(
    HWND hWnd,
    SCROLLBAR_CONSTANTS wBar,
    BOOL bShow
);

パラメーター

名前方向
hWndHWNDin
wBarSCROLLBAR_CONSTANTSin
bShowBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

lib = Fiddle.dlopen('USER32.dll')
ShowScrollBar = Fiddle::Function.new(
  lib['ShowScrollBar'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    Fiddle::TYPE_INT,  # wBar : SCROLLBAR_CONSTANTS
    Fiddle::TYPE_INT,  # bShow : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn ShowScrollBar(
        hWnd: *mut core::ffi::c_void,  // HWND
        wBar: i32,  // SCROLLBAR_CONSTANTS
        bShow: 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 ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_ShowScrollBar' -Namespace Win32 -PassThru
# $api::ShowScrollBar(hWnd, wBar, bShow)
#uselib "USER32.dll"
#func global ShowScrollBar "ShowScrollBar" sptr, sptr, sptr
; ShowScrollBar hWnd, wBar, bShow   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; wBar : SCROLLBAR_CONSTANTS -> "sptr"
; bShow : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global ShowScrollBar "ShowScrollBar" sptr, int, int
; res = ShowScrollBar(hWnd, wBar, bShow)
; hWnd : HWND -> "sptr"
; wBar : SCROLLBAR_CONSTANTS -> "int"
; bShow : BOOL -> "int"
; BOOL ShowScrollBar(HWND hWnd, SCROLLBAR_CONSTANTS wBar, BOOL bShow)
#uselib "USER32.dll"
#cfunc global ShowScrollBar "ShowScrollBar" intptr, int, int
; res = ShowScrollBar(hWnd, wBar, bShow)
; hWnd : HWND -> "intptr"
; wBar : SCROLLBAR_CONSTANTS -> "int"
; bShow : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procShowScrollBar = user32.NewProc("ShowScrollBar")
)

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