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

GetCurrentObject

関数
DCで現在選択中のGDIオブジェクトを取得する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HGDIOBJ GetCurrentObject(
    HDC hdc,
    DWORD type
);

パラメーター

名前方向
hdcHDCin
typeDWORDin

戻り値の型: HGDIOBJ

各言語での呼び出し定義

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

HGDIOBJ GetCurrentObject(
    HDC hdc,
    DWORD type
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern IntPtr GetCurrentObject(
    IntPtr hdc,   // HDC
    uint type   // DWORD
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetCurrentObject(
    hdc As IntPtr,   ' HDC
    type As UInteger   ' DWORD
) As IntPtr
End Function
' hdc : HDC
' type : DWORD
Declare PtrSafe Function GetCurrentObject Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal type As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetCurrentObject = ctypes.windll.gdi32.GetCurrentObject
GetCurrentObject.restype = ctypes.c_void_p
GetCurrentObject.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.DWORD,  # type : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetCurrentObject = gdi32.NewProc("GetCurrentObject")
)

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