Re: What is the correct way to response to the wxEVT_DPI_CHANGED event?
Maarten Bent <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
When I move the application between displays with different DPI, I only
get breakpoint2 (OnDPIChanged).
When I have the application on a display, and change the DPI of that
display in the Windows settings, it hits both breakpoints.
I get breakpoint2 first (OnDPIChanged) and then breakpoint1 (via
OnDisplayChanged). So opposite to what you get.
(Windows 10.0.19045, latest Visual Studio 2022).
Even without breakpoints I can see this behavior, because it shows
'Display resolution was changed' in the status bar, and not ''DPI
changed: ...'.
These events are direct responses to Windows messages (WM_DPICHANGED and
WM_DISPLAYCHANGE).
We don't have any influence on the order of these events.
Maarten
On 3 Apr 2023 14:41, AsmWarrior wrote:
> Hi, everyone, I still have question about the DPI change handling.
>
> Here is the patch I made to the "display" sample code:
>
> diff --git a/samples/display/display.cpp b/samples/display/display.cpp
> index 58f18de..fb028ef 100644
> --- a/samples/display/display.cpp
> +++ b/samples/display/display.cpp
> @@ -356,6 +356,10 @@ void MyFrame::PopuplateWithDisplayInfo()
> sizer->Add(new wxStaticText(page, wxID_ANY, "Current: "));
> sizer->Add(new wxStaticText(page, Display_CurrentMode,
> currentMode));
>
> + wxSize dpi = GetDPI();
> + wxSize newSize = wxWindow::FromDIP(wxSize(250,50));
> + sizer->Add(new wxButton(page, wxID_ANY, _T("Hello World"),
> wxDefaultPosition, newSize));
> +
> sizerTop->Add(new wxButton(page, Display_ResetMode, "&Reset
> mode"),
> wxSizerFlags().Centre().Border());
> #endif // wxUSE_DISPLAY
>
>
> And now I try to set two breakpoints. The breakpoint1 in the above
> code, in the line of Add() function call. The breakpoint2 is set
> inside the function:
>
> void MyFrame::OnDPIChanged(wxDPIChangedEvent& event)
> {
> wxLogStatus(this, "DPI changed: was %d*%d, now %d*%d",
> event.GetOldDPI().x, event.GetOldDPI().y,
> event.GetNewDPI().x, event.GetNewDPI().y);
>
> event.Skip();
> }
> Now, I try to run the executable when the initial DPI scaling is 100%,
> I first got breakpoint1 hit, and I see the "newSize" is 250*50. Now, I
> try to change the DPI scaling to 150%, and after that, I got
> breakpoint1 hit again, I see the value of "newSize" is still 250*50.
> After that I got the breakpoint2 hit.
>
> I expect that when the second time the breakpoint1 got hit, the
> newSize value should be 375*75, because I have already changed the DPI
> scaling.
> Also, I expect that the breakpoint2 should be hit before the
> breakpoint1 after the DPI changes?
>
> Any one can explain this?
>
> Thanks.
> Asmwarrior
> --
> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
> ---
> You received this message because you are subscribed to the Google
> Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wx-users/d55b16b5-2aed-462c-940b-9e0e8ea96a0bn%40googlegroups.com
> <https://groups.google.com/d/msgid/wx-users/d55b16b5-2aed-462c-940b-9e0e8ea96a0bn%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/a0354f3f-7c07-e2fe-7b56-5b346cc40669%40gmail.com.