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

ShowWindowAsync

関数
別スレッドのウィンドウ表示状態を非同期に設定する。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL ShowWindowAsync(
    HWND hWnd,
    SHOW_WINDOW_CMD nCmdShow
);

パラメーター

名前方向
hWndHWNDin
nCmdShowSHOW_WINDOW_CMDin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

ShowWindowAsync = ctypes.windll.user32.ShowWindowAsync
ShowWindowAsync.restype = wintypes.BOOL
ShowWindowAsync.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    ctypes.c_int,  # nCmdShow : SHOW_WINDOW_CMD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procShowWindowAsync = user32.NewProc("ShowWindowAsync")
)

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