Hi,
App.xaml:
<Window x:Class="WpfApplicationNonMinimizable.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
Topmost="True"
ResizeMode="NoResize">
<Grid>
</Grid>
</Window>
App.xaml.cs:
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace WpfApplicationNonMinimizable
{
public partial class MainWindow : Window
{
public const int SW_SHOWNORMAL = 1;
public const int SW_SHOWMINIMIZED = 2;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
[DllImport("user32.dll")]
public static extern bool SetWindowPlacement(IntPtr hWnd,
ref WINDOWPLACEMENT lpwndpl);
public struct POINTAPI
{
public int x;
public int y;
}
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
public struct WINDOWPLACEMENT
{
public int length;
public int flags;
public int showCmd;
public POINTAPI ptMinPosition;
public POINTAPI ptMaxPosition;
public RECT rcNormalPosition;
}
public MainWindow()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
try
{
System.IntPtr app_hwnd = new WindowInteropHelper(this).Handle;
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
GetWindowPlacement(app_hwnd, ref wp);
wp.showCmd = (wp.showCmd == SW_SHOWMINIMIZED ? SW_SHOWNORMAL : wp.showCmd);
SetWindowPlacement(app_hwnd, ref wp);
}
catch
{
}
}
}
}
I was inspired by the following article:
http://www.codeproject.com/Articles/29560/Set-Window-Action-Minimize-Maximize
and of course the source code of Snoop.
https://snoopwpf.codeplex.com/
If this works for you, don't forget to vote.
Happy Coding,
Stephan