-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(win32-api): fun/user32GetWindowText()
- Loading branch information
1 parent
2484706
commit e672a2a
Showing
6 changed files
with
70 additions
and
45 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import ref from 'ref-napi' | ||
|
||
import { DllNames } from '../../index.js' | ||
import { User32 as DLL } from '../../index.promise.js' | ||
|
||
|
||
export { DModel as M } from '../../index.js' | ||
export { ref } | ||
|
||
export const dllName = DllNames.user32 | ||
export type Win32Fns = DLL.Win32Fns | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,58 @@ | ||
import { | ||
genUcsBufferFrom, | ||
ucsBufferToString, | ||
} from '../../index.js' | ||
import { getMod } from '../func.helper.js' | ||
|
||
export * from './FindWindowEx.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 | undefined> { | ||
|
||
const mod = getMod<Win32Fns>(dllName) | ||
|
||
const lpszClassBuf = genUcsBufferFrom(lpszClass) | ||
const lpszWindowBuf = genUcsBufferFrom(lpszWindow) | ||
|
||
const hWnd = await mod.FindWindowExW( | ||
hwndParent, | ||
hwndChildAfter, | ||
lpszClassBuf, | ||
lpszWindowBuf, | ||
) | ||
|
||
const ret = hWnd ? hWnd : undefined | ||
return ret | ||
} | ||
|
||
|
||
/** | ||
* @docs https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextw | ||
*/ | ||
export async function user32GetWindowText( | ||
hWnd: M.HWND, | ||
nMaxCount: M.INT, | ||
): Promise<string> { | ||
|
||
const mod = getMod<Win32Fns>(dllName) | ||
|
||
const len = nMaxCount | ||
const buf = Buffer.alloc(len * 2) | ||
|
||
const ret = await mod.GetWindowTextW(hWnd, buf, len) | ||
if (ret > 0) { | ||
const str = ucsBufferToString(buf) | ||
return str | ||
} | ||
return '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters