Browse Source

Adding Native Helpers to do DPI aware windows

pull/20/head
Joseph Finney 5 years ago
parent
commit
aaa8fa02f1
  1. 1
      .gitignore
  2. 40
      NativeHelpers/AssemblyInfo.cpp
  3. 108
      NativeHelpers/NativeHelpers.vcxproj
  4. 38
      NativeHelpers/NativeHelpers.vcxproj.filters
  5. 75
      NativeHelpers/PerMonitorDPIHelpers.cpp
  6. 30
      NativeHelpers/PerMonitorDPIHelpers.h
  7. 155
      NativeHelpers/PerMonitorDPIWindow.cpp
  8. 81
      NativeHelpers/PerMonitorDPIWindow.h
  9. 13
      NativeHelpers/pch.cpp
  10. 12
      NativeHelpers/pch.h
  11. 14
      Text-Grab.sln
  12. 2
      Text-Grab/AssemblyInfo.cs
  13. 5
      Text-Grab/MainWindow.xaml
  14. 3
      Text-Grab/MainWindow.xaml.cs
  15. 9
      Text-Grab/Text-Grab.csproj

1
.gitignore

@ -26,6 +26,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
./NativeHelpers/Debug/
# Visual Studio 2015/2017 cache/options directory
.vs/

40
NativeHelpers/AssemblyInfo.cpp

@ -0,0 +1,40 @@
#include "pch.h"
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly:AssemblyTitleAttribute("NativeHelpers")];
[assembly:AssemblyDescriptionAttribute("")];
[assembly:AssemblyConfigurationAttribute("")];
[assembly:AssemblyCompanyAttribute("")];
[assembly:AssemblyProductAttribute("NativeHelpers")];
[assembly:AssemblyCopyrightAttribute("Copyright (c)")];
[assembly:AssemblyTrademarkAttribute("")];
[assembly:AssemblyCultureAttribute("")];
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly:AssemblyVersionAttribute("1.0.*")];
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
//[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];

108
NativeHelpers/NativeHelpers.vcxproj

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{938E65D0-EC9C-4181-87CA-A43D4747610D}</ProjectGuid>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Keyword>ManagedCProj</Keyword>
<RootNamespace>NativeHelpers</RootNamespace>
<SccProjectName>
</SccProjectName>
<SccAuxPath>
</SccAuxPath>
<SccLocalPath>
</SccLocalPath>
<SccProvider>
</SccProvider>
<ProjectName>NativeHelpers</ProjectName>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CLRSupport>true</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel />
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="PerMonitorDPIHelpers.h" />
<ClInclude Include="PerMonitorDPIWindow.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp" />
<ClCompile Include="PerMonitorDPIHelpers.cpp" />
<ClCompile Include="PerMonitorDPIWindow.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

38
NativeHelpers/NativeHelpers.vcxproj.filters

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="PerMonitorDPIWindow.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PerMonitorDPIHelpers.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PerMonitorDPIWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PerMonitorDPIHelpers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

75
NativeHelpers/PerMonitorDPIHelpers.cpp

@ -0,0 +1,75 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
//Main helper class that provides helper functions used by the PerMonitorDPIWindow class
#include "pch.h"
#include "PerMonitorDPIHelpers.h"
// Returns the DPI awareness of the current process
PROCESS_DPI_AWARENESS NativeHelpers::PerMonitorDPIHelper::GetPerMonitorDPIAware()
{
PROCESS_DPI_AWARENESS awareness;
HANDLE hProcess;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, GetCurrentProcessId());
auto result = GetProcessDpiAwareness(hProcess, &awareness);
if (S_OK != result)
{
throw gcnew System::Exception(L"Unable to read process DPI level");
}
return awareness;
}
//Sets the current process as Per_Monitor_DPI_Aware. Returns True if the process was marked as Per_Monitor_DPI_Aware
BOOL NativeHelpers::PerMonitorDPIHelper::SetPerMonitorDPIAware()
{
auto result = SetProcessDpiAwareness(PROCESS_DPI_AWARENESS::PROCESS_PER_MONITOR_DPI_AWARE);
if (S_OK != result)
{
return FALSE;
}
return TRUE;
}
//Returns the DPI of the window handle passed in the parameter
double NativeHelpers::PerMonitorDPIHelper::GetDpiForWindow(IntPtr hwnd)
{
return GetDpiForHwnd(static_cast<HWND>(hwnd.ToPointer()));
}
double NativeHelpers::PerMonitorDPIHelper::GetDpiForHwnd(HWND hWnd)
{
auto monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
UINT newDpiX;
UINT newDpiY;
if (FAILED(GetDpiForMonitor(monitor, MONITOR_DPI_TYPE::MDT_EFFECTIVE_DPI, &newDpiX, &newDpiY)))
{
newDpiX = 96;
newDpiY = 96;
}
return ((double) newDpiX);
}
//Returns the system DPI
double NativeHelpers::PerMonitorDPIHelper::GetSystemDPI()
{
int newDpiX(0);
auto hDC = GetDC(NULL);
newDpiX = GetDeviceCaps(hDC, LOGPIXELSX);
ReleaseDC(NULL, hDC);
return (double)newDpiX;
}

30
NativeHelpers/PerMonitorDPIHelpers.h

@ -0,0 +1,30 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#include "pch.h"
using namespace System;
namespace NativeHelpers
{
public ref class PerMonitorDPIHelper
{
public:
static BOOL SetPerMonitorDPIAware();
static PROCESS_DPI_AWARENESS GetPerMonitorDPIAware();
static double GetDpiForWindow(IntPtr hwnd);
static double GetSystemDPI();
private:
static double GetDpiForHwnd(HWND hWnd);
};
}

155
NativeHelpers/PerMonitorDPIWindow.cpp

@ -0,0 +1,155 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
#include "PerMonitorDPIWindow.h"
namespace NativeHelpers
{
//Constructor; sets the current process as Per_Monitor_DPI_Aware
PerMonitorDPIWindow::PerMonitorDPIWindow(void)
{
Loaded += gcnew System::Windows::RoutedEventHandler(this, &NativeHelpers::PerMonitorDPIWindow::OnLoaded);
if (PerMonitorDPIHelper::SetPerMonitorDPIAware())
{
m_perMonitorEnabled = true;
}
else
{
throw gcnew System::Exception(L"Enabling Per-monitor DPI Failed. Do you have [assembly: DisableDpiAwareness] in your assembly manifest [AssemblyInfo.cs]?");
}
}
PerMonitorDPIWindow::~PerMonitorDPIWindow()
{
}
//OnLoaded Handler: Adjusts the window size and graphics and text size based on current DPI of the Window
void PerMonitorDPIWindow::OnLoaded(Object^ , RoutedEventArgs^ )
{
// WPF has already scaled window size, graphics and text based on system DPI. In order to scale the window based on monitor DPI, update the
// window size, graphics and text based on monitor DPI. For example consider an application with size 600 x 400 in device independent pixels
// - Size in device independent pixels = 600 x 400
// - Size calculated by WPF based on system/WPF DPI = 192 (scale factor = 2)
// - Expected size based on monitor DPI = 144 (scale factor = 1.5)
// Similarly the graphics and text are updated updated by applying appropriate scale transform to the top level node of the WPF application
// Important Note: This method overwrites the size of the window and the scale transform of the root node of the WPF Window. Hence,
// this sample may not work "as is" if
// - The size of the window impacts other portions of the application like this WPF Window being hosted inside another application.
// - The WPF application that is extending this class is setting some other transform on the root visual; the sample may
// overwrite some other transform that is being applied by the WPF application itself.
if (m_perMonitorEnabled)
{
m_source = (HwndSource^) PresentationSource::FromVisual((Visual^) this);
HwndSourceHook^ hook = gcnew HwndSourceHook(this, &PerMonitorDPIWindow::HandleMessages);
m_source->AddHook(hook);
//Calculate the DPI used by WPF; this is same as the system DPI.
m_wpfDPI = 96.0 * m_source->CompositionTarget->TransformToDevice.M11;
//Get the Current DPI of the monitor of the window.
m_currentDPI = NativeHelpers::PerMonitorDPIHelper::GetDpiForWindow(m_source->Handle);
//Calculate the scale factor used to modify window size, graphics and text
m_scaleFactor = m_currentDPI / m_wpfDPI;
//Update Width and Height based on the on the current DPI of the monitor
Width = Width * m_scaleFactor;
Height = Height * m_scaleFactor;
//Update graphics and text based on the current DPI of the monitor
UpdateLayoutTransform(m_scaleFactor);
}
}
//Called when the DPI of the window changes. This method adjusts the graphics and text size based on the new DPI of the window
void PerMonitorDPIWindow::OnDPIChanged()
{
m_scaleFactor = m_currentDPI / m_wpfDPI;
UpdateLayoutTransform(m_scaleFactor);
DPIChanged(this, EventArgs::Empty);
}
void PerMonitorDPIWindow::UpdateLayoutTransform(double scaleFactor)
{
// Adjust the rendering graphics and text size by applying the scale transform to the top level visual node of the Window
if (m_perMonitorEnabled)
{
auto child = GetVisualChild(0);
if (m_scaleFactor != 1.0) {
ScaleTransform^ dpiScale = gcnew ScaleTransform(scaleFactor, scaleFactor);
child->SetValue(Window::LayoutTransformProperty, dpiScale);
}
else
{
child->SetValue(Window::LayoutTransformProperty, nullptr);
}
}
}
// Message handler of the Per_Monitor_DPI_Aware window. The handles the WM_DPICHANGED message and adjusts window size, graphics and text
// based on the DPI of the monitor. The window message provides the new window size (lparam) and new DPI (wparam)
IntPtr PerMonitorDPIWindow::HandleMessages(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, bool% )
{
double oldDpi;
switch (msg)
{
case WM_DPICHANGED:
LPRECT lprNewRect = (LPRECT)lParam.ToPointer();
SetWindowPos(static_cast<HWND>(hwnd.ToPointer()), 0, lprNewRect->left, lprNewRect->top, lprNewRect->right - lprNewRect->left, lprNewRect->bottom - lprNewRect->top, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
oldDpi = m_currentDPI;
m_currentDPI = static_cast<int>(LOWORD(wParam.ToPointer()));
if (oldDpi != m_currentDPI)
{
OnDPIChanged();
}
break;
}
return IntPtr::Zero;
}
System::String^ PerMonitorDPIWindow::GetCurrentDpiConfiguration()
{
System::Text::StringBuilder^ stringBuilder = gcnew System::Text::StringBuilder();
auto awareness = NativeHelpers::PerMonitorDPIHelper::GetPerMonitorDPIAware();
auto systemDpi = NativeHelpers::PerMonitorDPIHelper::GetSystemDPI();
switch (awareness)
{
case PROCESS_DPI_AWARENESS::PROCESS_DPI_UNAWARE:
stringBuilder->AppendFormat(gcnew System::String(L"Application is DPI Unaware. Using {0} DPI."), systemDpi);
break;
case PROCESS_DPI_AWARENESS::PROCESS_SYSTEM_DPI_AWARE:
stringBuilder->AppendFormat(gcnew System::String(L"Application is System DPI Aware. Using System DPI:{0}."), systemDpi);
break;
case PROCESS_DPI_AWARENESS::PROCESS_PER_MONITOR_DPI_AWARE:
stringBuilder->AppendFormat(gcnew System::String(L"Application is Per-Monitor DPI Aware. Using \tmonitor DPI = {0} \t(System DPI = {1})."), m_currentDPI, systemDpi);
break;
}
return stringBuilder->ToString();
}
}

81
NativeHelpers/PerMonitorDPIWindow.h

@ -0,0 +1,81 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#include "PerMonitorDPIHelpers.h"
using namespace System;
using namespace System::Windows::Interop;
using namespace System::Windows;
using namespace System::Windows::Media;
using namespace System::Security::Permissions;
namespace NativeHelpers
{
public ref class PerMonitorDPIWindow : public Window
{
public:
PerMonitorDPIWindow(void);
event EventHandler^ DPIChanged;
System::String^ GetCurrentDpiConfiguration();
property double CurrentDPI
{
double get()
{
return m_currentDPI;
}
}
property double WpfDPI
{
double get()
{
return m_wpfDPI;
}
void set(double value)
{
m_wpfDPI = value;
}
}
property double ScaleFactor
{
double get()
{
return m_scaleFactor;
}
}
protected:
~PerMonitorDPIWindow();
[EnvironmentPermissionAttribute(SecurityAction::LinkDemand, Unrestricted = true)]
void OnLoaded(Object^ sender, RoutedEventArgs^ args);
void OnDPIChanged();
void UpdateLayoutTransform(double scaleFactor);
IntPtr HandleMessages(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, bool %handled);
private:
System::Boolean m_perMonitorEnabled;
double m_currentDPI;
double m_systemDPI;
double m_wpfDPI;
double m_scaleFactor;
System::Windows::Interop::HwndSource^ m_source;
};
}

13
NativeHelpers/pch.cpp

@ -0,0 +1,13 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
// stdafx.cpp : source file that includes just the standard includes
// NativeHelpers.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "pch.h"

12
NativeHelpers/pch.h

@ -0,0 +1,12 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
#include <Windows.h>
#include <ShellScalingApi.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "shcore.lib")
#pragma comment(lib, "Gdi32.lib")

14
Text-Grab.sln

@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Text-Grab", "Text-Grab\Text
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Text-Grab-Package", "Text-Grab-Package\Text-Grab-Package.wapproj", "{CE37F469-F629-4B49-84BA-37A1DA192C60}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NativeHelpers", "NativeHelpers\NativeHelpers.vcxproj", "{938E65D0-EC9C-4181-87CA-A43D4747610D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -71,6 +73,18 @@ Global
{CE37F469-F629-4B49-84BA-37A1DA192C60}.Release|x86.ActiveCfg = Release|x86
{CE37F469-F629-4B49-84BA-37A1DA192C60}.Release|x86.Build.0 = Release|x86
{CE37F469-F629-4B49-84BA-37A1DA192C60}.Release|x86.Deploy.0 = Release|x86
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Debug|Any CPU.ActiveCfg = Debug|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Debug|ARM.ActiveCfg = Debug|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Debug|ARM64.ActiveCfg = Debug|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Debug|x64.ActiveCfg = Debug|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Debug|x86.ActiveCfg = Debug|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Debug|x86.Build.0 = Debug|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Release|Any CPU.ActiveCfg = Release|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Release|ARM.ActiveCfg = Release|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Release|ARM64.ActiveCfg = Release|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Release|x64.ActiveCfg = Release|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Release|x86.ActiveCfg = Release|Win32
{938E65D0-EC9C-4181-87CA-A43D4747610D}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

2
Text-Grab/AssemblyInfo.cs

@ -1,4 +1,5 @@
using System.Windows;
using System.Windows.Media;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
@ -8,3 +9,4 @@ using System.Windows;
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
[assembly: DisableDpiAwareness]

5
Text-Grab/MainWindow.xaml

@ -1,10 +1,11 @@
<Window
<src:PerMonitorDPIWindow
x:Class="Text_Grab.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Text_Grab"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:src="clr-namespace:NativeHelpers;assembly=NativeHelpers"
Title="Text Grab"
Width="800"
Height="450"
@ -25,4 +26,4 @@
</Canvas.Background>
<Image x:Name="DebugImage" />
</Canvas>
</Window>
</src:PerMonitorDPIWindow>

3
Text-Grab/MainWindow.xaml.cs

@ -15,13 +15,14 @@ using Windows.Globalization;
using Windows.Media.Ocr;
using Windows.System.UserProfile;
using BitmapDecoder = Windows.Graphics.Imaging.BitmapDecoder;
using NativeHelpers;
namespace Text_Grab
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public partial class MainWindow : PerMonitorDPIWindow
{
public MainWindow()
{

9
Text-Grab/Text-Grab.csproj

@ -7,12 +7,17 @@
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>t_ICON.ico</ApplicationIcon>
<StartupObject>Text_Grab.App</StartupObject>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<COMReference Include="{215d64d2-031c-33c7-96e3-61794cd1ee61}">
<WrapperTool>tlbimp</WrapperTool>
@ -27,6 +32,10 @@
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NativeHelpers\NativeHelpers.vcxproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>

Loading…
Cancel
Save