libwin32
Version:
Node bindings to native Win32 DLLs through Koffi
95 lines • 4.34 kB
JavaScript
import koffi from 'koffi-cream';
import { cVOID, cBOOL, cINT, cUINT, cLONG, cDWORD, cPDWORD, cHANDLE, cLRESULT, cWPARAM, cLPARAM } from '../ctypes.js';
import { cBSMINFO, BSMINFO, cMSG } from '../structs.js';
import { user32 } from './lib.js';
/**
* Sends a message to the specified recipients. The recipients can be applications, installable drivers,
* network drivers, system-level device drivers, or any combination of these system components.
*
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-broadcastsystemmessagew
*/
export function BroadcastSystemMessage(flags, info, msg, wParam, lParam) {
BroadcastSystemMessage.native ??= user32.func('BroadcastSystemMessageW', cLONG, [cDWORD, koffi.inout(cPDWORD), cUINT, cWPARAM, cLPARAM]);
const pInfo = [info];
return BroadcastSystemMessage.native(flags, pInfo, msg, wParam, lParam) > 0;
}
/**
* Sends a message to the specified recipients. This function is similar to BroadcastSystemMessage
* except that this function can return more information from the recipients.
*
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-broadcastsystemmessageexw
*
*/
export function BroadcastSystemMessageEx(flags, info, msg, wParam, lParam) {
BroadcastSystemMessageEx.native ??= user32.func('BroadcastSystemMessageExW', cLONG, [cDWORD, koffi.inout(cPDWORD), cUINT, cWPARAM, cLPARAM, koffi.out(koffi.pointer(cBSMINFO))]);
const pInfo = [info];
const bsmInfo = new BSMINFO();
const ret = BroadcastSystemMessageEx.native(flags, pInfo, msg, wParam, lParam, bsmInfo);
return ret === 0 ? bsmInfo : ret > 0;
}
/**
* Dispatches a message to a window procedure.
*
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-dispatchmessagew
*/
export function DispatchMessage(msg) {
DispatchMessage.native ??= user32.func('DispatchMessageW', cLRESULT, [koffi.pointer(cMSG)]);
return DispatchMessage.native(msg);
}
/**
* Retrieves a message from the calling thread's message queue.
*
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmessagew
*/
export function GetMessage(hWnd, msgFilterMin = 0, msgFilterMax = 0) {
GetMessage.native ??= user32.func('GetMessageW', cBOOL, [koffi.out(koffi.pointer(cMSG)), cHANDLE, cUINT, cUINT]);
const msg = {};
return GetMessage.native(msg, hWnd, msgFilterMin, msgFilterMax) !== 0 ? msg : null;
}
/**
* Checks the thread message queue for a posted message.
*
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-peekmessagew
*/
export function PeekMessage(hWnd, msgFilterMin, msgFilterMax, removeMsg) {
PeekMessage.native ??= user32.func('PeekMessageW', cBOOL, [koffi.out(koffi.pointer(cMSG)), cHANDLE, cUINT, cUINT, cUINT]);
const msg = {};
return PeekMessage.native(msg, hWnd, msgFilterMin, msgFilterMax, removeMsg) !== 0 ? msg : null;
}
/**
* Indicates to the system that a thread has made a request to terminate (quit).
*
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-postquitmessage
*/
export function PostQuitMessage(exitCode) {
PostQuitMessage.native ??= user32.func('PostQuitMessage', cVOID, [cINT]);
PostQuitMessage.native(exitCode);
}
/**
* Sends a message to the specified window.
*
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendmessagew
*/
export function SendMessage(hWnd, msg, wParam, lParam) {
SendMessage.native ??= user32.func('SendMessageW', cLRESULT, [cHANDLE, cUINT, cWPARAM, cLPARAM]);
return SendMessage.native(hWnd, msg, wParam, lParam);
}
/**
* Translates virtual-key messages into character messages.
*
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-translatemessage
*/
export function TranslateMessage(msg) {
TranslateMessage.native ??= user32.func('TranslateMessage', cBOOL, [koffi.pointer(cMSG)]);
return TranslateMessage.native(msg) !== 0;
}
/**
* Translates virtual-key messages into character messages.
*
* https://learn.microsoft.com/en-us/windows/win32/winmsg/translatemessageex
*/
export function TranslateMessageEx(msg, flags) {
TranslateMessageEx.native ??= user32.func('TranslateMessageEx', cBOOL, [koffi.pointer(cMSG), cUINT]);
return TranslateMessageEx.native(msg, flags) !== 0;
}
//# sourceMappingURL=message.js.map