ホーム › Graphics.Gdi › GrayStringW
GrayStringW
関数文字列を淡色化して指定位置に描画する(Unicode版)。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL GrayStringW(
HDC hDC,
HBRUSH hBrush, // optional
GRAYSTRINGPROC lpOutputFunc, // optional
LPARAM lpData,
INT nCount,
INT X,
INT Y,
INT nWidth,
INT nHeight
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hDC | HDC | in | デバイスコンテキストへのハンドルです。 |
| hBrush | HBRUSH | inoptional | グレー表示に使用するブラシへのハンドルです。このパラメーターが NULL の場合、ウィンドウのテキスト描画に使用されたものと同じブラシでテキストがグレー表示されます。 |
| lpOutputFunc | GRAYSTRINGPROC | inoptional | 文字列を描画する、アプリケーション定義の関数へのポインターです。文字列の描画に TextOut を使用する場合は NULL ポインターを指定します。詳細については、OutputProc コールバック関数を参照してください。 |
| lpData | LPARAM | in | 出力関数に渡すデータへのポインターです。lpOutputFunc パラメーターが NULL の場合、lpData は出力する文字列へのポインターである必要があります。 |
| nCount | INT | in | 出力する文字数です。nCount パラメーターが 0 の場合、GrayString は文字列の長さを計算します(lpData が文字列へのポインターであることを前提とします)。nCount が 1 で、lpOutputFunc が指す関数が FALSE を返した場合、イメージは表示されますがグレー表示にはなりません。 |
| X | INT | in | 文字列を囲む四角形の開始位置の x 座標(デバイス座標)です。 |
| Y | INT | in | 文字列を囲む四角形の開始位置の y 座標(デバイス座標)です。 |
| nWidth | INT | in | 文字列を囲む四角形の幅(デバイス単位)です。このパラメーターが 0 の場合、GrayString は領域の幅を計算します(lpData が文字列へのポインターであることを前提とします)。 |
| nHeight | INT | in | 文字列を囲む四角形の高さ(デバイス単位)です。このパラメーターが 0 の場合、GrayString は領域の高さを計算します(lpData が文字列へのポインターであることを前提とします)。 |
戻り値の型: BOOL
公式ドキュメント
GrayString 関数は、指定された位置にグレー表示のテキストを描画します。(Unicode)
戻り値
文字列が描画された場合、戻り値は 0 以外の値になります。
TextOut 関数またはアプリケーション定義の出力関数が 0 を返した場合、あるいはグレー表示用のメモリビットマップを作成するのに十分なメモリがなかった場合、戻り値は 0 になります。
解説(Remarks)
アプリケーションは、GrayString を呼び出さなくても、単色のグレーをサポートするデバイス上でグレー表示の文字列を描画できます。システムカラー COLOR_GRAYTEXT は、無効化されたテキストの描画に使用される単色グレーのシステムカラーです。アプリケーションは GetSysColor 関数を呼び出して COLOR_GRAYTEXT のカラー値を取得できます。色が 0(黒)以外の場合、アプリケーションは SetTextColor 関数を呼び出してテキストの色をそのカラー値に設定し、文字列を直接描画できます。取得した色が黒の場合、アプリケーションはテキストをグレー表示するために GrayString を呼び出す必要があります。
メモ
winuser.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして GrayString を定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在させて使用すると、コンパイルエラーや実行時エラーを引き起こす不整合が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
BOOL GrayStringW(
HDC hDC,
HBRUSH hBrush, // optional
GRAYSTRINGPROC lpOutputFunc, // optional
LPARAM lpData,
INT nCount,
INT X,
INT Y,
INT nWidth,
INT nHeight
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool GrayStringW(
IntPtr hDC, // HDC
IntPtr hBrush, // HBRUSH optional
IntPtr lpOutputFunc, // GRAYSTRINGPROC optional
IntPtr lpData, // LPARAM
int nCount, // INT
int X, // INT
int Y, // INT
int nWidth, // INT
int nHeight // INT
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GrayStringW(
hDC As IntPtr, ' HDC
hBrush As IntPtr, ' HBRUSH optional
lpOutputFunc As IntPtr, ' GRAYSTRINGPROC optional
lpData As IntPtr, ' LPARAM
nCount As Integer, ' INT
X As Integer, ' INT
Y As Integer, ' INT
nWidth As Integer, ' INT
nHeight As Integer ' INT
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hDC : HDC
' hBrush : HBRUSH optional
' lpOutputFunc : GRAYSTRINGPROC optional
' lpData : LPARAM
' nCount : INT
' X : INT
' Y : INT
' nWidth : INT
' nHeight : INT
Declare PtrSafe Function GrayStringW Lib "user32" ( _
ByVal hDC As LongPtr, _
ByVal hBrush As LongPtr, _
ByVal lpOutputFunc As LongPtr, _
ByVal lpData As LongPtr, _
ByVal nCount As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GrayStringW = ctypes.windll.user32.GrayStringW
GrayStringW.restype = wintypes.BOOL
GrayStringW.argtypes = [
wintypes.HANDLE, # hDC : HDC
wintypes.HANDLE, # hBrush : HBRUSH optional
ctypes.c_void_p, # lpOutputFunc : GRAYSTRINGPROC optional
ctypes.c_ssize_t, # lpData : LPARAM
ctypes.c_int, # nCount : INT
ctypes.c_int, # X : INT
ctypes.c_int, # Y : INT
ctypes.c_int, # nWidth : INT
ctypes.c_int, # nHeight : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GrayStringW = Fiddle::Function.new(
lib['GrayStringW'],
[
Fiddle::TYPE_VOIDP, # hDC : HDC
Fiddle::TYPE_VOIDP, # hBrush : HBRUSH optional
Fiddle::TYPE_VOIDP, # lpOutputFunc : GRAYSTRINGPROC optional
Fiddle::TYPE_INTPTR_T, # lpData : LPARAM
Fiddle::TYPE_INT, # nCount : INT
Fiddle::TYPE_INT, # X : INT
Fiddle::TYPE_INT, # Y : INT
Fiddle::TYPE_INT, # nWidth : INT
Fiddle::TYPE_INT, # nHeight : INT
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn GrayStringW(
hDC: *mut core::ffi::c_void, // HDC
hBrush: *mut core::ffi::c_void, // HBRUSH optional
lpOutputFunc: *const core::ffi::c_void, // GRAYSTRINGPROC optional
lpData: isize, // LPARAM
nCount: i32, // INT
X: i32, // INT
Y: i32, // INT
nWidth: i32, // INT
nHeight: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USER32.dll", CharSet = CharSet.Unicode)]
public static extern bool GrayStringW(IntPtr hDC, IntPtr hBrush, IntPtr lpOutputFunc, IntPtr lpData, int nCount, int X, int Y, int nWidth, int nHeight);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GrayStringW' -Namespace Win32 -PassThru
# $api::GrayStringW(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight)#uselib "USER32.dll"
#func global GrayStringW "GrayStringW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; GrayStringW hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight ; 戻り値は stat
; hDC : HDC -> "wptr"
; hBrush : HBRUSH optional -> "wptr"
; lpOutputFunc : GRAYSTRINGPROC optional -> "wptr"
; lpData : LPARAM -> "wptr"
; nCount : INT -> "wptr"
; X : INT -> "wptr"
; Y : INT -> "wptr"
; nWidth : INT -> "wptr"
; nHeight : INT -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global GrayStringW "GrayStringW" sptr, sptr, sptr, sptr, int, int, int, int, int
; res = GrayStringW(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight)
; hDC : HDC -> "sptr"
; hBrush : HBRUSH optional -> "sptr"
; lpOutputFunc : GRAYSTRINGPROC optional -> "sptr"
; lpData : LPARAM -> "sptr"
; nCount : INT -> "int"
; X : INT -> "int"
; Y : INT -> "int"
; nWidth : INT -> "int"
; nHeight : INT -> "int"; BOOL GrayStringW(HDC hDC, HBRUSH hBrush, GRAYSTRINGPROC lpOutputFunc, LPARAM lpData, INT nCount, INT X, INT Y, INT nWidth, INT nHeight)
#uselib "USER32.dll"
#cfunc global GrayStringW "GrayStringW" intptr, intptr, intptr, intptr, int, int, int, int, int
; res = GrayStringW(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight)
; hDC : HDC -> "intptr"
; hBrush : HBRUSH optional -> "intptr"
; lpOutputFunc : GRAYSTRINGPROC optional -> "intptr"
; lpData : LPARAM -> "intptr"
; nCount : INT -> "int"
; X : INT -> "int"
; Y : INT -> "int"
; nWidth : INT -> "int"
; nHeight : INT -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGrayStringW = user32.NewProc("GrayStringW")
)
// hDC (HDC), hBrush (HBRUSH optional), lpOutputFunc (GRAYSTRINGPROC optional), lpData (LPARAM), nCount (INT), X (INT), Y (INT), nWidth (INT), nHeight (INT)
r1, _, err := procGrayStringW.Call(
uintptr(hDC),
uintptr(hBrush),
uintptr(lpOutputFunc),
uintptr(lpData),
uintptr(nCount),
uintptr(X),
uintptr(Y),
uintptr(nWidth),
uintptr(nHeight),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GrayStringW(
hDC: THandle; // HDC
hBrush: THandle; // HBRUSH optional
lpOutputFunc: Pointer; // GRAYSTRINGPROC optional
lpData: NativeInt; // LPARAM
nCount: Integer; // INT
X: Integer; // INT
Y: Integer; // INT
nWidth: Integer; // INT
nHeight: Integer // INT
): BOOL; stdcall;
external 'USER32.dll' name 'GrayStringW';result := DllCall("USER32\GrayStringW"
, "Ptr", hDC ; HDC
, "Ptr", hBrush ; HBRUSH optional
, "Ptr", lpOutputFunc ; GRAYSTRINGPROC optional
, "Ptr", lpData ; LPARAM
, "Int", nCount ; INT
, "Int", X ; INT
, "Int", Y ; INT
, "Int", nWidth ; INT
, "Int", nHeight ; INT
, "Int") ; return: BOOL●GrayStringW(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight) = DLL("USER32.dll", "bool GrayStringW(void*, void*, void*, int, int, int, int, int, int)")
# 呼び出し: GrayStringW(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight)
# hDC : HDC -> "void*"
# hBrush : HBRUSH optional -> "void*"
# lpOutputFunc : GRAYSTRINGPROC optional -> "void*"
# lpData : LPARAM -> "int"
# nCount : INT -> "int"
# X : INT -> "int"
# Y : INT -> "int"
# nWidth : INT -> "int"
# nHeight : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "user32" fn GrayStringW(
hDC: ?*anyopaque, // HDC
hBrush: ?*anyopaque, // HBRUSH optional
lpOutputFunc: ?*anyopaque, // GRAYSTRINGPROC optional
lpData: isize, // LPARAM
nCount: i32, // INT
X: i32, // INT
Y: i32, // INT
nWidth: i32, // INT
nHeight: i32 // INT
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc GrayStringW(
hDC: pointer, # HDC
hBrush: pointer, # HBRUSH optional
lpOutputFunc: pointer, # GRAYSTRINGPROC optional
lpData: int, # LPARAM
nCount: int32, # INT
X: int32, # INT
Y: int32, # INT
nWidth: int32, # INT
nHeight: int32 # INT
): int32 {.importc: "GrayStringW", stdcall, dynlib: "USER32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "user32");
extern(Windows)
int GrayStringW(
void* hDC, // HDC
void* hBrush, // HBRUSH optional
void* lpOutputFunc, // GRAYSTRINGPROC optional
ptrdiff_t lpData, // LPARAM
int nCount, // INT
int X, // INT
int Y, // INT
int nWidth, // INT
int nHeight // INT
);ccall((:GrayStringW, "USER32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Int, Int32, Int32, Int32, Int32, Int32),
hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight)
# hDC : HDC -> Ptr{Cvoid}
# hBrush : HBRUSH optional -> Ptr{Cvoid}
# lpOutputFunc : GRAYSTRINGPROC optional -> Ptr{Cvoid}
# lpData : LPARAM -> Int
# nCount : INT -> Int32
# X : INT -> Int32
# Y : INT -> Int32
# nWidth : INT -> Int32
# nHeight : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t GrayStringW(
void* hDC,
void* hBrush,
void* lpOutputFunc,
intptr_t lpData,
int32_t nCount,
int32_t X,
int32_t Y,
int32_t nWidth,
int32_t nHeight);
]]
local user32 = ffi.load("user32")
-- user32.GrayStringW(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight)
-- hDC : HDC
-- hBrush : HBRUSH optional
-- lpOutputFunc : GRAYSTRINGPROC optional
-- lpData : LPARAM
-- nCount : INT
-- X : INT
-- Y : INT
-- nWidth : INT
-- nHeight : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const GrayStringW = lib.func('__stdcall', 'GrayStringW', 'int32_t', ['void *', 'void *', 'void *', 'intptr_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t']);
// GrayStringW(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight)
// hDC : HDC -> 'void *'
// hBrush : HBRUSH optional -> 'void *'
// lpOutputFunc : GRAYSTRINGPROC optional -> 'void *'
// lpData : LPARAM -> 'intptr_t'
// nCount : INT -> 'int32_t'
// X : INT -> 'int32_t'
// Y : INT -> 'int32_t'
// nWidth : INT -> 'int32_t'
// nHeight : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("USER32.dll", {
GrayStringW: { parameters: ["pointer", "pointer", "pointer", "isize", "i32", "i32", "i32", "i32", "i32"], result: "i32" },
});
// lib.symbols.GrayStringW(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight)
// hDC : HDC -> "pointer"
// hBrush : HBRUSH optional -> "pointer"
// lpOutputFunc : GRAYSTRINGPROC optional -> "pointer"
// lpData : LPARAM -> "isize"
// nCount : INT -> "i32"
// X : INT -> "i32"
// Y : INT -> "i32"
// nWidth : INT -> "i32"
// nHeight : INT -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GrayStringW(
void* hDC,
void* hBrush,
void* lpOutputFunc,
intptr_t lpData,
int32_t nCount,
int32_t X,
int32_t Y,
int32_t nWidth,
int32_t nHeight);
C, "USER32.dll");
// $ffi->GrayStringW(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight);
// hDC : HDC
// hBrush : HBRUSH optional
// lpOutputFunc : GRAYSTRINGPROC optional
// lpData : LPARAM
// nCount : INT
// X : INT
// Y : INT
// nWidth : INT
// nHeight : 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 User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.UNICODE_OPTIONS);
boolean GrayStringW(
Pointer hDC, // HDC
Pointer hBrush, // HBRUSH optional
Callback lpOutputFunc, // GRAYSTRINGPROC optional
long lpData, // LPARAM
int nCount, // INT
int X, // INT
int Y, // INT
int nWidth, // INT
int nHeight // INT
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("user32")]
lib LibUSER32
fun GrayStringW = GrayStringW(
hDC : Void*, # HDC
hBrush : Void*, # HBRUSH optional
lpOutputFunc : Void*, # GRAYSTRINGPROC optional
lpData : LibC::SSizeT, # LPARAM
nCount : Int32, # INT
X : Int32, # INT
Y : Int32, # INT
nWidth : Int32, # INT
nHeight : 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 GrayStringWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, IntPtr, Int32, Int32, Int32, Int32, Int32);
typedef GrayStringWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, int, int, int, int, int);
final GrayStringW = DynamicLibrary.open('USER32.dll')
.lookupFunction<GrayStringWNative, GrayStringWDart>('GrayStringW');
// hDC : HDC -> Pointer<Void>
// hBrush : HBRUSH optional -> Pointer<Void>
// lpOutputFunc : GRAYSTRINGPROC optional -> Pointer<Void>
// lpData : LPARAM -> IntPtr
// nCount : INT -> Int32
// X : INT -> Int32
// Y : INT -> Int32
// nWidth : INT -> Int32
// nHeight : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GrayStringW(
hDC: THandle; // HDC
hBrush: THandle; // HBRUSH optional
lpOutputFunc: Pointer; // GRAYSTRINGPROC optional
lpData: NativeInt; // LPARAM
nCount: Integer; // INT
X: Integer; // INT
Y: Integer; // INT
nWidth: Integer; // INT
nHeight: Integer // INT
): BOOL; stdcall;
external 'USER32.dll' name 'GrayStringW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GrayStringW"
c_GrayStringW :: Ptr () -> Ptr () -> Ptr () -> CIntPtr -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO CInt
-- hDC : HDC -> Ptr ()
-- hBrush : HBRUSH optional -> Ptr ()
-- lpOutputFunc : GRAYSTRINGPROC optional -> Ptr ()
-- lpData : LPARAM -> CIntPtr
-- nCount : INT -> Int32
-- X : INT -> Int32
-- Y : INT -> Int32
-- nWidth : INT -> Int32
-- nHeight : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let graystringw =
foreign "GrayStringW"
((ptr void) @-> (ptr void) @-> (ptr void) @-> intptr_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> returning int32_t)
(* hDC : HDC -> (ptr void) *)
(* hBrush : HBRUSH optional -> (ptr void) *)
(* lpOutputFunc : GRAYSTRINGPROC optional -> (ptr void) *)
(* lpData : LPARAM -> intptr_t *)
(* nCount : INT -> int32_t *)
(* X : INT -> int32_t *)
(* Y : INT -> int32_t *)
(* nWidth : INT -> int32_t *)
(* nHeight : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("GrayStringW" gray-string-w :convention :stdcall) :int32
(h-dc :pointer) ; HDC
(h-brush :pointer) ; HBRUSH optional
(lp-output-func :pointer) ; GRAYSTRINGPROC optional
(lp-data :int64) ; LPARAM
(n-count :int32) ; INT
(x :int32) ; INT
(y :int32) ; INT
(n-width :int32) ; INT
(n-height :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GrayStringW = Win32::API::More->new('USER32',
'BOOL GrayStringW(HANDLE hDC, HANDLE hBrush, LPVOID lpOutputFunc, LPARAM lpData, int nCount, int X, int Y, int nWidth, int nHeight)');
# my $ret = $GrayStringW->Call($hDC, $hBrush, $lpOutputFunc, $lpData, $nCount, $X, $Y, $nWidth, $nHeight);
# hDC : HDC -> HANDLE
# hBrush : HBRUSH optional -> HANDLE
# lpOutputFunc : GRAYSTRINGPROC optional -> LPVOID
# lpData : LPARAM -> LPARAM
# nCount : INT -> int
# X : INT -> int
# Y : INT -> int
# nWidth : INT -> int
# nHeight : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f GrayStringA (ANSI版) — 文字列を淡色化して指定位置に描画する(ANSI版)。
公式の関連項目
- f GetSysColor — 指定したシステム表示要素の色を取得する。
- f SetTextColor — デバイスコンテキストの文字色を設定する。
- f TabbedTextOutW — タブ位置を展開して文字列を描画する(Unicode版)。
- f TextOutW — 指定座標に文字列を出力する(Unicode版)。
使用する型