const os = require("os");
const ffi = require("ffi-napi");
const ref = require("ref-napi");
const Struct = require("ref-struct-di")(ref);
const { screen } = require("electron");
const ABM_NEW = 0;
const ABM_REMOVE = 0x1;
const ABM_QUERYPOS = 0x2;
const ABM_SETPOS = 0x3;
const ABM_GETSTATE = 0x4;
const ABM_GETTASKBARPOS = 0x5; // 0x00000005
const ABM_ACTIVATE = 0x6;
const ABM_WINDOWPOSCHANGED = 0x9;
const ABEdgeLeft = 0;
const ABEdgeTop = 1;
const ABEdgeRight = 2;
const ABEdgeBottom = 3;
const ABEdgeFloat = 4;
const RECT_Struct = Struct({
left: ref.types.long,
top: ref.types.long,
right: ref.types.long,
bottom: ref.types.long,
});
const APPBARDATA_Struct = Struct({
cbSize: ref.types.uint32,
hWnd: ref.types.long,
uCallbackMessage: ref.types.uint32,
uEdge: ref.types.uint32,
rc: RECT_Struct,
lParam: ref.types.int64,
});
export const shell32 = ffi.Library("shell32.dll", {
SHAppBarMessage: ["pointer", ["int", "pointer"]],
});
const data = new APPBARDATA_Struct();
data.cbSize = APPBARDATA_Struct.size;
const result2 = shell32.SHAppBarMessage(ABM_GETTASKBARPOS, data.ref());
console.log(`ABM_GETTASKBARPOS: ${JSON.stringify(data)}`);
返回
ABM_GETTASKBARPOS: {"cbSize":40,"hWnd":0,"uCallbackMessage":0,"uEdge":0,"rc":{"left":0,"top":3,"right":0,"bottom":1380},"lParam":6184752908800}
为什么rc值不正确?因为另一个python和ahk示例返回正确的0 1380 2560 1440
,而不是0 3 0 1380
?使用偏移量从地址读取的示例。为什么节点ffi显示不正确的RECT值,从0 3 0 1380
开始,而不是从0 1380 2560 1440
开始?我试着把窗口注册为appbar,但什么也没发生。因此,我试着对这一小部分代码进行测试,并注意到rc中返回的值是不正确的。如果他们是不正确的,也许是因为我不能注册我附近的某个地方。但我无法进一步理解..。
发布于 2022-07-12 15:02:02
在像这样定义APPBARDATA_Struct时,我让它正常工作:
const APPBARDATA_Struct = Struct({
cbSize: ref.types.uint32,
hWnd: ref.types.int64,
uCallbackMessage: ref.types.uint32,
uEdge: ref.types.uint32,
rc: RECT_Struct,
lParam: ref.types.int64
});
罪魁祸首是hWnd
类型:)
https://stackoverflow.com/questions/68944250
复制相似问题