Win32 API 日本語リファレンス
ホームStorage.Xps › PrintWindow

PrintWindow

関数
指定ウィンドウの内容をデバイスコンテキストへコピー(描画)する。
DLLUSER32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

BOOL PrintWindow(
    HWND hwnd,
    HDC hdcBlt,
    PRINT_WINDOW_FLAGS nFlags
);

パラメーター

名前方向
hwndHWNDin
hdcBltHDCin
nFlagsPRINT_WINDOW_FLAGSin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

PrintWindow = ctypes.windll.user32.PrintWindow
PrintWindow.restype = wintypes.BOOL
PrintWindow.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND
    wintypes.HANDLE,  # hdcBlt : HDC
    wintypes.DWORD,  # nFlags : PRINT_WINDOW_FLAGS
]
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procPrintWindow = user32.NewProc("PrintWindow")
)

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