WPF中的非最小化应用程序使用C# [英] Non Minimizable Application in WPF usign C#

查看:98
本文介绍了WPF中的非最小化应用程序使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



有没有办法阻止我的应用程序最小化到系统托盘。我必须开发一个允许用户查看该应用程序的应用程序的应用程序,这意味着应用程序将始终在我的桌面上保持打开状态,因为它不应该被最小化。但他可以将该控件的顺序设置为像Windows Media Player或类似任务管理器。在使用C#的WPF中有任何选项。让我知道你的任何链接。

解决方案

你好,



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高度= 350宽度= 525
Topmost =
ResizeMode = NoResize >
< Grid>

< / 网格 >
< / 窗口 >





App.xaml.cs:

 使用系统; 
使用 System.Runtime.InteropServices;
使用 System.Windows;
使用 System.Windows.Interop;

命名空间 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 标志;
public int showCmd;
public POINTAPI ptMinPosition;
public POINTAPI ptMaxPosition;
public RECT rcNormalPosition;
}

public MainWindow()
{
InitializeComponent();
}

受保护 覆盖 void OnSourceInitialized(EventArgs e)
{
base .OnSourceInitialized(e);

尝试
{
系统。 IntPtr app_hwnd = new WindowInteropHelper( this )。句柄;
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
{
}
}
}
}





我受到以下文章的启发:

http://www.codeproject.com/Articles/29560/Set-Window-Action-Minimize-Maximize



,当然还有Snoop的源代码。

https:// snoopwpf .codeplex.com /



如果这对您有用,请不要忘记投票。



Happy Coding,

Stephan






使用窗口的对象< a href =http://msdn.microsoft.com/en-us/library/system.windows.window.windowstate.aspx>窗口状态属性。并尝试将其设置为最大化。

并使用ResizeMode以拒绝调整大小。



我没有使用过这个,但想到了建议。它可能有用。


Hi
设置表格属性 ResizeMode => NoResize WindowStyle => ToolWindow

Hi all,

Is there is a way to block minimizing of my application to system tray. I have to develop an application that will allow the user to view the prupose of that Application, which mean the application will remain open in my desktop all time for that it should not be minimized. But he can set order of that control as like windows Media player or like Task Manager. is there is any option to this in WPF using C#. let me know any link you have.

解决方案

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


Hi,

Use the window's object Window State property. And try setting it to Maximized.
And use ResizeMode so deny resizing.

I havent used this, but thought of suggesting. It might work.


Hi Set Form property ResizeMode=>NoResize and WindowStyle=>ToolWindow


这篇关于WPF中的非最小化应用程序使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆