ホーム › UI.WindowsAndMessaging › GetWindowTextLengthW
GetWindowTextLengthW
関数ウィンドウテキストの文字数を取得する(Unicode版)。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
INT GetWindowTextLengthW(
HWND hWnd
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | テキスト長を取得する対象ウィンドウまたはコントロールのハンドル。文字数を返す。 |
戻り値の型: INT
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
INT GetWindowTextLengthW(
HWND hWnd
);[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern int GetWindowTextLengthW(
IntPtr hWnd // HWND
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetWindowTextLengthW(
hWnd As IntPtr ' HWND
) As Integer
End Function' hWnd : HWND
Declare PtrSafe Function GetWindowTextLengthW Lib "user32" ( _
ByVal hWnd As LongPtr) 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
GetWindowTextLengthW = ctypes.windll.user32.GetWindowTextLengthW
GetWindowTextLengthW.restype = ctypes.c_int
GetWindowTextLengthW.argtypes = [
wintypes.HANDLE, # hWnd : HWND
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
GetWindowTextLengthW = Fiddle::Function.new(
lib['GetWindowTextLengthW'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn GetWindowTextLengthW(
hWnd: *mut core::ffi::c_void // HWND
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetWindowTextLengthW(IntPtr hWnd);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_GetWindowTextLengthW' -Namespace Win32 -PassThru
# $api::GetWindowTextLengthW(hWnd)#uselib "USER32.dll"
#func global GetWindowTextLengthW "GetWindowTextLengthW" wptr
; GetWindowTextLengthW hWnd ; 戻り値は stat
; hWnd : HWND -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global GetWindowTextLengthW "GetWindowTextLengthW" sptr
; res = GetWindowTextLengthW(hWnd)
; hWnd : HWND -> "sptr"; INT GetWindowTextLengthW(HWND hWnd)
#uselib "USER32.dll"
#cfunc global GetWindowTextLengthW "GetWindowTextLengthW" intptr
; res = GetWindowTextLengthW(hWnd)
; hWnd : HWND -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procGetWindowTextLengthW = user32.NewProc("GetWindowTextLengthW")
)
// hWnd (HWND)
r1, _, err := procGetWindowTextLengthW.Call(
uintptr(hWnd),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction GetWindowTextLengthW(
hWnd: THandle // HWND
): Integer; stdcall;
external 'USER32.dll' name 'GetWindowTextLengthW';result := DllCall("USER32\GetWindowTextLengthW"
, "Ptr", hWnd ; HWND
, "Int") ; return: INT●GetWindowTextLengthW(hWnd) = DLL("USER32.dll", "int GetWindowTextLengthW(void*)")
# 呼び出し: GetWindowTextLengthW(hWnd)
# hWnd : HWND -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。