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

GrayStringA

関数
文字列を淡色化して指定位置に描画する(ANSI版)。
DLLUSER32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (ANSI / -A)
#include <windows.h>

BOOL GrayStringA(
    HDC hDC,
    HBRUSH hBrush,   // optional
    GRAYSTRINGPROC lpOutputFunc,   // optional
    LPARAM lpData,
    INT nCount,
    INT X,
    INT Y,
    INT nWidth,
    INT nHeight
);

パラメーター

名前方向
hDCHDCin
hBrushHBRUSHinoptional
lpOutputFuncGRAYSTRINGPROCinoptional
lpDataLPARAMin
nCountINTin
XINTin
YINTin
nWidthINTin
nHeightINTin

戻り値の型: BOOL

各言語での呼び出し定義

// USER32.dll  (ANSI / -A)
#include <windows.h>

BOOL GrayStringA(
    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.Ansi, ExactSpelling = true)]
static extern bool GrayStringA(
    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.Ansi, ExactSpelling:=True)>
Public Shared Function GrayStringA(
    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 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 GrayStringA 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
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GrayStringA = ctypes.windll.user32.GrayStringA
GrayStringA.restype = wintypes.BOOL
GrayStringA.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')
GrayStringA = Fiddle::Function.new(
  lib['GrayStringA'],
  [
    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)
#[link(name = "user32")]
extern "system" {
    fn GrayStringA(
        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.Ansi)]
public static extern bool GrayStringA(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_GrayStringA' -Namespace Win32 -PassThru
# $api::GrayStringA(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight)
#uselib "USER32.dll"
#func global GrayStringA "GrayStringA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GrayStringA hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight   ; 戻り値は stat
; hDC : HDC -> "sptr"
; hBrush : HBRUSH optional -> "sptr"
; lpOutputFunc : GRAYSTRINGPROC optional -> "sptr"
; lpData : LPARAM -> "sptr"
; nCount : INT -> "sptr"
; X : INT -> "sptr"
; Y : INT -> "sptr"
; nWidth : INT -> "sptr"
; nHeight : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global GrayStringA "GrayStringA" sptr, sptr, sptr, sptr, int, int, int, int, int
; res = GrayStringA(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 GrayStringA(HDC hDC, HBRUSH hBrush, GRAYSTRINGPROC lpOutputFunc, LPARAM lpData, INT nCount, INT X, INT Y, INT nWidth, INT nHeight)
#uselib "USER32.dll"
#cfunc global GrayStringA "GrayStringA" intptr, intptr, intptr, intptr, int, int, int, int, int
; res = GrayStringA(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")
	procGrayStringA = user32.NewProc("GrayStringA")
)

// hDC (HDC), hBrush (HBRUSH optional), lpOutputFunc (GRAYSTRINGPROC optional), lpData (LPARAM), nCount (INT), X (INT), Y (INT), nWidth (INT), nHeight (INT)
r1, _, err := procGrayStringA.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   // BOOL
function GrayStringA(
  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 'GrayStringA';
result := DllCall("USER32\GrayStringA"
    , "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
●GrayStringA(hDC, hBrush, lpOutputFunc, lpData, nCount, X, Y, nWidth, nHeight) = DLL("USER32.dll", "bool GrayStringA(void*, void*, void*, int, int, int, int, int, int)")
# 呼び出し: GrayStringA(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)。