-
Notifications
You must be signed in to change notification settings - Fork 53
/
index.user32.ts
57 lines (46 loc) · 1.36 KB
/
index.user32.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {
ucsBufferFrom,
ucsBufferToString,
} from '../../index.js'
import { getMod } from '../func.helper.js'
import { Win32Fns, dllName, M } from './helper.js'
/**
* Retrieves a handle to the specified printer or print server or other types of handles in the print subsystem.
* @docs https://docs.microsoft.com/en-us/windows/win32/printdocs/openprinter
* @docs https://docs.microsoft.com/zh-cn/windows/win32/printdocs/openprinter
*/
export async function user32FindWindowEx(
hwndParent: M.HWND,
hwndChildAfter: M.HWND,
lpszClass: string | null,
lpszWindow: string | null,
): Promise<M.HWND> {
const mod = getMod<Win32Fns>(dllName)
const lpszClassBuf = ucsBufferFrom(lpszClass)
const lpszWindowBuf = ucsBufferFrom(lpszWindow)
const hWnd = await mod.FindWindowExW(
hwndParent,
hwndChildAfter,
lpszClassBuf,
lpszWindowBuf,
)
return hWnd
}
/**
* @docs https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextw
*/
export async function user32GetWindowText(
hWnd: M.HWND,
/** Not including the null character */
nMaxCount: M.INT,
): Promise<string> {
const mod = getMod<Win32Fns>(dllName)
const len = nMaxCount + 1
const buf = Buffer.alloc(len * 2)
const ret = await mod.GetWindowTextW(hWnd, buf, len)
if (ret > 0) {
const str = ucsBufferToString(buf, len)
return str
}
return ''
}