Forked from fronterior/electron-prevent-zorder-change.js
Last active
December 26, 2023 20:36
-
-
Save tuj84257/ee92a1e000a3922d9d526e3ac603919b to your computer and use it in GitHub Desktop.
WM_WINDOWPOSCHANGING Message Handler for Electron Application, which is always fixed on the floor.
This file contains hidden or 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
// Node.js & Electron reference : https://stackoverflow.com/a/58473299 | |
// C++ reference : https://stackoverflow.com/a/65052538 | |
// Environment: | |
// - Windows 10 | |
// - Nodejs v14.17.6 | |
// Dependencies: | |
// - [email protected] | |
// - [email protected] | |
// - [email protected] | |
// - [email protected] | |
/* // example in Electron main process. | |
const { | |
SetWindowPos, | |
HWND_BOTTOM, | |
SWP_SHOWWINDOW, | |
} = require('win-setwindowpos'); | |
SetWindowPos( | |
win.getNativeWindowHandle(), | |
HWND_BOTTOM, | |
0, | |
700, | |
800, | |
600, | |
SWP_SHOWWINDOW | |
); | |
preventZOrderChange(win); | |
*/ | |
const ref = require('ref-napi'); | |
const StructType = require('ref-struct-di')(ref); | |
const { | |
SetWindowPos, | |
HWND_BOTTOM, | |
SWP_NOACTIVATE, | |
SWP_NOSIZE, | |
SWP_NOMOVE, | |
SWP_NOZORDER, | |
SWP_NOSENDCHANGING, | |
} = require('win-setwindowpos'); | |
const WINDOWPOS = StructType({ | |
hwnd: ref.types.int32, | |
hwndInsertAfter: ref.types.int32, | |
x: ref.types.int32, | |
y: ref.types.int32, | |
cx: ref.types.int32, | |
cy: ref.types.int32, | |
flags: ref.types.uint32, | |
}); | |
const WM_WINDOWPOSCHANGING = 0x0046; | |
const preventZOrderChange = win => { | |
win.hookWindowMessage(WM_WINDOWPOSCHANGING, (wParam, lParam)=> { | |
const buf = Buffer.alloc(8); | |
buf.type = ref.refType(WINDOWPOS); | |
lParam.copy(buf); | |
const actualStructDataBuffer = buf.deref(); | |
const windowPos = actualStructDataBuffer.deref(); | |
const newFlags = windowPos.flags | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE; | |
actualStructDataBuffer.writeUInt32LE(newFlags, 6); | |
actualStructDataBuffer.writeUInt32LE(HWND_BOTTOM, 1); | |
}); | |
}; | |
module.exports = { | |
WINDOWPOS, | |
WM_WINDOWPOSCHANGING, | |
preventZOrderChange, | |
}; |
Hi @Thesiva7, I hope I am not responding too late. I think you might need to upgrade the version of node you're running.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @tuj84257, while running your code i am getting TypeError: actualStructDataBuffer.writeUInt32LE is not a function
Could you help me on this?