diff --git a/Sources/windows/main.cc b/Sources/windows/main.cc index 1611cba..2f4f469 100644 --- a/Sources/windows/main.cc +++ b/Sources/windows/main.cc @@ -181,10 +181,13 @@ Napi::Value getWindowInformation(const HWND &hwnd, const Napi::CallbackInfo &inf return env.Null(); } - RECT lpRect; - BOOL rectResult = GetWindowRect(hwnd, &lpRect); + RECT lpWinRect; + BOOL rectWinResult = GetWindowRect(hwnd, &lpWinRect); - if (rectResult == 0) { + RECT lpClientRect; + BOOL rectClientResult = GetClientRect(hwnd, &lpClientRect); + + if (rectWinResult == 0 || rectClientResult == 0 ) { return env.Null(); } @@ -194,12 +197,26 @@ Napi::Value getWindowInformation(const HWND &hwnd, const Napi::CallbackInfo &inf owner.Set(Napi::String::New(env, "path"), ownerInfo.path); owner.Set(Napi::String::New(env, "name"), ownerInfo.name); + // bounds window Napi::Object bounds = Napi::Object::New(env); - bounds.Set(Napi::String::New(env, "x"), lpRect.left); - bounds.Set(Napi::String::New(env, "y"), lpRect.top); - bounds.Set(Napi::String::New(env, "width"), lpRect.right - lpRect.left); - bounds.Set(Napi::String::New(env, "height"), lpRect.bottom - lpRect.top); + bounds.Set(Napi::String::New(env, "x"), lpWinRect.left); + bounds.Set(Napi::String::New(env, "y"), lpWinRect.top); + bounds.Set(Napi::String::New(env, "width"), lpWinRect.right - lpWinRect.left); + bounds.Set(Napi::String::New(env, "height"), lpWinRect.bottom - lpWinRect.top); + + // bounds content + POINT rectTopLeft = {lpClientRect.left, lpClientRect.top}; + ClientToScreen(hwnd, &rectTopLeft); + POINT rectBottomRight = {lpClientRect.right, lpClientRect.bottom}; + ClientToScreen(hwnd, &rectBottomRight); + + Napi::Object contentBounds = Napi::Object::New(env); + + contentBounds.Set(Napi::String::New(env, "x"), rectTopLeft.x); + contentBounds.Set(Napi::String::New(env, "y"), rectTopLeft.y); + contentBounds.Set(Napi::String::New(env, "width"), rectBottomRight.x - rectTopLeft.x); + contentBounds.Set(Napi::String::New(env, "height"), rectBottomRight.y - rectTopLeft.y); Napi::Object activeWinObj = Napi::Object::New(env); @@ -208,6 +225,7 @@ Napi::Value getWindowInformation(const HWND &hwnd, const Napi::CallbackInfo &inf activeWinObj.Set(Napi::String::New(env, "title"), getWindowTitle(hwnd)); activeWinObj.Set(Napi::String::New(env, "owner"), owner); activeWinObj.Set(Napi::String::New(env, "bounds"), bounds); + activeWinObj.Set(Napi::String::New(env, "contentBounds"), contentBounds); activeWinObj.Set(Napi::String::New(env, "memoryUsage"), memoryCounter.WorkingSetSize); return activeWinObj; diff --git a/index.d.ts b/index.d.ts index 8acef88..3ceebd6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -95,6 +95,16 @@ export type LinuxResult = { export type WindowsResult = { platform: 'windows'; + + /** + Window content position and size, which excludes the title bar, menu bar, and frame. + */ + contentBounds: { + x: number; + y: number; + width: number; + height: number; + }; } & BaseResult; export type Result = MacOSResult | LinuxResult | WindowsResult; diff --git a/index.test-d.ts b/index.test-d.ts index 1021d7e..7ba88dc 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -39,9 +39,11 @@ if (result) { expectType(result.url); } else if (result.platform === 'linux') { expectType(result); - expectError(result.owner.bundleId); } else { expectType(result); - expectError(result.owner.bundleId); + expectType(result.contentBounds.x); + expectType(result.contentBounds.y); + expectType(result.contentBounds.width); + expectType(result.contentBounds.height); } } diff --git a/readme.md b/readme.md index 475b17c..d67c774 100644 --- a/readme.md +++ b/readme.md @@ -80,6 +80,11 @@ Returns a `Promise` with the result, or `Promise` if there is - `y` *(number)* - `width` *(number)* - `height` *(number)* +- `contentBounds` *(Object)* - Window content position and size, which excludes the title bar, menu bar, and frame *(Windows only)* + - `x` *(number)* + - `y` *(number)* + - `width` *(number)* + - `height` *(number)* - `owner` *(Object)* - App that owns the window - `name` *(string)* - Name of the app - `processId` *(number)* - Process identifier