Skip to content

Commit

Permalink
Fixed window size/position issue @ highdpi
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Oct 26, 2019
1 parent 35e6967 commit f6f43f9
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Installer/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0.1
2.1.0.32
13 changes: 8 additions & 5 deletions src/MCEControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup />
<PropertyGroup />
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System">
<Name>System</Name>
Expand Down Expand Up @@ -303,6 +309,8 @@
<Compile Include="WindowsInput\WindowsInputDeviceStateAdaptor.cs" />
<Compile Include="WindowsInput\WindowsInputMessageDispatcher.cs" />
<EmbeddedResource Include="Resources\MCEControl.commands" />
<Resource Include="app.manifest" />
<None Include="app.config" />
<None Include="MCEControl1.ruleset" />
<None Include="Resources\Trafficlight-gray-icon.bmp" />
<None Include="Resources\Trafficlight-gray-icon.png" />
Expand Down Expand Up @@ -336,11 +344,6 @@
<EmbeddedResource Include="Resources\Builtin.commands" />
<None Include="Resources\Trafficlight-red-icon.png" />
</ItemGroup>
<ItemGroup>
<None Include="app.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
Expand Down
15 changes: 11 additions & 4 deletions src/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.Win32.Security;
using log4net;
using Microsoft.Win32;
using System.Drawing;

[assembly: System.CLSCompliant(true)]
namespace MCEControl {
Expand Down Expand Up @@ -205,10 +206,6 @@ private void mainWindow_Load(object sender, EventArgs e) {
log4.Info($"Logger: Logging to {Logger.Instance.LogFile}");
Logger.Instance.TextBoxThreshold = LogManager.GetLogger("MCEControl").Logger.Repository.LevelMap[Instance.Settings.TextBoxLogThreshold];

// Location can not be changed in constructor, has to be done here
Location = Settings.WindowLocation;
Size = Settings.WindowSize;

if (cmdWindow == null)
cmdWindow = new CommandWindow();

Expand All @@ -226,6 +223,16 @@ private void mainWindow_Load(object sender, EventArgs e) {
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);

// Location can not be changed in constructor, has to be done here
// Use Window's default for location initially. Size needs highDPI conversion.
if (Settings.WindowLocation.IsEmpty || Settings.WindowSize.IsEmpty) {
Size = new Size(this.LogicalToDeviceUnits(1024), this.LogicalToDeviceUnits(640));
}
else {
Location = Settings.WindowLocation;
Size = Settings.WindowSize;
}

SetStatus($"Version: {Application.ProductVersion}");
Start();
}
Expand Down
4 changes: 2 additions & 2 deletions src/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,8 +1244,8 @@ public class AppSettings : ICloneable {
public int SerialServerDataBits;
public StopBits SerialServerStopBits;
public Handshake SerialServerHandshake;
public Point WindowLocation = new Point(120, 50);
public Size WindowSize = new Size(640, 400);
public Point WindowLocation;
public Size WindowSize;
public bool ShowCommandWindow;
public bool ActivityMonitorEnabled = false;
public string ActivityMonitorCommand = "activity";
Expand Down
74 changes: 74 additions & 0 deletions src/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->

<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

</application>
</compatibility>

<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>

<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>

0 comments on commit f6f43f9

Please sign in to comment.