Win32 API 日本語リファレンス
ホームUI.Controls › DrawShadowText

DrawShadowText

関数
影付きのテキストを指定矩形に描画する。
DLLCOMCTL32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

INT DrawShadowText(
    HDC hdc,
    LPCWSTR pszText,
    DWORD cch,
    RECT* prc,
    DWORD dwFlags,
    COLORREF crText,
    COLORREF crShadow,
    INT ixOffset,
    INT iyOffset
);

パラメーター

名前方向説明
hdcHDCinHDC。
pszTextLPCWSTRin描画するテキストを格納した文字列へのポインターです。
cchDWORDin描画する文字列内の文字数を指定する UINT です。
prcRECT*inテキストを描画する矩形を論理座標で格納した RECT 構造体へのポインターです。
dwFlagsDWORDinテキストの描画方法を指定する DWORD です。指定可能なパラメーター値については、Format Values を参照してください。
crTextCOLORREFinテキストの色を格納した COLORREF 構造体です。
crShadowCOLORREFinテキストの影の色を格納した COLORREF 構造体です。
ixOffsetINTinテキストの描画を開始する x 座標を指定する int 型の値です。
iyOffsetINTinテキストの描画を開始する y 座標を指定する int 型の値です。

戻り値の型: INT

公式ドキュメント

影付きのテキストを描画します。

戻り値

型: int

関数が成功した場合は、テキストの高さを論理単位で返します。それ以外の場合は 0 を返します。

解説(Remarks)

DrawShadowText を使用するには、マニフェストで Comctl32.dll バージョン 6 を指定します。マニフェストの詳細については、Enabling Visual Styles を参照してください。

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

各言語での呼び出し定義

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

INT DrawShadowText(
    HDC hdc,
    LPCWSTR pszText,
    DWORD cch,
    RECT* prc,
    DWORD dwFlags,
    COLORREF crText,
    COLORREF crShadow,
    INT ixOffset,
    INT iyOffset
);
[DllImport("COMCTL32.dll", ExactSpelling = true)]
static extern int DrawShadowText(
    IntPtr hdc,   // HDC
    [MarshalAs(UnmanagedType.LPWStr)] string pszText,   // LPCWSTR
    uint cch,   // DWORD
    IntPtr prc,   // RECT*
    uint dwFlags,   // DWORD
    uint crText,   // COLORREF
    uint crShadow,   // COLORREF
    int ixOffset,   // INT
    int iyOffset   // INT
);
<DllImport("COMCTL32.dll", ExactSpelling:=True)>
Public Shared Function DrawShadowText(
    hdc As IntPtr,   ' HDC
    <MarshalAs(UnmanagedType.LPWStr)> pszText As String,   ' LPCWSTR
    cch As UInteger,   ' DWORD
    prc As IntPtr,   ' RECT*
    dwFlags As UInteger,   ' DWORD
    crText As UInteger,   ' COLORREF
    crShadow As UInteger,   ' COLORREF
    ixOffset As Integer,   ' INT
    iyOffset As Integer   ' INT
) As Integer
End Function
' hdc : HDC
' pszText : LPCWSTR
' cch : DWORD
' prc : RECT*
' dwFlags : DWORD
' crText : COLORREF
' crShadow : COLORREF
' ixOffset : INT
' iyOffset : INT
Declare PtrSafe Function DrawShadowText Lib "comctl32" ( _
    ByVal hdc As LongPtr, _
    ByVal pszText As LongPtr, _
    ByVal cch As Long, _
    ByVal prc As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal crText As Long, _
    ByVal crShadow As Long, _
    ByVal ixOffset As Long, _
    ByVal iyOffset As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DrawShadowText = ctypes.windll.comctl32.DrawShadowText
DrawShadowText.restype = ctypes.c_int
DrawShadowText.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.LPCWSTR,  # pszText : LPCWSTR
    wintypes.DWORD,  # cch : DWORD
    ctypes.c_void_p,  # prc : RECT*
    wintypes.DWORD,  # dwFlags : DWORD
    wintypes.DWORD,  # crText : COLORREF
    wintypes.DWORD,  # crShadow : COLORREF
    ctypes.c_int,  # ixOffset : INT
    ctypes.c_int,  # iyOffset : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('COMCTL32.dll')
DrawShadowText = Fiddle::Function.new(
  lib['DrawShadowText'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # pszText : LPCWSTR
    -Fiddle::TYPE_INT,  # cch : DWORD
    Fiddle::TYPE_VOIDP,  # prc : RECT*
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    -Fiddle::TYPE_INT,  # crText : COLORREF
    -Fiddle::TYPE_INT,  # crShadow : COLORREF
    Fiddle::TYPE_INT,  # ixOffset : INT
    Fiddle::TYPE_INT,  # iyOffset : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "comctl32")]
extern "system" {
    fn DrawShadowText(
        hdc: *mut core::ffi::c_void,  // HDC
        pszText: *const u16,  // LPCWSTR
        cch: u32,  // DWORD
        prc: *mut RECT,  // RECT*
        dwFlags: u32,  // DWORD
        crText: u32,  // COLORREF
        crShadow: u32,  // COLORREF
        ixOffset: i32,  // INT
        iyOffset: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("COMCTL32.dll")]
public static extern int DrawShadowText(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] string pszText, uint cch, IntPtr prc, uint dwFlags, uint crText, uint crShadow, int ixOffset, int iyOffset);
"@
$api = Add-Type -MemberDefinition $sig -Name 'COMCTL32_DrawShadowText' -Namespace Win32 -PassThru
# $api::DrawShadowText(hdc, pszText, cch, prc, dwFlags, crText, crShadow, ixOffset, iyOffset)
#uselib "COMCTL32.dll"
#func global DrawShadowText "DrawShadowText" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DrawShadowText hdc, pszText, cch, varptr(prc), dwFlags, crText, crShadow, ixOffset, iyOffset   ; 戻り値は stat
; hdc : HDC -> "sptr"
; pszText : LPCWSTR -> "sptr"
; cch : DWORD -> "sptr"
; prc : RECT* -> "sptr"
; dwFlags : DWORD -> "sptr"
; crText : COLORREF -> "sptr"
; crShadow : COLORREF -> "sptr"
; ixOffset : INT -> "sptr"
; iyOffset : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "COMCTL32.dll"
#cfunc global DrawShadowText "DrawShadowText" sptr, wstr, int, var, int, int, int, int, int
; res = DrawShadowText(hdc, pszText, cch, prc, dwFlags, crText, crShadow, ixOffset, iyOffset)
; hdc : HDC -> "sptr"
; pszText : LPCWSTR -> "wstr"
; cch : DWORD -> "int"
; prc : RECT* -> "var"
; dwFlags : DWORD -> "int"
; crText : COLORREF -> "int"
; crShadow : COLORREF -> "int"
; ixOffset : INT -> "int"
; iyOffset : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT DrawShadowText(HDC hdc, LPCWSTR pszText, DWORD cch, RECT* prc, DWORD dwFlags, COLORREF crText, COLORREF crShadow, INT ixOffset, INT iyOffset)
#uselib "COMCTL32.dll"
#cfunc global DrawShadowText "DrawShadowText" intptr, wstr, int, var, int, int, int, int, int
; res = DrawShadowText(hdc, pszText, cch, prc, dwFlags, crText, crShadow, ixOffset, iyOffset)
; hdc : HDC -> "intptr"
; pszText : LPCWSTR -> "wstr"
; cch : DWORD -> "int"
; prc : RECT* -> "var"
; dwFlags : DWORD -> "int"
; crText : COLORREF -> "int"
; crShadow : COLORREF -> "int"
; ixOffset : INT -> "int"
; iyOffset : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	comctl32 = windows.NewLazySystemDLL("COMCTL32.dll")
	procDrawShadowText = comctl32.NewProc("DrawShadowText")
)

// hdc (HDC), pszText (LPCWSTR), cch (DWORD), prc (RECT*), dwFlags (DWORD), crText (COLORREF), crShadow (COLORREF), ixOffset (INT), iyOffset (INT)
r1, _, err := procDrawShadowText.Call(
	uintptr(hdc),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszText))),
	uintptr(cch),
	uintptr(prc),
	uintptr(dwFlags),
	uintptr(crText),
	uintptr(crShadow),
	uintptr(ixOffset),
	uintptr(iyOffset),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function DrawShadowText(
  hdc: THandle;   // HDC
  pszText: PWideChar;   // LPCWSTR
  cch: DWORD;   // DWORD
  prc: Pointer;   // RECT*
  dwFlags: DWORD;   // DWORD
  crText: DWORD;   // COLORREF
  crShadow: DWORD;   // COLORREF
  ixOffset: Integer;   // INT
  iyOffset: Integer   // INT
): Integer; stdcall;
  external 'COMCTL32.dll' name 'DrawShadowText';
result := DllCall("COMCTL32\DrawShadowText"
    , "Ptr", hdc   ; HDC
    , "WStr", pszText   ; LPCWSTR
    , "UInt", cch   ; DWORD
    , "Ptr", prc   ; RECT*
    , "UInt", dwFlags   ; DWORD
    , "UInt", crText   ; COLORREF
    , "UInt", crShadow   ; COLORREF
    , "Int", ixOffset   ; INT
    , "Int", iyOffset   ; INT
    , "Int")   ; return: INT
●DrawShadowText(hdc, pszText, cch, prc, dwFlags, crText, crShadow, ixOffset, iyOffset) = DLL("COMCTL32.dll", "int DrawShadowText(void*, char*, dword, void*, dword, dword, dword, int, int)")
# 呼び出し: DrawShadowText(hdc, pszText, cch, prc, dwFlags, crText, crShadow, ixOffset, iyOffset)
# hdc : HDC -> "void*"
# pszText : LPCWSTR -> "char*"
# cch : DWORD -> "dword"
# prc : RECT* -> "void*"
# dwFlags : DWORD -> "dword"
# crText : COLORREF -> "dword"
# crShadow : COLORREF -> "dword"
# ixOffset : INT -> "int"
# iyOffset : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef DrawShadowTextNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Void>, Uint32, Uint32, Uint32, Int32, Int32);
typedef DrawShadowTextDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>, int, int, int, int, int);
final DrawShadowText = DynamicLibrary.open('COMCTL32.dll')
    .lookupFunction<DrawShadowTextNative, DrawShadowTextDart>('DrawShadowText');
// hdc : HDC -> Pointer<Void>
// pszText : LPCWSTR -> Pointer<Utf16>
// cch : DWORD -> Uint32
// prc : RECT* -> Pointer<Void>
// dwFlags : DWORD -> Uint32
// crText : COLORREF -> Uint32
// crShadow : COLORREF -> Uint32
// ixOffset : INT -> Int32
// iyOffset : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DrawShadowText(
  hdc: THandle;   // HDC
  pszText: PWideChar;   // LPCWSTR
  cch: DWORD;   // DWORD
  prc: Pointer;   // RECT*
  dwFlags: DWORD;   // DWORD
  crText: DWORD;   // COLORREF
  crShadow: DWORD;   // COLORREF
  ixOffset: Integer;   // INT
  iyOffset: Integer   // INT
): Integer; stdcall;
  external 'COMCTL32.dll' name 'DrawShadowText';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DrawShadowText"
  c_DrawShadowText :: Ptr () -> CWString -> Word32 -> Ptr () -> Word32 -> Word32 -> Word32 -> Int32 -> Int32 -> IO Int32
-- hdc : HDC -> Ptr ()
-- pszText : LPCWSTR -> CWString
-- cch : DWORD -> Word32
-- prc : RECT* -> Ptr ()
-- dwFlags : DWORD -> Word32
-- crText : COLORREF -> Word32
-- crShadow : COLORREF -> Word32
-- ixOffset : INT -> Int32
-- iyOffset : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let drawshadowtext =
  foreign "DrawShadowText"
    ((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> uint32_t @-> uint32_t @-> uint32_t @-> int32_t @-> int32_t @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* pszText : LPCWSTR -> (ptr uint16_t) *)
(* cch : DWORD -> uint32_t *)
(* prc : RECT* -> (ptr void) *)
(* dwFlags : DWORD -> uint32_t *)
(* crText : COLORREF -> uint32_t *)
(* crShadow : COLORREF -> uint32_t *)
(* ixOffset : INT -> int32_t *)
(* iyOffset : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library comctl32 (t "COMCTL32.dll"))
(cffi:use-foreign-library comctl32)

(cffi:defcfun ("DrawShadowText" draw-shadow-text :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (psz-text (:string :encoding :utf-16le))   ; LPCWSTR
  (cch :uint32)   ; DWORD
  (prc :pointer)   ; RECT*
  (dw-flags :uint32)   ; DWORD
  (cr-text :uint32)   ; COLORREF
  (cr-shadow :uint32)   ; COLORREF
  (ix-offset :int32)   ; INT
  (iy-offset :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DrawShadowText = Win32::API::More->new('COMCTL32',
    'int DrawShadowText(HANDLE hdc, LPCWSTR pszText, DWORD cch, LPVOID prc, DWORD dwFlags, DWORD crText, DWORD crShadow, int ixOffset, int iyOffset)');
# my $ret = $DrawShadowText->Call($hdc, $pszText, $cch, $prc, $dwFlags, $crText, $crShadow, $ixOffset, $iyOffset);
# hdc : HDC -> HANDLE
# pszText : LPCWSTR -> LPCWSTR
# cch : DWORD -> DWORD
# prc : RECT* -> LPVOID
# dwFlags : DWORD -> DWORD
# crText : COLORREF -> DWORD
# crShadow : COLORREF -> DWORD
# ixOffset : INT -> int
# iyOffset : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型