mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-11 04:55:39 +02:00
1. Initial code check into CodePlex
This commit is contained in:
commit
dc8b817460
26 changed files with 1173 additions and 0 deletions
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ManagedWinapi" version="0.3" />
|
||||
</packages>
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.30723.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ninjacrab.PersistentWindows.WpfShell", "Ninjacrab.PersistentWindows.WpfShell\Ninjacrab.PersistentWindows.WpfShell.csproj", "{4EA12EC8-B50F-4DEA-AA7D-85A5F4C81F83}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{FA5C1FB9-45F3-434F-9176-71A2D8EDA5B2}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.nuget\packages.config = .nuget\packages.config
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4EA12EC8-B50F-4DEA-AA7D-85A5F4C81F83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4EA12EC8-B50F-4DEA-AA7D-85A5F4C81F83}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4EA12EC8-B50F-4DEA-AA7D-85A5F4C81F83}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4EA12EC8-B50F-4DEA-AA7D-85A5F4C81F83}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -0,0 +1,7 @@
|
|||
<Application x:Class="Ninjacrab.PersistentWindows.WpfShell.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -0,0 +1,18 @@
|
|||
using System.Windows;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
new MainWindow().Show();
|
||||
new PersistentWindowProcessor().Start();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
using System;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.Diagnostics
|
||||
{
|
||||
public class Log
|
||||
{
|
||||
static Log()
|
||||
{
|
||||
var config = new LoggingConfiguration();
|
||||
|
||||
// Step 2. Create targets and add them to the configuration
|
||||
var consoleTarget = new ColoredConsoleTarget();
|
||||
config.AddTarget("console", consoleTarget);
|
||||
|
||||
var fileTarget = new FileTarget();
|
||||
config.AddTarget("file", fileTarget);
|
||||
|
||||
// Step 3. Set target properties
|
||||
consoleTarget.Layout = @"${date:format=HH\\:MM\\:ss} ${logger} ${message}";
|
||||
fileTarget.FileName = "${basedir}/PersistentWindows.Log";
|
||||
fileTarget.Layout = "${message}";
|
||||
|
||||
// Step 4. Define rules
|
||||
var rule1 = new LoggingRule("*", LogLevel.Trace, consoleTarget);
|
||||
config.LoggingRules.Add(rule1);
|
||||
|
||||
var rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);
|
||||
config.LoggingRules.Add(rule2);
|
||||
|
||||
// Step 5. Activate the configuration
|
||||
LogManager.Configuration = config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when something is logged. STATIC EVENT!
|
||||
/// </summary>
|
||||
public static event Action<LogLevel, string> LogEvent;
|
||||
|
||||
private static Logger _logger;
|
||||
private static Logger Logger
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_logger == null)
|
||||
{
|
||||
_logger = LogManager.GetLogger("Logger");
|
||||
}
|
||||
return _logger;
|
||||
}
|
||||
}
|
||||
|
||||
private static void RaiseLogEvent(LogLevel level, string message)
|
||||
{
|
||||
// could, should, would write a new logging target but this is brute force faster
|
||||
if(LogEvent != null)
|
||||
{
|
||||
LogEvent(level, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Trace(string format, params object[] args)
|
||||
{
|
||||
var message = Format(format, args);
|
||||
Logger.Trace(message);
|
||||
RaiseLogEvent(LogLevel.Trace, message);
|
||||
}
|
||||
|
||||
public static void Info(string format, params object[] args)
|
||||
{
|
||||
var message = Format(format, args);
|
||||
Logger.Info(Format(format, args));
|
||||
RaiseLogEvent(LogLevel.Info, message);
|
||||
}
|
||||
|
||||
public static void Error(string format, params object[] args)
|
||||
{
|
||||
var message = Format(format, args);
|
||||
Logger.Error(Format(format, args));
|
||||
RaiseLogEvent(LogLevel.Error, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Since string.Format doesn't like args being null or having no entries.
|
||||
/// </summary>
|
||||
/// <param name="format">The format.</param>
|
||||
/// <param name="args">The args.</param>
|
||||
/// <returns></returns>
|
||||
private static string Format(string format, params object[] args)
|
||||
{
|
||||
return args == null || args.Length == 0 ? format : string.Format(format, args);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<UserControl x:Class="Ninjacrab.PersistentWindows.WpfShell.DiagnosticsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:prism="http://www.codeplex.com/prism"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<ListBox Name="eventLogList" ItemsSource="{Binding EventLog}" />
|
||||
</Grid>
|
||||
</UserControl>
|
|
@ -0,0 +1,32 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Ninjacrab.PersistentWindows.WpfShell.Diagnostics;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DiagnosticsView.xaml
|
||||
/// </summary>
|
||||
public partial class DiagnosticsView : UserControl
|
||||
{
|
||||
private DiagnosticsViewModel viewModel;
|
||||
|
||||
public DiagnosticsView()
|
||||
{
|
||||
InitializeComponent();
|
||||
viewModel = new DiagnosticsViewModel();
|
||||
this.DataContext = viewModel;
|
||||
Log.LogEvent += (level, message) =>
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
viewModel.EventLog.Add(string.Format("{0}: {1}", level, message));
|
||||
if (viewModel.EventLog.Count > 500)
|
||||
{
|
||||
viewModel.EventLog.RemoveAt(0);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
using System.ComponentModel;
|
||||
using Microsoft.Practices.Prism.Mvvm;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell
|
||||
{
|
||||
public class DiagnosticsViewModel : BindableBase
|
||||
{
|
||||
public DiagnosticsViewModel()
|
||||
{
|
||||
EventLog = new BindingList<string>();
|
||||
}
|
||||
|
||||
public const string AllProcessesPropertyName = "AllProcesses";
|
||||
private BindingList<string> allProcesses;
|
||||
public BindingList<string> EventLog
|
||||
{
|
||||
get { return allProcesses; }
|
||||
set { SetProperty(ref allProcesses, value); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<Window x:Class="Ninjacrab.PersistentWindows.WpfShell.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Ninjacrab.PersistentWindows.WpfShell"
|
||||
Title="MainWindow" Height="350" Width="525">
|
||||
<Grid>
|
||||
<local:DiagnosticsView />
|
||||
</Grid>
|
||||
</Window>
|
|
@ -0,0 +1,17 @@
|
|||
using System.Windows;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public PersistentWindowProcessor Processor { get; set; }
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using Ninjacrab.PersistentWindows.WpfShell.WinApiBridge;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.Models
|
||||
{
|
||||
public class ApplicationDisplayMetrics
|
||||
{
|
||||
public IntPtr HWnd { get; set; }
|
||||
public int ProcessId { get; set; }
|
||||
public string ApplicationName { get; set; }
|
||||
public WindowPlacement WindowPlacement { get; set; }
|
||||
|
||||
public string Key
|
||||
{
|
||||
get { return string.Format("{0}-{1}", HWnd.ToInt64(), ApplicationName); }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ninjacrab.PersistentWindows.WpfShell.WinApiBridge;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.Models
|
||||
{
|
||||
public class DesktopDisplayMetrics
|
||||
{
|
||||
public static DesktopDisplayMetrics AcquireMetrics()
|
||||
{
|
||||
DesktopDisplayMetrics metrics = new DesktopDisplayMetrics();
|
||||
|
||||
var displays = Display.GetDisplays();
|
||||
int displayId = 0;
|
||||
foreach (var display in displays)
|
||||
{
|
||||
metrics.SetMonitor(displayId++, display);
|
||||
}
|
||||
return metrics;
|
||||
}
|
||||
|
||||
private Dictionary<int, Display> monitorResolutions = new Dictionary<int, Display>();
|
||||
|
||||
public int NumberOfDisplays { get { return monitorResolutions.Count; } }
|
||||
|
||||
public void SetMonitor(int id, Display display)
|
||||
{
|
||||
if (!monitorResolutions.ContainsKey(id) ||
|
||||
monitorResolutions[id].ScreenWidth != display.ScreenWidth ||
|
||||
monitorResolutions[id].ScreenHeight != display.ScreenHeight)
|
||||
{
|
||||
monitorResolutions.Add(id, display);
|
||||
BuildKey();
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildKey()
|
||||
{
|
||||
List<string> keySegments = new List<string>();
|
||||
foreach(var entry in monitorResolutions.OrderBy(row => row.Key))
|
||||
{
|
||||
keySegments.Add(string.Format("[{0}-{1}x{2}-{3}x{4}]", entry.Key, entry.Value.Left, entry.Value.Top, entry.Value.ScreenWidth, entry.Value.ScreenHeight));
|
||||
}
|
||||
key = string.Join(",", keySegments);
|
||||
}
|
||||
|
||||
private string key;
|
||||
public string Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as DesktopDisplayMetrics;
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.Key == other.key;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return key.GetHashCode();
|
||||
}
|
||||
|
||||
public int GetHashCode(DesktopDisplayMetrics obj)
|
||||
{
|
||||
return obj.key.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4EA12EC8-B50F-4DEA-AA7D-85A5F4C81F83}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Ninjacrab.PersistentWindows.WpfShell</RootNamespace>
|
||||
<AssemblyName>PersistentWindows</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ManagedWinapi">
|
||||
<HintPath>..\packages\ManagedWinapi.0.3\ManagedWinapi.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Prism.Composition">
|
||||
<HintPath>..\packages\Prism.Composition.5.0.0\lib\NET45\Microsoft.Practices.Prism.Composition.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Prism.Interactivity">
|
||||
<HintPath>..\packages\Prism.Interactivity.5.0.0\lib\NET45\Microsoft.Practices.Prism.Interactivity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Prism.Mvvm">
|
||||
<HintPath>..\packages\Prism.Mvvm.1.0.0\lib\net45\Microsoft.Practices.Prism.Mvvm.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Prism.Mvvm.Desktop">
|
||||
<HintPath>..\packages\Prism.Mvvm.1.0.0\lib\net45\Microsoft.Practices.Prism.Mvvm.Desktop.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Prism.PubSubEvents">
|
||||
<HintPath>..\packages\Prism.PubSubEvents.1.0.0\lib\portable-sl4+wp7+windows8+net40\Microsoft.Practices.Prism.PubSubEvents.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Prism.SharedInterfaces">
|
||||
<HintPath>..\packages\Prism.Mvvm.1.0.0\lib\net45\Microsoft.Practices.Prism.SharedInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.ServiceLocation">
|
||||
<HintPath>..\packages\CommonServiceLocator.1.2\lib\portable-windows8+net40+sl5+windowsphone8\Microsoft.Practices.ServiceLocation.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\packages\NLog.3.1.0.0\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Diagnostics\Log.cs" />
|
||||
<Compile Include="Models\ApplicationDisplayMetrics.cs" />
|
||||
<Compile Include="WinApiBridge\Display.cs" />
|
||||
<Compile Include="WinApiBridge\MonitorInfo.cs" />
|
||||
<Compile Include="WinApiBridge\ShowWindowCommands.cs" />
|
||||
<Compile Include="WinApiBridge\User32.cs" />
|
||||
<Compile Include="WinApiBridge\WindowPlacement.cs" />
|
||||
<Page Include="DiagnosticsView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DiagnosticsView.xaml.cs">
|
||||
<DependentUpon>DiagnosticsView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="DiagnosticsViewModel.cs" />
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Models\DesktopDisplayMetrics.cs" />
|
||||
<Compile Include="PersistentWindowProcessor.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<AppDesigner Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,175 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using ManagedWinapi.Windows;
|
||||
using Microsoft.Win32;
|
||||
using Ninjacrab.PersistentWindows.WpfShell.Diagnostics;
|
||||
using Ninjacrab.PersistentWindows.WpfShell.Models;
|
||||
using Ninjacrab.PersistentWindows.WpfShell.WinApiBridge;
|
||||
using NLog;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell
|
||||
{
|
||||
public class PersistentWindowProcessor
|
||||
{
|
||||
private DesktopDisplayMetrics lastMetrics = null;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
var thread = new Thread(InternalRun);
|
||||
thread.IsBackground = true;
|
||||
thread.Name = "PersistentWindowProcessor.InternalRun()";
|
||||
thread.Start();
|
||||
|
||||
SystemEvents.DisplaySettingsChanged += (s, e) => BeginRestoreApplicationsOnCurrentDisplays();
|
||||
SystemEvents.PowerModeChanged += (s, e) =>
|
||||
{
|
||||
switch (e.Mode)
|
||||
{
|
||||
case PowerModes.Suspend:
|
||||
BeginCaptureApplicationsOnCurrentDisplays();
|
||||
break;
|
||||
|
||||
case PowerModes.Resume:
|
||||
BeginRestoreApplicationsOnCurrentDisplays();
|
||||
break;
|
||||
}
|
||||
};
|
||||
CaptureApplicationsOnCurrentDisplays();
|
||||
lastMetrics = DesktopDisplayMetrics.AcquireMetrics();
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, Dictionary<string, ApplicationDisplayMetrics>> monitorApplications = new Dictionary<string, Dictionary<string, ApplicationDisplayMetrics>>();
|
||||
private readonly object displayChangeLock = new object();
|
||||
|
||||
private void InternalRun()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
CaptureApplicationsOnCurrentDisplays();
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
private void BeginCaptureApplicationsOnCurrentDisplays()
|
||||
{
|
||||
var thread = new Thread(() => CaptureApplicationsOnCurrentDisplays());
|
||||
thread.IsBackground = true;
|
||||
thread.Name = "PersistentWindowProcessor.BeginCaptureApplicationsOnCurrentDisplays()";
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
private void CaptureApplicationsOnCurrentDisplays(string displayKey = null)
|
||||
{
|
||||
lock(displayChangeLock)
|
||||
{
|
||||
DesktopDisplayMetrics metrics = DesktopDisplayMetrics.AcquireMetrics();
|
||||
if (displayKey == null)
|
||||
{
|
||||
displayKey = metrics.Key;
|
||||
}
|
||||
|
||||
if (!metrics.Equals(lastMetrics))
|
||||
{
|
||||
// since the resolution doesn't match, lets wait till it's restored
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Info("Capturing applications for {0}", displayKey);
|
||||
if (!monitorApplications.ContainsKey(displayKey))
|
||||
{
|
||||
monitorApplications.Add(displayKey, new Dictionary<string, ApplicationDisplayMetrics>());
|
||||
}
|
||||
|
||||
var windows = SystemWindow.AllToplevelWindows.Where(row => row.VisibilityFlag == true);
|
||||
foreach (var window in windows)
|
||||
{
|
||||
WindowPlacement windowPlacement = new WindowPlacement();
|
||||
User32.GetWindowPlacement(window.HWnd, ref windowPlacement);
|
||||
|
||||
var applicationDisplayMetric = new ApplicationDisplayMetrics
|
||||
{
|
||||
HWnd = window.HWnd,
|
||||
ApplicationName = window.Process.ProcessName,
|
||||
ProcessId = window.Process.Id,
|
||||
WindowPlacement = windowPlacement
|
||||
};
|
||||
|
||||
if (!monitorApplications[displayKey].ContainsKey(applicationDisplayMetric.Key))
|
||||
{
|
||||
monitorApplications[displayKey].Add(applicationDisplayMetric.Key, applicationDisplayMetric);
|
||||
}
|
||||
else
|
||||
{
|
||||
monitorApplications[displayKey][applicationDisplayMetric.Key].WindowPlacement = applicationDisplayMetric.WindowPlacement;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BeginRestoreApplicationsOnCurrentDisplays()
|
||||
{
|
||||
var thread = new Thread(() => RestoreApplicationsOnCurrentDisplays());
|
||||
thread.IsBackground = true;
|
||||
thread.Name = "PersistentWindowProcessor.RestoreApplicationsOnCurrentDisplays()";
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
private void RestoreApplicationsOnCurrentDisplays(string displayKey = null)
|
||||
{
|
||||
lock (displayChangeLock)
|
||||
{
|
||||
DesktopDisplayMetrics metrics = DesktopDisplayMetrics.AcquireMetrics();
|
||||
if (displayKey == null)
|
||||
{
|
||||
displayKey = metrics.Key;
|
||||
}
|
||||
|
||||
lastMetrics = DesktopDisplayMetrics.AcquireMetrics();
|
||||
if (!monitorApplications.ContainsKey(displayKey))
|
||||
{
|
||||
// no old profile, we're done
|
||||
Log.Info("No old profile found for {0}", displayKey);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Info("Restoring applications for {0}", displayKey);
|
||||
foreach (var window in SystemWindow.AllToplevelWindows.Where(row => row.VisibilityFlag == true))
|
||||
{
|
||||
string applicationKey = string.Format("{0}-{1}", window.HWnd.ToInt64(), window.Process.ProcessName);
|
||||
if (monitorApplications[displayKey].ContainsKey(applicationKey))
|
||||
{
|
||||
// looks like the window is still here for us to restore
|
||||
WindowPlacement windowPlacement = monitorApplications[displayKey][applicationKey].WindowPlacement;
|
||||
|
||||
if (windowPlacement.ShowCmd == ShowWindowCommands.Maximize)
|
||||
{
|
||||
// When restoring maximized windows, it occasionally switches res and when the maximized setting is restored
|
||||
// the window thinks it's maxxed, but does not eat all the real estate. So we'll temporarily unmaximize then
|
||||
// re-apply that
|
||||
windowPlacement.ShowCmd = ShowWindowCommands.Normal;
|
||||
User32.SetWindowPlacement(monitorApplications[displayKey][applicationKey].HWnd, ref windowPlacement);
|
||||
windowPlacement.ShowCmd = ShowWindowCommands.Maximize;
|
||||
}
|
||||
var success = User32.SetWindowPlacement(monitorApplications[displayKey][applicationKey].HWnd, ref windowPlacement);
|
||||
if(!success)
|
||||
{
|
||||
string error = new Win32Exception(Marshal.GetLastWin32Error()).Message;
|
||||
Log.Error(error);
|
||||
}
|
||||
Log.Info("SetWindowPlacement({0} [{1}x{2}]-[{3}x{4}]) - {5}",
|
||||
window.Process.ProcessName,
|
||||
windowPlacement.NormalPosition.Left,
|
||||
windowPlacement.NormalPosition.Top,
|
||||
windowPlacement.NormalPosition.Width,
|
||||
windowPlacement.NormalPosition.Height,
|
||||
success);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
// 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: AssemblyTitle("Ninjacrab.PersistentWindows.WpfShell")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Ninjacrab.PersistentWindows.WpfShell")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
//In order to begin building localizable applications, set
|
||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||
//inside a <PropertyGroup>. For example, if you are using US english
|
||||
//in your source files, set the <UICulture> to en-US. Then uncomment
|
||||
//the NeutralResourceLanguage attribute below. Update the "en-US" in
|
||||
//the line below to match the UICulture setting in the project file.
|
||||
|
||||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.2.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.2.0")]
|
|
@ -0,0 +1,71 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.34014
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.Properties
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((resourceMan == null))
|
||||
{
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Ninjacrab.PersistentWindows.WpfShell.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
|
@ -0,0 +1,30 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.34014
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using ManagedWinapi.Windows;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.WinApiBridge
|
||||
{
|
||||
public class Display
|
||||
{
|
||||
public int ScreenWidth { get; internal set; }
|
||||
public int ScreenHeight { get; internal set; }
|
||||
public int Left { get; internal set; }
|
||||
public int Top { get; internal set; }
|
||||
public uint Flags { get; internal set; }
|
||||
|
||||
public static List<Display> GetDisplays()
|
||||
{
|
||||
List<Display> displays = new List<Display>();
|
||||
|
||||
User32.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
|
||||
delegate(IntPtr hMonitor, IntPtr hdcMonitor, ref RECT lprcMonitor, IntPtr dwData)
|
||||
{
|
||||
MonitorInfo monitorInfo = new MonitorInfo();
|
||||
monitorInfo.StructureSize = Marshal.SizeOf(monitorInfo);
|
||||
bool success = User32.GetMonitorInfo(hMonitor, ref monitorInfo);
|
||||
if (success)
|
||||
{
|
||||
Display display = new Display();
|
||||
display.ScreenWidth = monitorInfo.Monitor.Width;
|
||||
display.ScreenHeight = monitorInfo.Monitor.Height;
|
||||
display.Left = monitorInfo.Monitor.Left;
|
||||
display.Top = monitorInfo.Monitor.Top;
|
||||
display.Flags = monitorInfo.Flags;
|
||||
displays.Add(display);
|
||||
}
|
||||
return true;
|
||||
}, IntPtr.Zero);
|
||||
return displays;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using ManagedWinapi.Windows;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.WinApiBridge
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
public struct MonitorInfo
|
||||
{
|
||||
// size of a device name string
|
||||
private const int CCHDEVICENAME = 32;
|
||||
|
||||
public int StructureSize;
|
||||
public RECT Monitor;
|
||||
public RECT WorkArea;
|
||||
public uint Flags;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
|
||||
public string DeviceName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.WinApiBridge
|
||||
{
|
||||
public enum ShowWindowCommands
|
||||
{
|
||||
/// <summary>
|
||||
/// Hides the window and activates another window.
|
||||
/// </summary>
|
||||
Hide = 0,
|
||||
/// <summary>
|
||||
/// Activates and displays a window. If the window is minimized or
|
||||
/// maximized, the system restores it to its original size and position.
|
||||
/// An application should specify this flag when displaying the window
|
||||
/// for the first time.
|
||||
/// </summary>
|
||||
Normal = 1,
|
||||
/// <summary>
|
||||
/// Activates the window and displays it as a minimized window.
|
||||
/// </summary>
|
||||
ShowMinimized = 2,
|
||||
/// <summary>
|
||||
/// Maximizes the specified window.
|
||||
/// </summary>
|
||||
Maximize = 3, // is this the right value?
|
||||
/// <summary>
|
||||
/// Activates the window and displays it as a maximized window.
|
||||
/// </summary>
|
||||
ShowMaximized = 3,
|
||||
/// <summary>
|
||||
/// Displays a window in its most recent size and position. This value
|
||||
/// is similar to <see cref="Win32.ShowWindowCommand.Normal"/>, except
|
||||
/// the window is not activated.
|
||||
/// </summary>
|
||||
ShowNoActivate = 4,
|
||||
/// <summary>
|
||||
/// Activates the window and displays it in its current size and position.
|
||||
/// </summary>
|
||||
Show = 5,
|
||||
/// <summary>
|
||||
/// Minimizes the specified window and activates the next top-level
|
||||
/// window in the Z order.
|
||||
/// </summary>
|
||||
Minimize = 6,
|
||||
/// <summary>
|
||||
/// Displays the window as a minimized window. This value is similar to
|
||||
/// <see cref="Win32.ShowWindowCommand.ShowMinimized"/>, except the
|
||||
/// window is not activated.
|
||||
/// </summary>
|
||||
ShowMinNoActive = 7,
|
||||
/// <summary>
|
||||
/// Displays the window in its current size and position. This value is
|
||||
/// similar to <see cref="Win32.ShowWindowCommand.Show"/>, except the
|
||||
/// window is not activated.
|
||||
/// </summary>
|
||||
ShowNA = 8,
|
||||
/// <summary>
|
||||
/// Activates and displays the window. If the window is minimized or
|
||||
/// maximized, the system restores it to its original size and position.
|
||||
/// An application should specify this flag when restoring a minimized window.
|
||||
/// </summary>
|
||||
Restore = 9,
|
||||
/// <summary>
|
||||
/// Sets the show state based on the SW_* value specified in the
|
||||
/// STARTUPINFO structure passed to the CreateProcess function by the
|
||||
/// program that started the application.
|
||||
/// </summary>
|
||||
ShowDefault = 10,
|
||||
/// <summary>
|
||||
/// <b>Windows 2000/XP:</b> Minimizes a window, even if the thread
|
||||
/// that owns the window is not responding. This flag should only be
|
||||
/// used when minimizing windows from a different thread.
|
||||
/// </summary>
|
||||
ForceMinimize = 11
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using ManagedWinapi.Windows;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.WinApiBridge
|
||||
{
|
||||
public class User32
|
||||
{
|
||||
#region EnumDisplayMonitors
|
||||
public delegate bool MonitorEnumDelegate(IntPtr hMonitor, IntPtr hdcMonitor, ref RECT lprcMonitor, IntPtr dwData);
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, MonitorEnumDelegate lpfnEnum, IntPtr dwData);
|
||||
#endregion
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MonitorInfo lpmi);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WindowPlacement lpwndpl);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WindowPlacement lpwndpl);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using ManagedWinapi.Windows;
|
||||
|
||||
namespace Ninjacrab.PersistentWindows.WpfShell.WinApiBridge
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct WindowPlacement
|
||||
{
|
||||
/// <summary>
|
||||
/// The length of the structure, in bytes. Before calling the GetWindowPlacement or SetWindowPlacement functions, set this member to sizeof(WINDOWPLACEMENT).
|
||||
/// <para>
|
||||
/// GetWindowPlacement and SetWindowPlacement fail if this member is not set correctly.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public int Length;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies flags that control the position of the minimized window and the method by which the window is restored.
|
||||
/// </summary>
|
||||
public int Flags;
|
||||
|
||||
/// <summary>
|
||||
/// The current show state of the window.
|
||||
/// </summary>
|
||||
public ShowWindowCommands ShowCmd;
|
||||
|
||||
/// <summary>
|
||||
/// The coordinates of the window's upper-left corner when the window is minimized.
|
||||
/// </summary>
|
||||
public POINT MinPosition;
|
||||
|
||||
/// <summary>
|
||||
/// The coordinates of the window's upper-left corner when the window is maximized.
|
||||
/// </summary>
|
||||
public POINT MaxPosition;
|
||||
|
||||
/// <summary>
|
||||
/// The window's coordinates when the window is in the restored position.
|
||||
/// </summary>
|
||||
public RECT NormalPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default (empty) value.
|
||||
/// </summary>
|
||||
public static WindowPlacement Default
|
||||
{
|
||||
get
|
||||
{
|
||||
WindowPlacement result = new WindowPlacement();
|
||||
result.Length = Marshal.SizeOf(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CommonServiceLocator" version="1.2" targetFramework="net45" />
|
||||
<package id="NLog" version="3.1.0.0" targetFramework="net45" />
|
||||
<package id="Prism" version="5.0.0" targetFramework="net45" />
|
||||
<package id="Prism.Composition" version="5.0.0" targetFramework="net45" />
|
||||
<package id="Prism.Interactivity" version="5.0.0" targetFramework="net45" />
|
||||
<package id="Prism.Mvvm" version="1.0.0" targetFramework="net45" />
|
||||
<package id="Prism.PubSubEvents" version="1.0.0" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue