TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Changing the primary display using the Win32 API

59 pointsby michidkalmost 3 years ago

9 comments

alin23almost 3 years ago
Most users of my Lunar app (<a href="https:&#x2F;&#x2F;lunar.fyi" rel="nofollow">https:&#x2F;&#x2F;lunar.fyi</a>) that were coming from Windows, have been praising the Windows multi monitor experience while the Mac felt limited in the handling of external monitors.<p>I admit that finding a way to change monitor brightness [1] or turn off individual displays [2] wasn’t as straightforward and needed a lot of reverse engineering. But macOS has a much nicer API [3] for configuring screen position, resolution, mirroring etc.<p>It’s not without its quirks however, I ran into a lot of bugs while developing the Blackout feature when having to create multiple mirror sets with multiple displays in each one. I finally had to reverse engineer the MonitorPanel.framework that’s used by System Preferences to get that functionality. [4]<p>From my understanding, Windows has a native way of disabling a display in software so this wouldn’t even be needed there.<p>[1] <a href="https:&#x2F;&#x2F;alinpanaitiu.com&#x2F;blog&#x2F;journey-to-ddc-on-m1-macs&#x2F;" rel="nofollow">https:&#x2F;&#x2F;alinpanaitiu.com&#x2F;blog&#x2F;journey-to-ddc-on-m1-macs&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;lunar.fyi&#x2F;#blackout" rel="nofollow">https:&#x2F;&#x2F;lunar.fyi&#x2F;#blackout</a><p>[3] <a href="https:&#x2F;&#x2F;developer.apple.com&#x2F;documentation&#x2F;coregraphics&#x2F;quartz_display_services" rel="nofollow">https:&#x2F;&#x2F;developer.apple.com&#x2F;documentation&#x2F;coregraphics&#x2F;quart...</a><p>[4] <a href="https:&#x2F;&#x2F;github.com&#x2F;alin23&#x2F;monitorpanel" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;alin23&#x2F;monitorpanel</a>
评论 #31714528 未加载
moron4hirealmost 3 years ago
The documentation--the very links that OP provided--<i>does</i> say all of this. Look in the &quot;Remarks&quot; section of EnumDisplayDevices and ChangeDisplaySettings.
评论 #31714234 未加载
评论 #31714028 未加载
评论 #31714361 未加载
steinuilalmost 3 years ago
I wrote an F# tool specifically for changing the primary display not too long ago. This is the code that calls the Win32 API to query the displays and set the primary one.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;steinuil&#x2F;SatouinDp&#x2F;blob&#x2F;master&#x2F;DisplayDevice.fs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;steinuil&#x2F;SatouinDp&#x2F;blob&#x2F;master&#x2F;DisplayDev...</a><p>One thing I never figured out was how to map the displays you get from EnumDisplayDevices to the names you see in the display settings, or how to list them in a consistent order.
CrendKingalmost 3 years ago
I thought ChangeDisplaySettingsEx and EnumDisplaySettings are superseded by SetDisplayConfig and QueryDisplayConfig, respectively? <a href="https:&#x2F;&#x2F;github.com&#x2F;MicrosoftDocs&#x2F;windows-driver-docs&#x2F;blob&#x2F;staging&#x2F;windows-driver-docs-pr&#x2F;display&#x2F;scaling-the-desktop-image.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;MicrosoftDocs&#x2F;windows-driver-docs&#x2F;blob&#x2F;st...</a> calls ChangeDisplaySettingsEx &quot;legacy API&quot;.<p>From my experience, changing topology using SetDisplayConfig is straightforward.
评论 #31715019 未加载
unlogalmost 3 years ago
I have been thinking to automate &quot;when an app enters fullscreen, disable all the non-primary screens&quot;. mostly for gaming. Thanks for the MultiMonitorTool hint as that will probably help in combination with AHK! I&#x27;m trying to avoid composite. On a somehow related note, I can&#x27;t recommend MouseUnSnag enough for multimonitors setups <a href="https:&#x2F;&#x2F;github.com&#x2F;MouseUnSnag&#x2F;MouseUnSnag" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;MouseUnSnag&#x2F;MouseUnSnag</a>
评论 #31715004 未加载
dixie_landalmost 3 years ago
The coordinate system reminds me of an interesting trivia I read from The Old New Thing:<p>Windows 9x “parks” minimized windows at (3000, 3000) , a coordinate that is unlikely to be seen, at the time (remember 1024x768 was hi-res?)<p><a href="https:&#x2F;&#x2F;devblogs.microsoft.com&#x2F;oldnewthing&#x2F;20041028-00&#x2F;?p=37453" rel="nofollow">https:&#x2F;&#x2F;devblogs.microsoft.com&#x2F;oldnewthing&#x2F;20041028-00&#x2F;?p=37...</a>
londons_explorealmost 3 years ago
When you have used the display config tool in Windows 9x to XP, you see why this API is like this.<p>The API lets you position each monitor independently on the &#x27;virtual desktop&#x27;, and sometimes there are constraints which mean certain positions aren&#x27;t possible - and the API needs to give feedback on if a position, colour depth and resolution is allowed. Then you hit &#x27;apply&#x27; and the change takes effect.<p>I don&#x27;t really see any better way to implement the API without leaking implementation details which might change in future windows versions.
kulhuralmost 3 years ago
nircmd has this functionality (haven&#x27;t tried it myself so no guarantees)<p><a href="https:&#x2F;&#x2F;nircmd.nirsoft.net&#x2F;setprimarydisplay.html" rel="nofollow">https:&#x2F;&#x2F;nircmd.nirsoft.net&#x2F;setprimarydisplay.html</a><p>It also has a bunch of other useful features like changing the default audio device (something I use every day) and opening the CD tray ;)<p>Anyway, it&#x27;s the best tool I&#x27;ve used for scripting stuff on windows. No GUI, just a bunch of useful or less useful command line utilities.
hdjjhhvvhgaalmost 3 years ago
Respect to all those folks who seem to comfortably write Win32 code in Rust. I&#x27;m so used to the original C&#x2F;C++ syntax I need to constantly translate between these in my brain, it hurts.