wxDPIChangedEvent not triggering Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxDPIChangedEvent not triggering

Post by PB »

To make things clear, you do not have to use a manifest shipped with wxWidgets. All you need is to ensure that the application is PMv2 DPI-aware.

wxWidgets ships those manifests just for convenience, and since many applications still may not be able to willing to support PMv2 awareness, it is an opt-in.

I also do not understand why after all those years MSVS 2019 still does not allow setting PMv2: Is it for compatibility with older systems?
GamerX
Earned a small fee
Earned a small fee
Posts: 17
Joined: Wed Oct 20, 2021 3:06 pm

Re: wxDPIChangedEvent not triggering

Post by GamerX »

Yeah I understand that, I was just puzzled that setting the application to Per Monitor DPI-aware via the Visual Studio properties page was insufficient, guess Microsoft still has to fix that and provide a PMv2 option there.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxDPIChangedEvent not triggering

Post by PB »

Confusingly enough, manifest can set elements dpiAware and dpiAwareness (which is needed for PMv2):
https://docs.microsoft.com/en-us/window ... s#dpiaware
https://docs.microsoft.com/en-us/window ... iawareness

Both are set in manifests shipped with wxWidgets, but per monitor awareness is probably supported there only when PMv2 is on (see the code I linked before).

Either way, good luck with your coding.
GamerX
Earned a small fee
Earned a small fee
Posts: 17
Joined: Wed Oct 20, 2021 3:06 pm

Re: wxDPIChangedEvent not triggering

Post by GamerX »

Thanks, have a nice day.
GamerX
Earned a small fee
Earned a small fee
Posts: 17
Joined: Wed Oct 20, 2021 3:06 pm

Re: wxDPIChangedEvent not triggering

Post by GamerX »

PB wrote: Wed Oct 20, 2021 8:56 pm Confusingly enough, manifest can set elements dpiAware and dpiAwareness (which is needed for PMv2):
https://docs.microsoft.com/en-us/window ... s#dpiaware
https://docs.microsoft.com/en-us/window ... iawareness

Both are set in manifests shipped with wxWidgets, but per monitor awareness is probably supported there only when PMv2 is on (see the code I linked before).

Either way, good luck with your coding.
Sorry to bother you guys again, but I stumbled upon another problem, these are the steps to replicate it (project properties are still the same as suggested by PB earlier)
1) I made a new .rc file in VS2019 via Add => New Item => Resource File (.rc)
2) I added the line #include "wx/msw/wx.rc" to the new .rc file
3) I saved the .rc file
4) Everything works fine, DPI scaling is ok, all is well
5) I added a bitmap resource to my project via Add => Resource... => Bitmap
6) I tried to save my .rc file
7) VS 2019 complains that it "cannot load external resource file" and after that, my entire project is cluttered with tons of resources from wxWidgets and the bitmap I added earlier can´t be used either and every time I try to open the .rc file again, it gives several errors about some IDs being defined twice.
8) DPI scaling is back to stretching the window too at that point from what I am seeing.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxDPIChangedEvent not triggering

Post by PB »

GamerX wrote: Thu Oct 21, 2021 6:05 am ....my entire project is cluttered with tons of resources from wxWidgets
What does that mean?

I would say you need to clear your resource file. It is a plain text file, so it should be easy.

I am not sure how your resource file looked before but it seems MSVS broke it, nothing to do with wxWidgets.

How do you load windows resources in the application. If using wxWidgets (e.g., with wxBitmap), make sure you understand how to use the resource ID (ordinal vs string). There is at least one thread about it on this forum.

It may be just me, but I think it is simplest to add resources to the .rc fie by hand. With wxWidgets, you do not need a resource editor to create dialog templates, menus, toolbars...

I would also recommend starting a new thread for a new problem next time, so that the thread topic matches the content.
GamerX
Earned a small fee
Earned a small fee
Posts: 17
Joined: Wed Oct 20, 2021 3:06 pm

Re: wxDPIChangedEvent not triggering

Post by GamerX »

Yeah you're right, it's just that I wouldn't even have bothered adding that wxwidgets .rc file if it weren't for fixing the DPI awareness. By cluttering I mean that the solution explorer suddenly shows various resources from wx after the initial error message.

The issue basically occurs whenever VS2019 tries to modify the .rc file and it already has the #include "wx/msw/wx.rc" line in it. It doesn't matter, it even happens with a fresh .rc file. When having an empty .rc file (with or without that one wx line in it), the resource editor won't even be able to open it anymore. It needs all those APS Studio definitions in it to be compatible with the VS editor. VS automatically adds them when creating a new resource file (Add => New file => Resource file).

I didn't modify my .rc in any other way, just a fresh .rc created by VS, added the line to it, tried to add a bitmap resource to the .rc and the problem occurred.

I mean, maybe it's easier to just go with a custom manifest file that enables DPI awareness, in order to preserve the resource editor functionality of VS. Or I could do what you suggested and manually add each resource to the .rc file. Because this clearly seems like a VS2019 issue and not something that could be fixed by modifying the wx.rc, right?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxDPIChangedEvent not triggering

Post by PB »

I would advise to include wxWidgets .rc file, it contains few things your app may (or may not) need.

What about going another way: Just use the .rc file generated by MSVS as the base and put the wxWidgets specific #include and #define there? Additionally, I think that wxUSE_NO_MANIFEST can be added to wxUSE_RC_MANIFEST;wxUSE_DPI_AWARE_MANIFEST=2 in the project's Resource compiler defines. Or did you try that (i.e, what you meant by "fresh" .rc file) and it did not work either?

I do not use MSVS resource editor so...

EDIT
Adding wx.rc to the .rc file generated by MSVS works for me, at least build- and run-wise. I added it here:
#ifndef APSTUDIO_INVOKED
#include "targetver.h"
#include "wx/msw/wx.rc"
#endif
I moved wxUSE_NO_MANIFEST=0 to the Resource Compiler defines.

I think I had to remove the app .rc file and readd it to the project. Just replacing seemed to have left some dead resources in the project

EDIT2
It seems that MSVS Resource Editor dislikes any manual modification of the .rc file and refuses to edit it. I am probably missing something, as I wrote I am not really familiar with it.
GamerX
Earned a small fee
Earned a small fee
Posts: 17
Joined: Wed Oct 20, 2021 3:06 pm

Re: wxDPIChangedEvent not triggering

Post by GamerX »

Yeah, the issue isn´t compiling, it happens when the resource editor tries to modify the file after it was manually edited (e.g. by adding the line for the wx .rc). I´ll go with manually editing the .rc file for now, that should be fine. Although I stumbled upon a new issue, gonna make a new thread for that though. Thanks again for the help.
Post Reply