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

ShowHideMenuCtl

関数
メニュー項目に応じてコントロールの表示を切り替える。
DLLCOMCTL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

BOOL ShowHideMenuCtl(
    HWND hWnd,
    UINT_PTR uFlags,
    INT* lpInfo
);

パラメーター

名前方向説明
hWndHWNDinメニューとコントロールを含むウィンドウへのハンドル。
uFlagsUINT_PTRinチェックマークを付与または解除するメニュー項目の識別子。
lpInfoINT*in値のペアを格納した配列へのポインター。最初のペアの2番目の値は、アプリケーションのメインメニューへのハンドルでなければなりません。以降の各ペアは、メニュー項目識別子とコントロールウィンドウ識別子で構成されます。この関数は配列から uFlags に一致する値を検索し、見つかった場合はそのメニュー項目のチェックを切り替え、対応するコントロールの表示または非表示を切り替えます。

戻り値の型: BOOL

公式ドキュメント

指定したメニュー項目のチェックマーク属性を設定または解除し、対応するコントロールの表示または非表示を切り替えます。

戻り値

型: BOOL

成功した場合は0以外、それ以外の場合は0を返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL ShowHideMenuCtl(
    HWND hWnd,
    UINT_PTR uFlags,
    INT* lpInfo
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("COMCTL32.dll", ExactSpelling = true)]
static extern bool ShowHideMenuCtl(
    IntPtr hWnd,   // HWND
    UIntPtr uFlags,   // UINT_PTR
    ref int lpInfo   // INT*
);
<DllImport("COMCTL32.dll", ExactSpelling:=True)>
Public Shared Function ShowHideMenuCtl(
    hWnd As IntPtr,   ' HWND
    uFlags As UIntPtr,   ' UINT_PTR
    ByRef lpInfo As Integer   ' INT*
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hWnd : HWND
' uFlags : UINT_PTR
' lpInfo : INT*
Declare PtrSafe Function ShowHideMenuCtl Lib "comctl32" ( _
    ByVal hWnd As LongPtr, _
    ByVal uFlags As LongPtr, _
    ByRef lpInfo As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ShowHideMenuCtl = ctypes.windll.comctl32.ShowHideMenuCtl
ShowHideMenuCtl.restype = wintypes.BOOL
ShowHideMenuCtl.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_size_t,  # uFlags : UINT_PTR
    ctypes.POINTER(ctypes.c_int),  # lpInfo : INT*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('COMCTL32.dll')
ShowHideMenuCtl = Fiddle::Function.new(
  lib['ShowHideMenuCtl'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    Fiddle::TYPE_UINTPTR_T,  # uFlags : UINT_PTR
    Fiddle::TYPE_VOIDP,  # lpInfo : INT*
  ],
  Fiddle::TYPE_INT)
#[link(name = "comctl32")]
extern "system" {
    fn ShowHideMenuCtl(
        hWnd: *mut core::ffi::c_void,  // HWND
        uFlags: usize,  // UINT_PTR
        lpInfo: *mut i32  // INT*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("COMCTL32.dll")]
public static extern bool ShowHideMenuCtl(IntPtr hWnd, UIntPtr uFlags, ref int lpInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMCTL32_ShowHideMenuCtl' -Namespace Win32 -PassThru
# $api::ShowHideMenuCtl(hWnd, uFlags, lpInfo)
#uselib "COMCTL32.dll"
#func global ShowHideMenuCtl "ShowHideMenuCtl" sptr, sptr, sptr
; ShowHideMenuCtl hWnd, uFlags, varptr(lpInfo)   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; uFlags : UINT_PTR -> "sptr"
; lpInfo : INT* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "COMCTL32.dll"
#cfunc global ShowHideMenuCtl "ShowHideMenuCtl" sptr, sptr, var
; res = ShowHideMenuCtl(hWnd, uFlags, lpInfo)
; hWnd : HWND -> "sptr"
; uFlags : UINT_PTR -> "sptr"
; lpInfo : INT* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL ShowHideMenuCtl(HWND hWnd, UINT_PTR uFlags, INT* lpInfo)
#uselib "COMCTL32.dll"
#cfunc global ShowHideMenuCtl "ShowHideMenuCtl" intptr, intptr, var
; res = ShowHideMenuCtl(hWnd, uFlags, lpInfo)
; hWnd : HWND -> "intptr"
; uFlags : UINT_PTR -> "intptr"
; lpInfo : INT* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	comctl32 = windows.NewLazySystemDLL("COMCTL32.dll")
	procShowHideMenuCtl = comctl32.NewProc("ShowHideMenuCtl")
)

// hWnd (HWND), uFlags (UINT_PTR), lpInfo (INT*)
r1, _, err := procShowHideMenuCtl.Call(
	uintptr(hWnd),
	uintptr(uFlags),
	uintptr(lpInfo),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function ShowHideMenuCtl(
  hWnd: THandle;   // HWND
  uFlags: NativeUInt;   // UINT_PTR
  lpInfo: Pointer   // INT*
): BOOL; stdcall;
  external 'COMCTL32.dll' name 'ShowHideMenuCtl';
result := DllCall("COMCTL32\ShowHideMenuCtl"
    , "Ptr", hWnd   ; HWND
    , "UPtr", uFlags   ; UINT_PTR
    , "Ptr", lpInfo   ; INT*
    , "Int")   ; return: BOOL
●ShowHideMenuCtl(hWnd, uFlags, lpInfo) = DLL("COMCTL32.dll", "bool ShowHideMenuCtl(void*, int, void*)")
# 呼び出し: ShowHideMenuCtl(hWnd, uFlags, lpInfo)
# hWnd : HWND -> "void*"
# uFlags : UINT_PTR -> "int"
# lpInfo : INT* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "comctl32" fn ShowHideMenuCtl(
    hWnd: ?*anyopaque, // HWND
    uFlags: usize, // UINT_PTR
    lpInfo: [*c]i32 // INT*
) callconv(std.os.windows.WINAPI) i32;
proc ShowHideMenuCtl(
    hWnd: pointer,  # HWND
    uFlags: uint,  # UINT_PTR
    lpInfo: ptr int32  # INT*
): int32 {.importc: "ShowHideMenuCtl", stdcall, dynlib: "COMCTL32.dll".}
pragma(lib, "comctl32");
extern(Windows)
int ShowHideMenuCtl(
    void* hWnd,   // HWND
    size_t uFlags,   // UINT_PTR
    int* lpInfo   // INT*
);
ccall((:ShowHideMenuCtl, "COMCTL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Csize_t, Ptr{Int32}),
      hWnd, uFlags, lpInfo)
# hWnd : HWND -> Ptr{Cvoid}
# uFlags : UINT_PTR -> Csize_t
# lpInfo : INT* -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ShowHideMenuCtl(
    void* hWnd,
    uintptr_t uFlags,
    int32_t* lpInfo);
]]
local comctl32 = ffi.load("comctl32")
-- comctl32.ShowHideMenuCtl(hWnd, uFlags, lpInfo)
-- hWnd : HWND
-- uFlags : UINT_PTR
-- lpInfo : INT*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('COMCTL32.dll');
const ShowHideMenuCtl = lib.func('__stdcall', 'ShowHideMenuCtl', 'int32_t', ['void *', 'uintptr_t', 'int32_t *']);
// ShowHideMenuCtl(hWnd, uFlags, lpInfo)
// hWnd : HWND -> 'void *'
// uFlags : UINT_PTR -> 'uintptr_t'
// lpInfo : INT* -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("COMCTL32.dll", {
  ShowHideMenuCtl: { parameters: ["pointer", "usize", "pointer"], result: "i32" },
});
// lib.symbols.ShowHideMenuCtl(hWnd, uFlags, lpInfo)
// hWnd : HWND -> "pointer"
// uFlags : UINT_PTR -> "usize"
// lpInfo : INT* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ShowHideMenuCtl(
    void* hWnd,
    size_t uFlags,
    int32_t* lpInfo);
C, "COMCTL32.dll");
// $ffi->ShowHideMenuCtl(hWnd, uFlags, lpInfo);
// hWnd : HWND
// uFlags : UINT_PTR
// lpInfo : INT*
// 構造体/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 Comctl32 extends StdCallLibrary {
    Comctl32 INSTANCE = Native.load("comctl32", Comctl32.class);
    boolean ShowHideMenuCtl(
        Pointer hWnd,   // HWND
        long uFlags,   // UINT_PTR
        IntByReference lpInfo   // INT*
    );
}
@[Link("comctl32")]
lib LibCOMCTL32
  fun ShowHideMenuCtl = ShowHideMenuCtl(
    hWnd : Void*,   # HWND
    uFlags : LibC::SizeT,   # UINT_PTR
    lpInfo : Int32*   # INT*
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ShowHideMenuCtlNative = Int32 Function(Pointer<Void>, UintPtr, Pointer<Int32>);
typedef ShowHideMenuCtlDart = int Function(Pointer<Void>, int, Pointer<Int32>);
final ShowHideMenuCtl = DynamicLibrary.open('COMCTL32.dll')
    .lookupFunction<ShowHideMenuCtlNative, ShowHideMenuCtlDart>('ShowHideMenuCtl');
// hWnd : HWND -> Pointer<Void>
// uFlags : UINT_PTR -> UintPtr
// lpInfo : INT* -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ShowHideMenuCtl(
  hWnd: THandle;   // HWND
  uFlags: NativeUInt;   // UINT_PTR
  lpInfo: Pointer   // INT*
): BOOL; stdcall;
  external 'COMCTL32.dll' name 'ShowHideMenuCtl';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ShowHideMenuCtl"
  c_ShowHideMenuCtl :: Ptr () -> CUIntPtr -> Ptr Int32 -> IO CInt
-- hWnd : HWND -> Ptr ()
-- uFlags : UINT_PTR -> CUIntPtr
-- lpInfo : INT* -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let showhidemenuctl =
  foreign "ShowHideMenuCtl"
    ((ptr void) @-> size_t @-> (ptr int32_t) @-> returning int32_t)
(* hWnd : HWND -> (ptr void) *)
(* uFlags : UINT_PTR -> size_t *)
(* lpInfo : INT* -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library comctl32 (t "COMCTL32.dll"))
(cffi:use-foreign-library comctl32)

(cffi:defcfun ("ShowHideMenuCtl" show-hide-menu-ctl :convention :stdcall) :int32
  (h-wnd :pointer)   ; HWND
  (u-flags :uint64)   ; UINT_PTR
  (lp-info :pointer))   ; INT*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ShowHideMenuCtl = Win32::API::More->new('COMCTL32',
    'BOOL ShowHideMenuCtl(HANDLE hWnd, WPARAM uFlags, LPVOID lpInfo)');
# my $ret = $ShowHideMenuCtl->Call($hWnd, $uFlags, $lpInfo);
# hWnd : HWND -> HANDLE
# uFlags : UINT_PTR -> WPARAM
# lpInfo : INT* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。