Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 892085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:59:42+00:00 2026-05-15T13:59:42+00:00

The actual problem I’m trying to solve is, I want to automatically find out

  • 0

The actual problem I’m trying to solve is, I want to automatically find out the size of the margins around windows. If you can find a better way, please by all means answer that instead of this.

To do this I decided to take a screenshot of a test window and measure the margins. This is simple enough, as I expect no margins will ever be bright pink, but I admit it’s a hack. I use GetWindowRect (py) to get the bounding box, and PIL to grab a screenshot and crop to the bounding box. The problem is that while the crop operates correctly, the bounding box is not accurate. The Windows 7 “Snipping Tool” gets the correct dimensions. How may I do the same?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:59:43+00:00Added an answer on May 15, 2026 at 1:59 pm

    My first thoughts were listed below but if, as you state, you’re certain that GetWindowRect is returning incorrect values, see RESOLUTION further down.


    “What’s wrong with GetSystemMetrics(SM_CXBORDER) and GetSystemMetrics(SM_CYBORDER)?

    The method you’re using seems a very roundabout way of doing it and, if you can call GetWindowRect(), I’m pretty certain you can call GetSystemMetrics() as well.

    One other possibility is to use GetWindowRect to get the entire bounding rectangle for the window and GetClientRect to get the bounding rectangle for the client (non-border) area.

    This should give you something like (100,200),(1000,900) and (112,227),(988,888) respectively and you can work out the top border as 227-200, bottom as 900-888, left as 112-100 and right as 900-888 (27,12,12,12).


    RESOLUTION:

    A bit of investigation turns up this. It’s a thread from 2006 stating that you might not get the correct values from GetWindowsRect. The thread that pointed me to this stated:

    Apps under Vista that are not linked with WINVER=6 will receive a misleading set of values here, that do not account for the extra padding of “glass” pixels Vista Aero applies to the window. This appears to happen even in Aero Basic (without Glass) to retain sizing consistency. The workaround (if you don’t want to set WINVER=6) seems to be to dynamically bind to dwmapi.dll and use GetProcAddress() to obtain the DwmGetWindowAttribute() function, and call it with the DWMWA_EXTENDED_FRAME_BOUNDS argument to request the genuine window frame dimensions.

    So basically, use something like (you may have to use ctypes to do this from Python):

    RECT r;
    HRESULT stat = DwmGetWindowAttribute (
        hwnd,
        DWMWA_EXTENDED_FRAME_BOUNDS,
        &r,
        sizeof(r));
    

    and that should give you the correct bounding rectangle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't figure out what the actual problem is with this. typedef struct _actor
I have the following code: The actual problem is the non-quoted code. I want
Note: The title of this was changed to better reflect the actual problem. I've
Given a MethodDeclarationSyntax object how can I find out the method's declaring type? My
The images below illustrate what the actual problem is So as you can see
I have a problem I'm trying to solve in Java and I cannot figure
EDITED HEADER: more related with the actual problem I'm trying to setup spring security
I've been trying to figure out this XSLT/XML problem for the past few days
I have been trying to solve a problem involving thread communication using wait() and
I am very new to sql.The actual problem is much bigger. I need information

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.