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

DrawCaption

関数
ウィンドウのタイトルバー(キャプション)を描画する。
DLLUSER32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

BOOL DrawCaption(
    HWND hwnd,
    HDC hdc,
    const RECT* lprect,
    DRAW_CAPTION_FLAGS flags
);

パラメーター

名前方向説明
hwndHWNDinウィンドウキャプションのテキストとアイコンを提供するウィンドウへのハンドル。
hdcHDCinデバイスコンテキストへのハンドル。関数はこのデバイスコンテキストにウィンドウキャプションを描画します。
lprectRECT*inウィンドウキャプションの境界矩形を論理座標で指定する RECT 構造体へのポインター。
flagsDRAW_CAPTION_FLAGSin

描画オプション。このパラメーターには、次の値のうち 0 個以上を指定できます。

意味
DC_ACTIVE
アクティブなキャプションを示す色を使用します。
DC_BUTTONS
設定すると、関数はキャプションバーにボタン (アプリケーションの最小化、元のサイズに戻す、または閉じるためのボタン) を描画します。
DC_GRADIENT
このフラグを設定すると、関数はタイトルバーの色として COLOR_GRADIENTACTIVECAPTION (DC_ACTIVE フラグが設定されている場合) または COLOR_GRADIENTINACTIVECAPTION を使用します。

このフラグが設定されていない場合、関数は両方の色に COLOR_ACTIVECAPTION または COLOR_INACTIVECAPTION を使用します。

DC_ICON
キャプションテキストの描画時にアイコンを描画します。
DC_INBUTTON
キャプションをボタンとして描画します。
DC_SMALLCAP
現在の小さいキャプションフォントを使用して、小さいキャプションを描画します。
DC_TEXT
キャプションの描画時にキャプションテキストを描画します。

DC_SMALLCAP が指定されている場合、関数は通常のウィンドウキャプションを描画します。

戻り値の型: BOOL

公式ドキュメント

DrawCaption 関数は、ウィンドウのキャプションを描画します。

戻り値

関数が成功した場合、戻り値は 0 以外の値になります。

関数が失敗した場合、戻り値は 0 になります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

DrawCaption = ctypes.windll.user32.DrawCaption
DrawCaption.restype = wintypes.BOOL
DrawCaption.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_void_p,  # lprect : RECT*
    wintypes.DWORD,  # flags : DRAW_CAPTION_FLAGS
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
DrawCaption = Fiddle::Function.new(
  lib['DrawCaption'],
  [
    Fiddle::TYPE_VOIDP,  # hwnd : HWND
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # lprect : RECT*
    -Fiddle::TYPE_INT,  # flags : DRAW_CAPTION_FLAGS
  ],
  Fiddle::TYPE_INT)
#[link(name = "user32")]
extern "system" {
    fn DrawCaption(
        hwnd: *mut core::ffi::c_void,  // HWND
        hdc: *mut core::ffi::c_void,  // HDC
        lprect: *const RECT,  // RECT*
        flags: u32  // DRAW_CAPTION_FLAGS
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll")]
public static extern bool DrawCaption(IntPtr hwnd, IntPtr hdc, IntPtr lprect, uint flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DrawCaption' -Namespace Win32 -PassThru
# $api::DrawCaption(hwnd, hdc, lprect, flags)
#uselib "USER32.dll"
#func global DrawCaption "DrawCaption" sptr, sptr, sptr, sptr
; DrawCaption hwnd, hdc, varptr(lprect), flags   ; 戻り値は stat
; hwnd : HWND -> "sptr"
; hdc : HDC -> "sptr"
; lprect : RECT* -> "sptr"
; flags : DRAW_CAPTION_FLAGS -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global DrawCaption "DrawCaption" sptr, sptr, var, int
; res = DrawCaption(hwnd, hdc, lprect, flags)
; hwnd : HWND -> "sptr"
; hdc : HDC -> "sptr"
; lprect : RECT* -> "var"
; flags : DRAW_CAPTION_FLAGS -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL DrawCaption(HWND hwnd, HDC hdc, RECT* lprect, DRAW_CAPTION_FLAGS flags)
#uselib "USER32.dll"
#cfunc global DrawCaption "DrawCaption" intptr, intptr, var, int
; res = DrawCaption(hwnd, hdc, lprect, flags)
; hwnd : HWND -> "intptr"
; hdc : HDC -> "intptr"
; lprect : RECT* -> "var"
; flags : DRAW_CAPTION_FLAGS -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procDrawCaption = user32.NewProc("DrawCaption")
)

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

extern "user32" fn DrawCaption(
    hwnd: ?*anyopaque, // HWND
    hdc: ?*anyopaque, // HDC
    lprect: [*c]RECT, // RECT*
    flags: u32 // DRAW_CAPTION_FLAGS
) callconv(std.os.windows.WINAPI) i32;
proc DrawCaption(
    hwnd: pointer,  # HWND
    hdc: pointer,  # HDC
    lprect: ptr RECT,  # RECT*
    flags: uint32  # DRAW_CAPTION_FLAGS
): int32 {.importc: "DrawCaption", stdcall, dynlib: "USER32.dll".}
pragma(lib, "user32");
extern(Windows)
int DrawCaption(
    void* hwnd,   // HWND
    void* hdc,   // HDC
    RECT* lprect,   // RECT*
    uint flags   // DRAW_CAPTION_FLAGS
);
ccall((:DrawCaption, "USER32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{RECT}, UInt32),
      hwnd, hdc, lprect, flags)
# hwnd : HWND -> Ptr{Cvoid}
# hdc : HDC -> Ptr{Cvoid}
# lprect : RECT* -> Ptr{RECT}
# flags : DRAW_CAPTION_FLAGS -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t DrawCaption(
    void* hwnd,
    void* hdc,
    void* lprect,
    uint32_t flags);
]]
local user32 = ffi.load("user32")
-- user32.DrawCaption(hwnd, hdc, lprect, flags)
-- hwnd : HWND
-- hdc : HDC
-- lprect : RECT*
-- flags : DRAW_CAPTION_FLAGS
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const DrawCaption = lib.func('__stdcall', 'DrawCaption', 'int32_t', ['void *', 'void *', 'void *', 'uint32_t']);
// DrawCaption(hwnd, hdc, lprect, flags)
// hwnd : HWND -> 'void *'
// hdc : HDC -> 'void *'
// lprect : RECT* -> 'void *'
// flags : DRAW_CAPTION_FLAGS -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USER32.dll", {
  DrawCaption: { parameters: ["pointer", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.DrawCaption(hwnd, hdc, lprect, flags)
// hwnd : HWND -> "pointer"
// hdc : HDC -> "pointer"
// lprect : RECT* -> "pointer"
// flags : DRAW_CAPTION_FLAGS -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DrawCaption(
    void* hwnd,
    void* hdc,
    void* lprect,
    uint32_t flags);
C, "USER32.dll");
// $ffi->DrawCaption(hwnd, hdc, lprect, flags);
// hwnd : HWND
// hdc : HDC
// lprect : RECT*
// flags : DRAW_CAPTION_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 DrawCaption(
        Pointer hwnd,   // HWND
        Pointer hdc,   // HDC
        Pointer lprect,   // RECT*
        int flags   // DRAW_CAPTION_FLAGS
    );
}
@[Link("user32")]
lib LibUSER32
  fun DrawCaption = DrawCaption(
    hwnd : Void*,   # HWND
    hdc : Void*,   # HDC
    lprect : RECT*,   # RECT*
    flags : UInt32   # DRAW_CAPTION_FLAGS
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef DrawCaptionNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32);
typedef DrawCaptionDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int);
final DrawCaption = DynamicLibrary.open('USER32.dll')
    .lookupFunction<DrawCaptionNative, DrawCaptionDart>('DrawCaption');
// hwnd : HWND -> Pointer<Void>
// hdc : HDC -> Pointer<Void>
// lprect : RECT* -> Pointer<Void>
// flags : DRAW_CAPTION_FLAGS -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DrawCaption(
  hwnd: THandle;   // HWND
  hdc: THandle;   // HDC
  lprect: Pointer;   // RECT*
  flags: DWORD   // DRAW_CAPTION_FLAGS
): BOOL; stdcall;
  external 'USER32.dll' name 'DrawCaption';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DrawCaption"
  c_DrawCaption :: Ptr () -> Ptr () -> Ptr () -> Word32 -> IO CInt
-- hwnd : HWND -> Ptr ()
-- hdc : HDC -> Ptr ()
-- lprect : RECT* -> Ptr ()
-- flags : DRAW_CAPTION_FLAGS -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let drawcaption =
  foreign "DrawCaption"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hwnd : HWND -> (ptr void) *)
(* hdc : HDC -> (ptr void) *)
(* lprect : RECT* -> (ptr void) *)
(* flags : DRAW_CAPTION_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 ("DrawCaption" draw-caption :convention :stdcall) :int32
  (hwnd :pointer)   ; HWND
  (hdc :pointer)   ; HDC
  (lprect :pointer)   ; RECT*
  (flags :uint32))   ; DRAW_CAPTION_FLAGS
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DrawCaption = Win32::API::More->new('USER32',
    'BOOL DrawCaption(HANDLE hwnd, HANDLE hdc, LPVOID lprect, DWORD flags)');
# my $ret = $DrawCaption->Call($hwnd, $hdc, $lprect, $flags);
# hwnd : HWND -> HANDLE
# hdc : HDC -> HANDLE
# lprect : RECT* -> LPVOID
# flags : DRAW_CAPTION_FLAGS -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型