提交 34b99509 编写于 作者: K Knine

node-win32-api

上级 a1b22bcb
......@@ -9,7 +9,19 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"ffi-napi": "^4.0.3"
"ffi-napi": "^4.0.3",
"win32-api": "^20.4.1"
}
},
"node_modules/@waiting/shared-types": {
"version": "20.13.0",
"resolved": "https://registry.npmmirror.com/@waiting/shared-types/-/shared-types-20.13.0.tgz",
"integrity": "sha512-OiMocNStZbtkf8LEwrbtAuiI3WtwXo+Aoqhz6jP6i9KSogNDsEMccJRz5wq+gVeO2qEcymn5J2NyK7vR/icgBg==",
"engines": {
"node": ">=14.16.0"
},
"peerDependencies": {
"typescript": ">=4.7.4"
}
},
"node_modules/debug": {
......@@ -108,9 +120,79 @@
"dependencies": {
"ms": "^2.1.1"
}
},
"node_modules/ref-union-di": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/ref-union-di/-/ref-union-di-1.0.1.tgz",
"integrity": "sha512-JWSF2BwNVtCgmEfoDGMh8S1KO07oq+T8L7cBHwcsmQmeXDZd9JNlrxU+ebSHs+jsf0qrqFFWXMCmj94Tcl26TA==",
"peer": true,
"dependencies": {
"debug": "^3.1.0"
}
},
"node_modules/ref-union-di/node_modules/debug": {
"version": "3.2.7",
"resolved": "https://registry.npmmirror.com/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"peer": true,
"dependencies": {
"ms": "^2.1.1"
}
},
"node_modules/typescript": {
"version": "5.2.2",
"resolved": "https://registry.npmmirror.com/typescript/-/typescript-5.2.2.tgz",
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
"peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/win32-api": {
"version": "20.4.1",
"resolved": "https://registry.npmmirror.com/win32-api/-/win32-api-20.4.1.tgz",
"integrity": "sha512-STbeoFsVndgc5eMmXcvmuuoWM2S8mOh/0V2w/gmYAFSI+FPoYDjGhvntrvhvoFMec8AC2ReI2LSkb8KGyEqhPQ==",
"dependencies": {
"win32-def": "^20.4.1"
},
"engines": {
"node": ">=14.15.0"
},
"peerDependencies": {
"ffi-napi": "^4.0.3",
"ref-napi": "^3.0.3",
"ref-struct-di": "^1.1.1",
"ref-union-di": "^1.0.1"
}
},
"node_modules/win32-def": {
"version": "20.4.1",
"resolved": "https://registry.npmmirror.com/win32-def/-/win32-def-20.4.1.tgz",
"integrity": "sha512-d2y6pN/ebLU4Vsu4JepzeEtdWTVcAkJIiAFZiPjT/mjac2YYvhM4jM2bGKdt8usJNxAI2o7YiF0ytdVDQO6Qdg==",
"dependencies": {
"@waiting/shared-types": "^20.11.0"
},
"engines": {
"node": ">=14.15.0"
},
"peerDependencies": {
"ref-napi": "^3.0.3",
"ref-struct-di": "^1.1.1",
"ref-union-di": "^1.0.1"
}
}
},
"dependencies": {
"@waiting/shared-types": {
"version": "20.13.0",
"resolved": "https://registry.npmmirror.com/@waiting/shared-types/-/shared-types-20.13.0.tgz",
"integrity": "sha512-OiMocNStZbtkf8LEwrbtAuiI3WtwXo+Aoqhz6jP6i9KSogNDsEMccJRz5wq+gVeO2qEcymn5J2NyK7vR/icgBg==",
"requires": {}
},
"debug": {
"version": "4.3.4",
"resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.4.tgz",
......@@ -188,6 +270,48 @@
}
}
}
},
"ref-union-di": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/ref-union-di/-/ref-union-di-1.0.1.tgz",
"integrity": "sha512-JWSF2BwNVtCgmEfoDGMh8S1KO07oq+T8L7cBHwcsmQmeXDZd9JNlrxU+ebSHs+jsf0qrqFFWXMCmj94Tcl26TA==",
"peer": true,
"requires": {
"debug": "^3.1.0"
},
"dependencies": {
"debug": {
"version": "3.2.7",
"resolved": "https://registry.npmmirror.com/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"peer": true,
"requires": {
"ms": "^2.1.1"
}
}
}
},
"typescript": {
"version": "5.2.2",
"resolved": "https://registry.npmmirror.com/typescript/-/typescript-5.2.2.tgz",
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
"peer": true
},
"win32-api": {
"version": "20.4.1",
"resolved": "https://registry.npmmirror.com/win32-api/-/win32-api-20.4.1.tgz",
"integrity": "sha512-STbeoFsVndgc5eMmXcvmuuoWM2S8mOh/0V2w/gmYAFSI+FPoYDjGhvntrvhvoFMec8AC2ReI2LSkb8KGyEqhPQ==",
"requires": {
"win32-def": "^20.4.1"
}
},
"win32-def": {
"version": "20.4.1",
"resolved": "https://registry.npmmirror.com/win32-def/-/win32-def-20.4.1.tgz",
"integrity": "sha512-d2y6pN/ebLU4Vsu4JepzeEtdWTVcAkJIiAFZiPjT/mjac2YYvhM4jM2bGKdt8usJNxAI2o7YiF0ytdVDQO6Qdg==",
"requires": {
"@waiting/shared-types": "^20.11.0"
}
}
}
}
......@@ -3,15 +3,18 @@
"version": "1.0.0",
"description": "todo",
"main": "index.js",
"type": "module",
"directories": {
"doc": "doc"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"foo2": "node win32-api.js"
},
"author": "khz",
"license": "ISC",
"dependencies": {
"ffi-napi": "^4.0.3"
"ffi-napi": "^4.0.3",
"win32-api": "^20.4.1"
}
}
// 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')
// }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册