ホーム › UI.WindowsAndMessaging › SetMenu
SetMenu
関数指定ウィンドウにメニューを割り当てる。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL SetMenu(
HWND hWnd,
HMENU hMenu // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hWnd | HWND | in |
| hMenu | HMENU | inoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
BOOL SetMenu(
HWND hWnd,
HMENU hMenu // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetMenu(
IntPtr hWnd, // HWND
IntPtr hMenu // HMENU optional
);<DllImport("USER32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetMenu(
hWnd As IntPtr, ' HWND
hMenu As IntPtr ' HMENU optional
) As Boolean
End Function' hWnd : HWND
' hMenu : HMENU optional
Declare PtrSafe Function SetMenu Lib "user32" ( _
ByVal hWnd As LongPtr, _
ByVal hMenu As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetMenu = ctypes.windll.user32.SetMenu
SetMenu.restype = wintypes.BOOL
SetMenu.argtypes = [
wintypes.HANDLE, # hWnd : HWND
wintypes.HANDLE, # hMenu : HMENU optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
SetMenu = Fiddle::Function.new(
lib['SetMenu'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
Fiddle::TYPE_VOIDP, # hMenu : HMENU optional
],
Fiddle::TYPE_INT)#[link(name = "user32")]
extern "system" {
fn SetMenu(
hWnd: *mut core::ffi::c_void, // HWND
hMenu: *mut core::ffi::c_void // HMENU optional
) -> 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 SetMenu(IntPtr hWnd, IntPtr hMenu);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetMenu' -Namespace Win32 -PassThru
# $api::SetMenu(hWnd, hMenu)#uselib "USER32.dll"
#func global SetMenu "SetMenu" sptr, sptr
; SetMenu hWnd, hMenu ; 戻り値は stat
; hWnd : HWND -> "sptr"
; hMenu : HMENU optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global SetMenu "SetMenu" sptr, sptr
; res = SetMenu(hWnd, hMenu)
; hWnd : HWND -> "sptr"
; hMenu : HMENU optional -> "sptr"; BOOL SetMenu(HWND hWnd, HMENU hMenu)
#uselib "USER32.dll"
#cfunc global SetMenu "SetMenu" intptr, intptr
; res = SetMenu(hWnd, hMenu)
; hWnd : HWND -> "intptr"
; hMenu : HMENU optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procSetMenu = user32.NewProc("SetMenu")
)
// hWnd (HWND), hMenu (HMENU optional)
r1, _, err := procSetMenu.Call(
uintptr(hWnd),
uintptr(hMenu),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetMenu(
hWnd: THandle; // HWND
hMenu: THandle // HMENU optional
): BOOL; stdcall;
external 'USER32.dll' name 'SetMenu';result := DllCall("USER32\SetMenu"
, "Ptr", hWnd ; HWND
, "Ptr", hMenu ; HMENU optional
, "Int") ; return: BOOL●SetMenu(hWnd, hMenu) = DLL("USER32.dll", "bool SetMenu(void*, void*)")
# 呼び出し: SetMenu(hWnd, hMenu)
# hWnd : HWND -> "void*"
# hMenu : HMENU optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。