Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added getWindowAccurateBounds() using DwmGetWindowAttribute to get window bounds without the drop shadow #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#include <napi.h>
#include <shtypes.h>
#include <string>
#include <dwmapi.h>
#include <windows.h>

#pragma comment (lib, "Dwmapi")

typedef int (__stdcall* lp_GetScaleFactorForMonitor) (HMONITOR, DEVICE_SCALE_FACTOR*);

struct Process {
Expand Down Expand Up @@ -201,6 +204,24 @@ Napi::Object getWindowBounds (const Napi::CallbackInfo& info) {
return bounds;
}

Napi::Object getWindowAccurateBounds (const Napi::CallbackInfo& info) {
Napi::Env env{ info.Env () };

auto handle{ getValueFromCallbackData<HWND> (info, 0) };

RECT rect{};
DwmGetWindowAttribute (handle, DWMWA_EXTENDED_FRAME_BOUNDS, &rect, sizeof(RECT));

Napi::Object bounds{ Napi::Object::New (env) };

bounds.Set ("x", rect.left);
bounds.Set ("y", rect.top);
bounds.Set ("width", rect.right - rect.left);
bounds.Set ("height", rect.bottom - rect.top);

return bounds;
}

Napi::String getWindowTitle (const Napi::CallbackInfo& info) {
Napi::Env env{ info.Env () };

Expand Down Expand Up @@ -411,6 +432,7 @@ Napi::Object Init (Napi::Env env, Napi::Object exports) {
exports.Set (Napi::String::New (env, "setWindowOwner"), Napi::Function::New (env, setWindowOwner));
exports.Set (Napi::String::New (env, "initWindow"), Napi::Function::New (env, initWindow));
exports.Set (Napi::String::New (env, "getWindowBounds"), Napi::Function::New (env, getWindowBounds));
exports.Set (Napi::String::New (env, "getWindowAccurateBounds"), Napi::Function::New (env, getWindowAccurateBounds));
exports.Set (Napi::String::New (env, "getWindowTitle"), Napi::Function::New (env, getWindowTitle));
exports.Set (Napi::String::New (env, "getWindowOwner"), Napi::Function::New (env, getWindowOwner));
exports.Set (Napi::String::New (env, "getWindowOpacity"), Napi::Function::New (env, getWindowOpacity));
Expand Down
Loading