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

CheckDlgButton

関数
ダイアログ内ボタンのチェック状態を設定する。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL CheckDlgButton(
    HWND hDlg,
    INT nIDButton,
    DLG_BUTTON_CHECK_STATE uCheck
);

パラメーター

名前方向
hDlgHWNDin
nIDButtonINTin
uCheckDLG_BUTTON_CHECK_STATEin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

CheckDlgButton = ctypes.windll.user32.CheckDlgButton
CheckDlgButton.restype = wintypes.BOOL
CheckDlgButton.argtypes = [
    wintypes.HANDLE,  # hDlg : HWND
    ctypes.c_int,  # nIDButton : INT
    wintypes.DWORD,  # uCheck : DLG_BUTTON_CHECK_STATE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procCheckDlgButton = user32.NewProc("CheckDlgButton")
)

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