none
GetWindowRect on Windows 10

    Question

  • I need to discover exactly if any part of the main frame in my App (CFrameWndEx) is loosing visible area (virtual screen).
    I tried to use API function GetWindowRect for the main frame.
    I got (for NOMAXIMIZED window) litle bit confusing results:

    A measure GetWindowRect versus screenshot:
    W7 = rectangles are the same,
    W8 = rectangles are the same,
    W8.1 = rectangles are the same,
    W10 = RECTANGLES ARE DIFFERENT, the wide of real raster picture is smaller by 16 px and the high is smaller by 7 px.
    I tried it on a few PCs with various grafic cards, I obtained always the same result.

    My question is this:
    Which function can I use for a measure of the main frame, when result of Windows API GetWindowRect is (for W10) invalid?

    Thank you boys (and girls :-) for help and ideas.
    Lubomir

    Sunday, May 13, 2018 7:52 AM

All replies

  • Hi,

    thanks for posting here.

    >>Which function can I use for a measure of the main frame, when result of Windows API GetWindowRect is (for W10) invalid?

    Please check if the the styles of the window are the same. For example, the border width and height.

    You could use GetWindowInfo to get the height and the width of the window border to see the issues is related to these borders.

    Hope this could be help of you.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, May 13, 2018 9:06 AM
  • Which versions of Windows 10 have you tried this on? Is it possible that you can get more versions of Windows 10 to try this on? Is it possible that you can test this on the Window Insider builds?

    The reason why I ask this is simple. First, the GetWindowRect documentation has not documented any change in behaviour for Windows 10, and the bounding rectangle is expected to be the minimum bounding rectangle for the window. If the function is reporting a size that is not the minimum bounding rectangle then the function is not doing what you expect it to. This is a bug.

    Another thing to do is make sure that you have DPI awareness set to Per Monitor or Per Monitor v2 if it is available (System if neither of these is available). This makes sure that you can get rid of the Windows DPI virtualisation from the problem.

    So your question really should be:

    "Is this a bug, and how do I report it to Microsoft to get it fixed."


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Sunday, May 13, 2018 2:41 PM
  • Thank you for your tip, but no, it is not the way.

    1) It is not easy to work with DwmGetWindowAttribute, because Dwmapi.lib is not in Visual Studio 2015 (professional) equipment, the result is linker error, unresolved external...

    2) so it is necessary to load DwmGetWindowAttribute from dwmapi.dll
    and after that all rubbish in

    .h

    typedef HRESULT(*LP_DwmGetWindowAttribute)(HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute);
    LP_DwmGetWindowAttribute pDwmGetWindowAttribute;

    .cpp

    HINSTANCE hInst = LoadLibrary(_T("dwmapi.dll"));
    pDwmGetWindowAttribute = (LP_DwmGetWindowAttribute)GetProcAddress(hInst, "DwmGetWindowAttribute");
    RECT ExendedRect;
    HRESULT hr = pDwmGetWindowAttribute(pMainFrm->m_hWnd, DWMWA_EXTENDED_FRAME_BOUNDS, &ExendedRect, sizeof(RECT));
    FreeLibrary(hInst);

    You obtain in ExendedRect any rect bigger by dx=68, dy=38 ???
    which is proably the useless shade around work window area...

    If I would be skilled enough and I would be able to answer any question heres, I would first ensure myselv if my answer is usefull.

    Lubomir

    Friday, May 18, 2018 5:05 AM
  • Hello.
    Thank you for your comment.

    My Windows version: Windows 10 Enterprise 1709 16299.309
    I dont try and I dont use Windows Insider builds.
    All systems are stable (should be stable) builds from MSDN download.

    I dont know what is DPI awareness set.
    As far as I know, I dont use it.
    Before publishing my ask for help, I tried to measure the main frame rect on 3 computers with various configurations and with different screen sizes. All with the same results.
    Even virtual machine on VMware Workstation 14 Player gave to me the same result.

    Did you ever try to report any bug to the Microsoft?
    I tried it once already.
    In MSDN there are are i think two reports for free.
    After long and tyring administrative process i got help from MS ... BIG ZERO.

    Tank you again for your comment.
    Regards.
    Lubomir

    Friday, May 18, 2018 5:31 AM
  • EZ, check what is your screen scale, because if you have a 125% of scale, you must to multiply the rectangle for this percent, 1.25, but only the width and the height.

    Bye!


    • Edited by VictorQR Friday, May 24, 2019 10:12 PM
    Friday, May 24, 2019 10:11 PM