Win32 API 日本語リファレンス
ホームGraphics.Gdi › GetDCEx

GetDCEx

関数
クリップ領域やフラグを指定してウィンドウのデバイスコンテキストを取得する。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HDC GetDCEx(
    HWND hWnd,   // optional
    HRGN hrgnClip,   // optional
    GET_DCX_FLAGS flags
);

パラメーター

名前方向
hWndHWNDinoptional
hrgnClipHRGNinoptional
flagsGET_DCX_FLAGSin

戻り値の型: HDC

各言語での呼び出し定義

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

HDC GetDCEx(
    HWND hWnd,   // optional
    HRGN hrgnClip,   // optional
    GET_DCX_FLAGS flags
);
[DllImport("USER32.dll", ExactSpelling = true)]
static extern IntPtr GetDCEx(
    IntPtr hWnd,   // HWND optional
    IntPtr hrgnClip,   // HRGN optional
    uint flags   // GET_DCX_FLAGS
);
<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function GetDCEx(
    hWnd As IntPtr,   ' HWND optional
    hrgnClip As IntPtr,   ' HRGN optional
    flags As UInteger   ' GET_DCX_FLAGS
) As IntPtr
End Function
' hWnd : HWND optional
' hrgnClip : HRGN optional
' flags : GET_DCX_FLAGS
Declare PtrSafe Function GetDCEx Lib "user32" ( _
    ByVal hWnd As LongPtr, _
    ByVal hrgnClip As LongPtr, _
    ByVal flags As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetDCEx = ctypes.windll.user32.GetDCEx
GetDCEx.restype = ctypes.c_void_p
GetDCEx.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND optional
    wintypes.HANDLE,  # hrgnClip : HRGN optional
    wintypes.DWORD,  # flags : GET_DCX_FLAGS
]
require 'fiddle'
require 'fiddle/import'

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

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procGetDCEx = user32.NewProc("GetDCEx")
)

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