ホーム › Storage.Xps › PrintWindow
PrintWindow
関数指定ウィンドウの内容をデバイスコンテキストへコピー(描画)する。
シグネチャ
// USER32.dll
#include <windows.h>
BOOL PrintWindow(
HWND hwnd,
HDC hdcBlt,
PRINT_WINDOW_FLAGS nFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwnd | HWND | in | コピー対象のウィンドウのハンドル。クライアント領域を含むウィンドウ全体を描画する。 |
| hdcBlt | HDC | in | 描画先のデバイスコンテキストのハンドル。通常はメモリDCを指定する。 |
| nFlags | PRINT_WINDOW_FLAGS | in | 描画範囲を制御するPRINT_WINDOW_FLAGS値。クライアント領域のみやレンダリング全体などを指定する。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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)。const std = @import("std");
extern "user32" fn PrintWindow(
hwnd: ?*anyopaque, // HWND
hdcBlt: ?*anyopaque, // HDC
nFlags: u32 // PRINT_WINDOW_FLAGS
) callconv(std.os.windows.WINAPI) i32;proc PrintWindow(
hwnd: pointer, # HWND
hdcBlt: pointer, # HDC
nFlags: uint32 # PRINT_WINDOW_FLAGS
): int32 {.importc: "PrintWindow", stdcall, dynlib: "USER32.dll".}pragma(lib, "user32");
extern(Windows)
int PrintWindow(
void* hwnd, // HWND
void* hdcBlt, // HDC
uint nFlags // PRINT_WINDOW_FLAGS
);ccall((:PrintWindow, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, UInt32),
hwnd, hdcBlt, nFlags)
# hwnd : HWND -> Ptr{Cvoid}
# hdcBlt : HDC -> Ptr{Cvoid}
# nFlags : PRINT_WINDOW_FLAGS -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PrintWindow(
void* hwnd,
void* hdcBlt,
uint32_t nFlags);
]]
local user32 = ffi.load("user32")
-- user32.PrintWindow(hwnd, hdcBlt, nFlags)
-- hwnd : HWND
-- hdcBlt : HDC
-- nFlags : PRINT_WINDOW_FLAGS
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const PrintWindow = lib.func('__stdcall', 'PrintWindow', 'int32_t', ['void *', 'void *', 'uint32_t']);
// PrintWindow(hwnd, hdcBlt, nFlags)
// hwnd : HWND -> 'void *'
// hdcBlt : HDC -> 'void *'
// nFlags : PRINT_WINDOW_FLAGS -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
PrintWindow: { parameters: ["pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.PrintWindow(hwnd, hdcBlt, nFlags)
// hwnd : HWND -> "pointer"
// hdcBlt : HDC -> "pointer"
// nFlags : PRINT_WINDOW_FLAGS -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PrintWindow(
void* hwnd,
void* hdcBlt,
uint32_t nFlags);
C, "USER32.dll");
// $ffi->PrintWindow(hwnd, hdcBlt, nFlags);
// hwnd : HWND
// hdcBlt : HDC
// nFlags : PRINT_WINDOW_FLAGS
// 構造体/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 User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class);
boolean PrintWindow(
Pointer hwnd, // HWND
Pointer hdcBlt, // HDC
int nFlags // PRINT_WINDOW_FLAGS
);
}@[Link("user32")]
lib LibUSER32
fun PrintWindow = PrintWindow(
hwnd : Void*, # HWND
hdcBlt : Void*, # HDC
nFlags : UInt32 # PRINT_WINDOW_FLAGS
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PrintWindowNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32);
typedef PrintWindowDart = int Function(Pointer<Void>, Pointer<Void>, int);
final PrintWindow = DynamicLibrary.open('USER32.dll')
.lookupFunction<PrintWindowNative, PrintWindowDart>('PrintWindow');
// hwnd : HWND -> Pointer<Void>
// hdcBlt : HDC -> Pointer<Void>
// nFlags : PRINT_WINDOW_FLAGS -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PrintWindow(
hwnd: THandle; // HWND
hdcBlt: THandle; // HDC
nFlags: DWORD // PRINT_WINDOW_FLAGS
): BOOL; stdcall;
external 'USER32.dll' name 'PrintWindow';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PrintWindow"
c_PrintWindow :: Ptr () -> Ptr () -> Word32 -> IO CInt
-- hwnd : HWND -> Ptr ()
-- hdcBlt : HDC -> Ptr ()
-- nFlags : PRINT_WINDOW_FLAGS -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let printwindow =
foreign "PrintWindow"
((ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hwnd : HWND -> (ptr void) *)
(* hdcBlt : HDC -> (ptr void) *)
(* nFlags : PRINT_WINDOW_FLAGS -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("PrintWindow" print-window :convention :stdcall) :int32
(hwnd :pointer) ; HWND
(hdc-blt :pointer) ; HDC
(n-flags :uint32)) ; PRINT_WINDOW_FLAGS
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PrintWindow = Win32::API::More->new('USER32',
'BOOL PrintWindow(HANDLE hwnd, HANDLE hdcBlt, DWORD nFlags)');
# my $ret = $PrintWindow->Call($hwnd, $hdcBlt, $nFlags);
# hwnd : HWND -> HANDLE
# hdcBlt : HDC -> HANDLE
# nFlags : PRINT_WINDOW_FLAGS -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型