Question: Getting the display information on Win32
See original GitHub issueI am trying to convert an existing UWP project to WinUI/Win32.
The project uses DisplayInformation.GetForCurrentView()
in one of the of the controls to get DPI information, which then results in the following error:
Windows.Graphics.Display: GetForCurrentView must be called on a thread that is associated with a CoreWindow.
CoreWindow
is a UWP thing, so I’m assuming this function is not supported on Win32. What would be the correct way to get the current DPI (and detect changes to the DPI) from a WinUI/Win32 app?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
retrieve multiple display information using win32/C++
Use the EnumDisplayMonitors() function, passing NULL for the first 2 arguments. Your callback gets the monitors in numeric order with their ...
Read more >Display Devices Reference - Win32 apps
The DISPLAYCONFIG_MODE_INFO_TYPE enumeration specifies that the information that is contained within the DISPLAYCONFIG_MODE_INFO structure is ...
Read more >Solved Write a computer program as a Win32 console
You program shall receive information from the user as the user types in two numbers to be processed. Your program shall NOT print...
Read more >How do Win32 executables display incompatibility ...
Short answer: every EXE file begins with a DOS executable. Long answer: The MS-DOS Header. Every PE file begins with a small MS-DOS® ......
Read more >Visual Studio Code Frequently Asked Questions
Yes, VS Code is free for private or commercial use. See the product license for details. How to disable telemetry reporting. VS Code...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@marb2000 Sorry for the late response, but using the Loaded/Unloaded events is indeed a good way ensure the control is attached to a XamlRoot.
Hi @rick-palmsens ,
there is currently no API exposed to get DPI information. But you can go via Win32 PInvoke right now.
Steps to try it:
To make it complete, these are all using directives that I have in the MainWindow.xaml.cs file:
That’s it.
Take also a look at the WinUI 3 Demos repository from @marb2000 that contains more Window interop scenarios. There is also a center window branch that shows you how to center a WinUI desktop window: https://github.com/microsoft/WinUI-3-Demos/tree/CenterWindow/src/Build2020Demo