Per-monitor DPI awareness issue.

RDH 41 Reputation points
2022-07-05T20:44:29.977+00:00

I have an odd issue when I run with a particular monitor configuration and I use the per monitor DPI awareness context for my app. First here is my current configuration when I open the Display settings.

Monitor 2 Monitor 3 Monitor 1

Monitor 2 is a 1680x1050 resolution, DPI is 100%, landscape and I have Extend desktop to this display.
Monitor 3 is a 3840 x 2160 resolution, DPI is 200%, landscape and is my main display.
Monitor 1 is a 1920x1080 resolution, DPI is 100%, landscape and I have Extend desktop to this display.

My issue is with some tool windows I have for which we save the location for when we close them and when we want to use them again, we create and set the size and position back to the saved data. If the tool window is on the monitor to the right of my main monitor (that is on Monitor 1) AND my frame window is on the main monitor, when I create the tool window and display it, though I get the messages expected, including WM_PAINT, the window does not display. Spyxx shows me the window, the styles, parent etc. and the rectangles used. I note the owner is my main frame and the desktop is the parent.

If the tool window is on the main monitor or the left monitor (Monitor 2), I have no issue. I thought the issue was related to the saved position data.

However, if the owner window, which is my main frame, is on Monitor 2, I have no problem at all. I have started my app and moved the frame so it is on the right monitor (1) and then I run code that creates the tool window. All the messages come thru, including WM_PAINT and the window shows up. I use Spy and it shows me the exact same info as when the window does not show up.

To recap, this issue depends on DPI awareness being per monitor AND my frame window being positioned on my main 4k monitor which has a DPI setting of 200%.

I have also tried, and have no problem if my main frame is on monitor 2, which is to the left of monitor 3. Again, all the data Spyxx shows me is the same and my window shows up on Monitor 1 with no problem. Indeed, I only get this issue if my main frame is on the 4k (main) monitor. It doesn't matter if I start with it on that monitor or not. All I have to do is move my main frame to either of the other monitors.

I do see one thing that may be a clue. When I have my frame on the right monitor (monitor 1), and I show the window, it isn't the right size. But, as soon as I click it it scales up to the correct size. But, I have seen that with office and visual studio, Edge, Chrome and a number of other apps that create a window after the frame is displayed.

I have tried extra calls to Invalidate, ShowWindow(SW_HIDE) followed by ShowWindow(SW_SHOW) to try and get it to display. I still suspect that something thinks the window is off screen but only when my main frame, the owner is on the 4k main monitor. Also, no problem if my awareness is system aware.

Windows development | Windows API - Win32
{count} votes

2 answers

Sort by: Most helpful
  1. Holland, RD (DI SW ME PRD SDE AS) 76 Reputation points
    2022-07-06T13:47:12.42+00:00

    218110-image.png

    I thought it would be outside the display area but Spyxx is showing me otherwise. And, all I have to do to get it to show up is to move my app onto "1" or "2" and then show the window. The window size and position is the same when the call is made to create the window and show it whether my app is on 1, 2 or 3 and Spyxx shows me the same data no matter what monitor my app is on when I create and show the window. But, if my app is on 3, which is my 4k monitor scaled at 200%, the window won't show up. Despite what Spyxx is showing me, since I get WM_PAINT and I can step thru the code, something has to be wrong with where the paint is supposed to be occurring as nothing shows up. And if I use Spyxx to highlight the window, I don't see that happening either if my app is on 3 when I created the window. Spyxx will highlight it if my app widow is not on monitor 3 and I create and display the window.

    0 comments No comments

  2. RDH 41 Reputation points
    2022-07-23T13:19:16.327+00:00

    Hi JunnjieZhu,

    I couldn't click "comment" as every time I did a window popped up saying I had to sign in. Even signing out and back in didn't fix that. I finally clicked your name and on that page, I saw a link back here that I clicked. Now I am able to reply.

    I have made no progress. But, since I have not noticed this before though I run all the time with my configuration, I am beginning to wonder if this is related to an OS update that was applied to my box by our IT. I was recently upgraded to 20H2 build 19042.1766. I have no way of going back to a previous version to test this and so far I have found no one else here that has an older OS as IT rolled this update out across our division (if not the entire company).

    I did notice one other thing a few days ago. I almost never use Edge but I kicked it off and it showed up on my main monitor. I dragged it to my right monitor and the display was messed up. About 2/3rds of the window was masked off. I could see the entire window rectangle but inside the display showed the background of the screen on about half of the window left to right and about 1/3 of the window top to bottom. That is, the display was only correct for part of the upper left area of the window. I mucked around with sizing until it corrected. I have also noticed Teams having the same sort of issue when displaying on that monitor. It acts as if the invalidated rectangle in the display context is not quite right when I see that issue but as long as the window is visible, I can resize or minimize and restore the window (Edge or Teams) to correct the display.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.