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

AllowSetForegroundWindow

関数
指定プロセスに前面化を許可する権限を与える。
DLLUSER32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL AllowSetForegroundWindow(
    DWORD dwProcessId
);

パラメーター

名前方向
dwProcessIdDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

AllowSetForegroundWindow = ctypes.windll.user32.AllowSetForegroundWindow
AllowSetForegroundWindow.restype = wintypes.BOOL
AllowSetForegroundWindow.argtypes = [
    wintypes.DWORD,  # dwProcessId : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procAllowSetForegroundWindow = user32.NewProc("AllowSetForegroundWindow")
)

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