win32-api
Version:
FFI definitions of windows win32 api for node-ffi
25 lines • 1.32 kB
JavaScript
import assert from 'node:assert';
import { ucsBufferToString } from 'win32-def';
import { load } from '../../lib/user32/index.js';
const fnName = 'GetWindowTextW';
const fnAsyncName = 'GetWindowTextW_Async';
/**
* Retrieves a handle to a window whose class name and window name match the specified strings.
* The function searches child windows, beginning with the one following the specified child window.
* This function does not perform a case-sensitive search.
* @link https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextw
*
* 检索其类名和窗口名称与指定字符串匹配的窗口的句柄。 函数搜索子窗口,从指定子窗口后面的子窗口开始。 此函数不执行区分大小写的搜索。
* @link https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-getwindowtextw
*/
export async function GetWindowText(hWnd, nMaxCount) {
const lib = load([fnName]);
const fn = lib[fnAsyncName];
assert(typeof fn === 'function', `Function "${fnAsyncName}" not found`);
const buf = Buffer.alloc(nMaxCount * 2);
const resLength = await fn(hWnd, buf, nMaxCount);
const len2 = Math.min(resLength, nMaxCount - 1);
const title = ucsBufferToString(buf, len2);
return title || '';
}
//# sourceMappingURL=GetWindowText.js.map