Skip to content

oledid-js/windows-api-show-window

Repository files navigation

windows-api-show-window Build Status npm npm

Call ShowWindow from node via ffi-napi

Win32 only!

What can I do with this?

Hide, show, maximize or minimize a window where you know either the window's hWnd or the process' PID.

The helper methods (methods not starting with "winApi") will only work when you are running node.exe as the main process, unlike running cmd.exe -> node, which makes cmd.exe the main process. This is because they use process.pid as the PID.

Installing

npm install --save windows-api-show-window

Testing (manual only)

// run with win + r
node {repository-location}/test/index.js

Usage

var api = require("windows-api-show-window");

api.hideCurrentProcessWindow().then(() => {
    // console window is hidden
}).catch(err => {
    console.error(err);
});

api.showCurrentProcessWindow().then(() => {
    // console window is visible
}).catch(err => {
    console.error(err);
});

api.maximizeCurrentProcessWindow().then(() => {
    // console window is maximized
}).catch(err => {
    console.error(err);
});

api.minimizeCurrentProcessWindow().then(() => {
    // console window is minimized
}).catch(err => {
    console.error(err);
});

api.restoreCurrentProcessWindow().then(() => {
    // console window is restored
}).catch(err => {
    console.error(err);
});

Advanced usage

api.winApiGetHwndFromPid(process.pid).then(hWnd => {
    // do something with hWnd
}).catch(err => {
    console.error(err);
});

api.winApiShowWindow(hWnd, api.SW_HIDE).then(() => {
    // custom calls to ShowWindow
}).catch(err => {
    console.error(err);
});

Troubleshooting

If node-gyp fails: Check out the node-gyp documentation and felixrieseberg/windows-build-tools

Relevant