// https://github.com/waitingsong/node-win32-api/blob/main/README.zh-CN.md // **查询计算器程序窗口句柄(需要先手动运行一个计算器)** /** * 导出的模块: * Comctl32: Comctl32 from lib/comctl32/api * Kernel32: kernel32 from lib/kernel32/api * User32: user32 from lib/user32/api */ import { Kernel32, User32 } from 'win32-api/promise' import ref from 'ref-napi' const knl32 = Kernel32.load() const user32 = User32.load() // user32.MessageBoxW("0","0",0,0) // const user32 = load(['FindWindowExW']) // load only one api defined in lib/{dll}/api from user32.dll // const title = 'Calculator\0' // null-terminated string const title = '计算器\0' // null-terminated string 字符串必须以\0即null结尾! const lpszWindow = Buffer.from(title, 'ucs2') const hWnd = await user32.FindWindowExW(0, 0, null, lpszWindow) // assert((typeof hWnd === 'string' && hWnd.length > 0) || hWnd > 0) console.log('buf: ', hWnd) user32.CloseWindow(hWnd) // // Change title of the Calculator // const res = await user32.SetWindowTextW(hWnd, Buffer.from('Node-Calculator\0', 'ucs2')) // if ( ! res) { // console.log('SetWindowTextW failed') // } // else { // console.log('window title changed') // }