精华内容
下载资源
问答
  • title author date CreateTime categories ... WPF 隐藏系统窗口菜单 lindexi 2019-06-05 17:26:44 +0800 2019-06-05 17:17:16 +0800 WPF 本文告诉大家如何隐藏系统窗口菜单 系统的窗...
        
    title author date CreateTime categories
    WPF 隐藏系统窗口菜单
    lindexi
    2019-06-05 17:26:44 +0800
    2019-06-05 17:17:16 +0800
    WPF

    本文告诉大家如何隐藏系统窗口菜单

    系统的窗口菜单请看下图

    通过在消息里面钩调一些消息的方式,此方法由 黄滨滨 大佬提供

            private IntPtr Hook(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
            {
                if (msg == 0x112)
                {
                    var param = wparam.ToInt32();
                    if (param is 0xf093 // 单击打开菜单
                        || param is 0xf100)//键盘打开菜单
                    {
                        handled = true;
                    }
                }
                else if (msg == 0xa4)
                {
                    var param = wparam.ToInt32();
                    if (param == 0x02 // 非图片客户区
                        || param is 0x03)
                    {
                        handled = true;
                    }
                }
    
                return IntPtr.Zero;
            }

    第二个方法是通过设置样式

           public MainWindow()
            {
                InitializeComponent();
    
                SourceInitialized += OnSourceInitialized;
            }
    
            private void OnSourceInitialized(object sender, EventArgs e)
            {
                var windowInteropHelper = new WindowInteropHelper(this);
                var hwnd = windowInteropHelper.Handle;
    
                var windowLong = GetWindowLong(hwnd, GWL_STYLE);
                windowLong &= ~WS_SYSMENU;
    
                SetWindowLongPtr(hwnd, GWL_STYLE, new IntPtr(windowLong));
            }
    
            public const int WS_SYSMENU = 0x00080000;
    
            [DllImport("user32.dll", SetLastError = true)]
            public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    
            public const int GWL_STYLE = -16;
    
            public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
            {
                if (Environment.Is64BitProcess)
                {
                    return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
                }
    
                return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
            }
    
            [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
            private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong);
    
            [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
            private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
    
           
    展开全文
  • wpf 悬浮窗口的实现

    2019-03-14 22:37:00
    wpf 悬浮窗口的实现 原文:wpf 悬浮窗口的实现 又到了写点东西的时候,因为有了新的收获,所以用随笔来记录下自己的成长。话不多说,正入主题。 最近又遇到一个新的需求,有一组控件,需要悬浮显示在...
    原文:wpf 悬浮窗口的实现

        又到了写点东西的时候,因为有了新的收获,所以用随笔来记录下自己的成长。话不多说,正入主题。

        最近又遇到一个新的需求,有一组控件,需要悬浮显示在面板的边缘上,刚开始的时候,是不显示的,点击后显示,然后再次点击,隐藏。就这么一个功能,折腾了一天。

        实现的方法很多,本次使用了DevExpress里面的DockLayoutManager控件。从DevExpress的官网上下载了一个Demo,然后学习了下。DevExpress的控件使用,搜索资料好像不多,当然也可能是我的搜索方法不对。

       

    <Window 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking" 
            xmlns:dxcore="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" x:Class="CreateAutoHiddenPanels.Window1" 
            Title="Window1" Height="300" Width="640" 
            >
        <Grid>
            <dxdo:DockLayoutManager Margin="12" x:Name="dockManager1" dxcore:ThemeManager.ThemeName="Office2010Blue"  AutoHideExpandMode="MouseDown" >
                <dxdo:DockLayoutManager.AutoHideGroups>
                    <dxdo:AutoHideGroup DockType="Bottom">
                        <dxdo:LayoutPanel x:Name="paneFindResults" Caption="Find Results"  ShowCloseButton="False" ShowControlBox="False" ShowMaximizeButton="False" 
                                          ShowPinButton="False"  CaptionVerticalAlignment="Stretch" CaptionHorizontalAlignment="Stretch" 
                                              TextWrapping="WrapWithOverflow"
                                              AllowDockToDocumentGroup="False" CaptionWidth="150" ItemWidth="150"
                                          AllowMaximize="False"
                                          AllowFloat="False"
                                          CaptionImage="Image/right.png"
                                          CaptionImageLocation="AfterText"
                                          >
                            <Grid>
                                <TextBlock/>
                            </Grid>
                        </dxdo:LayoutPanel>
                    </dxdo:AutoHideGroup>
                </dxdo:DockLayoutManager.AutoHideGroups>
            </dxdo:DockLayoutManager>
        </Grid>
    </Window>

    运行效果:

     点击FindResults后,出现FindResults窗口。

    这里需要的注意点:

    1、 点击最下面的FindResults,可以显示或者隐藏FindResults窗口,为了实现该功能

    需要把dockManager1的AutoHideExpandMode设置成"MouseDown"。

    2、显示出来的FindResults窗口的标题,点击后,并不会隐藏,我的需求是不显示。

    所以需要paneFindResults的ShowCaptionImage 设置成False。

    3、为了防止双击显示出来的FindResults窗口会最大化,需要屏蔽到下面的两个属性。

    AllowMaximize="False"
    AllowFloat="False"

     

    posted on 2019-03-14 22:37 NET未来之路 阅读(...) 评论(...) 编辑 收藏

    转载于:https://www.cnblogs.com/lonelyxmas/p/10534141.html

    展开全文
  • wpf中利用Interaction.Behaviors实现窗口的贴边隐藏
  • WPF 窗口

    2018-09-25 08:50:00
    原文:WPF 窗口WPF中,经常需要对窗口进行设置,下面讲讲常用的几个设置。 窗口样式 1、无边框窗口 无边框透明窗体 设置 WindowStyle="None"--无边框,如果需要其它按钮,如缩小、放大、收缩、关闭...
    原文:WPF 窗口

    在WPF中,经常需要对窗口进行设置,下面讲讲常用的几个设置。

    窗口样式

    1、无边框窗口

    无边框透明窗体 设置

    WindowStyle="None"--无边框,如果需要其它按钮,如缩小、放大、收缩、关闭按钮,可以自定义

    AllowsTransparency="True"--只有设置了AllowsTransparency,才有1、窗体真正的隐藏边框2、背景透明有效

    Background="Transparent"

    窗口阴影设置

    可以用Border的CornerRadius设置窗口四周圆角

    设置窗口阴影--值得一提的是,如果直接用Window.Effect,效果会影响CornerRadius设置的圆角效果。

    <Window.Effect>
    <DropShadowEffect BlurRadius="30" Color="Gray" ShadowDepth="0" RenderingBias="Quality" ></DropShadowEffect>
    </Window.Effect>

    举例:

    <Window x:Class="WpfApplication4.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525" WindowStartupLocation="CenterScreen" 
            AllowsTransparency="True" WindowStyle="None" Background="Transparent">
        <Grid>
            <Border CornerRadius="5" Background="Red"></Border>
        </Grid>
    </Window>
    View Code

    2、窗口按钮

    当我们设置无边窗口时,也即是需要重新设置一套窗口的操作按钮。

    按钮,可以用修改Button的Background或者修改Template,往其中设置图标或者直接用Path、Border、Rectangle等基础元素绘制。

    然后添加简单的动画Animation

    1) 方法1.下面是自定义的按钮Style,往其中传入图标路径即可

    <Style TargetType="Button">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Grid>
                                <Rectangle x:Name="T_Rectangle" Height="15" Width="15">
                                    <Rectangle.Fill>
                                        <ImageBrush ImageSource="{Binding ImagesSource}"></ImageBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"></ContentPresenter>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="T_Rectangle" Property="Height" Value="18"></Setter>
                                    <Setter TargetName="T_Rectangle" Property="Width" Value="18"></Setter>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter TargetName="T_Rectangle" Property="Height" Value="20"></Setter>
                                    <Setter TargetName="T_Rectangle" Property="Width" Value="20"></Setter>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    View Code

    2)方法2.直接用基础元素绘制

    Path,通过Path来画线。当然一般水平、竖直也是可以用Rectangle/Border之类的替代

    一些简单的线条图标用Path来做,还是很方便的。

    <StackPanel Grid.Column="1" Orientation="Horizontal">
                        <Button x:Name="BtnMinimize" ToolTip="Minimize" Style="{StaticResource TitleBtnStyle}">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                    <Border x:Name="T_Grid" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
                                        <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
                                            <Path x:Name="T_Path" Data="M0,0 L8,0" Stroke="Black" StrokeThickness="1"></Path>
                                        </Grid>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger SourceName="T_Grid" Property="IsMouseOver" Value="True">
                                            <Setter TargetName="T_Grid" Property="Background" Value="LightGray"></Setter>
                                        </Trigger>
                                        <Trigger Property="IsPressed" Value="True">
                                            <Setter TargetName="T_Grid" Property="Background" Value="#FFC1C1C1"></Setter>
                                            <Setter TargetName="T_Path" Property="Margin" Value="0,4,0,0"></Setter>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                             </Button.Template>
                        </Button>
                        <Button x:Name="BtnMaximize" ToolTip="Maximize" Style="{StaticResource TitleBtnStyle}">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                    <Border x:Name="T_Grid" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
                                        <Rectangle x:Name="T_Rect" Stroke="Black" StrokeThickness="0.5" Height="8" Margin="5,0" Width="8"></Rectangle>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter TargetName="T_Grid" Property="Background" Value="LightGray"></Setter>
                                        </Trigger>
                                        <Trigger Property="IsPressed" Value="True">
                                            <Setter TargetName="T_Grid" Property="Background" Value="#FFC1C1C1"></Setter>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                        <Button x:Name="BtnRestore" ToolTip="Restore" Style="{StaticResource TitleBtnStyle}">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                    <Border x:Name="T_Grid" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
                                        <Grid >
                                            <Rectangle Stroke="Black" StrokeThickness="0.5" Height="7" Width="7" Margin="2,0,0,2"></Rectangle>
                                            <Rectangle Stroke="Black" StrokeThickness="0.5" Height="7" Width="7" Fill="White" Margin="0,2,2,0"></Rectangle>
                                        </Grid>
                                     </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter TargetName="T_Grid" Property="Background" Value="LightGray"></Setter>
                                        </Trigger>
                                        <Trigger Property="IsPressed" Value="True">
                                            <Setter TargetName="T_Grid" Property="Background" Value="#FFC1C1C1"></Setter>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                        <Button x:Name="BtnClose" ToolTip="Close" Style="{StaticResource TitleBtnStyle}" Click="BtnClose_OnClick">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                        <Border x:Name="T_Grid" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
                                            <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
                                                <Path Data="M0,0 L8,8" Stroke="Black" StrokeThickness="1"></Path>
                                                <Path Data="M8,0 L0,8" Stroke="Black" StrokeThickness="1"></Path>
                                            </Grid>
                                        </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter TargetName="T_Grid" Property="Background" Value="LightGray"></Setter>
                                        </Trigger>
                                        <Trigger Property="IsPressed" Value="True">
                                            <Setter TargetName="T_Grid" Property="Background" Value="#FFC1C1C1"></Setter>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                    </StackPanel>
    View Code

     

    3、窗口 resize 鼠标自由改变窗口大小 (转)

    覆写一个OnSourceInitialized方法,在其中添加一个委托

            //重写
            protected override void OnSourceInitialized(EventArgs e)
            {
                base.OnSourceInitialized(e);
                HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
                if (hwndSource != null)
                {
                    hwndSource.AddHook(new HwndSourceHook(WndProc));
                }
            }
    
            private const int WM_NCHITTEST = 0x0084;
            private Point mousePoint = new Point(); //鼠标坐标
            private const int ResizeBorderAGWidth = 12;//转角宽度 
            private const int ResizeBorderThickness = 4;//边框宽度
            /// <summary>
            /// 委托方法
            /// </summary>
            /// <param name="hwnd"></param>
            /// <param name="msg"></param>
            /// <param name="wParam"></param>
            /// <param name="lParam"></param>
            /// <param name="handled"></param>
            /// <returns></returns>
            protected virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
            {
                switch (msg)
                {
                    case WM_NCHITTEST:
                        mousePoint.X = (lParam.ToInt32() & 0xFFFF);
                        mousePoint.Y = (lParam.ToInt32() >> 16);
                        // 窗口左上角
                        if (mousePoint.Y - Top <= ResizeBorderAGWidth && mousePoint.X - Left <= ResizeBorderAGWidth)
                        {
                            handled = true;
                            return new IntPtr((int)HitTest.HTTOPLEFT);
                        }
                        // 窗口左下角  
                        else if (ActualHeight + Top - mousePoint.Y <= ResizeBorderAGWidth && mousePoint.X - Left <= ResizeBorderAGWidth)
                        {
                            handled = true;
                            return new IntPtr((int)HitTest.HTBOTTOMLEFT);
                        }
                        // 窗口右上角
                        else if (mousePoint.Y - Top <= ResizeBorderAGWidth && ActualWidth + Left - mousePoint.X <= ResizeBorderAGWidth)
                        {
                            handled = true;
                            return new IntPtr((int)HitTest.HTTOPRIGHT);
                        }
                        // 窗口右下角
                        else if (ActualWidth + Left - mousePoint.X <= ResizeBorderAGWidth && ActualHeight + Top - mousePoint.Y <= ResizeBorderAGWidth)
                        {
                            handled = true;
                            return new IntPtr((int)HitTest.HTBOTTOMRIGHT);
                        }
                        // 窗口左侧
                        else if (mousePoint.X - Left <= ResizeBorderThickness)
                        {
                            handled = true;
                            return new IntPtr((int)HitTest.HTLEFT);
                        }
                        // 窗口右侧
                        else if (ActualWidth + Left - mousePoint.X <= ResizeBorderThickness)
                        {
                            handled = true;
                            return new IntPtr((int)HitTest.HTRIGHT);
                        }
                        // 窗口上方
                        else if (mousePoint.Y - Top <= ResizeBorderThickness)
                        {
                            handled = true;
                            return new IntPtr((int)HitTest.HTTOP);
                        }
                        // 窗口下方
                        else if (ActualHeight + Top - mousePoint.Y <= ResizeBorderThickness)
                        {
                            handled = true;
                            return new IntPtr((int)HitTest.HTBOTTOM);
                        }
                        else // 窗口移动
                        {
                            //handled = true;
                            //return new IntPtr((int)HitTest.HTCAPTION);
                            return IntPtr.Zero;
                        }
                }
    
                return IntPtr.Zero;
            }
    View Code

    用到的枚举列表类:

    public enum HitTest : int
        {
            HTERROR = -2,
            HTTRANSPARENT = -1,
            HTNOWHERE = 0,
            HTCLIENT = 1,
            HTCAPTION = 2,
            HTSYSMENU = 3,
            HTGROWBOX = 4,
            HTSIZE = HTGROWBOX,
            HTMENU = 5,
            HTHSCROLL = 6,
            HTVSCROLL = 7,
            HTMINBUTTON = 8,
            HTMAXBUTTON = 9,
            HTLEFT = 10,
            HTRIGHT = 11,
            HTTOP = 12,
            HTTOPLEFT = 13,
            HTTOPRIGHT = 14,
            HTBOTTOM = 15,
            HTBOTTOMLEFT = 16,
            HTBOTTOMRIGHT = 17,
            HTBORDER = 18,
            HTREDUCE = HTMINBUTTON,
            HTZOOM = HTMAXBUTTON,
            HTSIZEFIRST = HTLEFT,
            HTSIZELAST = HTBOTTOMRIGHT,
            HTOBJECT = 19,
            HTCLOSE = 20,
            HTHELP = 21,
        }
    View Code

      

    窗口拖动

    1、在界面上对布局元素如Grid,添加委托事件: MouseLeftButtonDown="UIElement_OnMouseLeftButtonDown"

    2、委托方法中处理一下就行了:

            private void UIElement_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                if (e.ButtonState==MouseButtonState.Pressed)
                {
                    this.DragMove();
                }
            }

     

    展开全文
  • 隐藏最小化、最大化按钮,十分简单,设置属性ResizeMode的值为NoResize即可。 隐藏关闭按钮代码如下:  private const int GWL_STYLE = -16;  private const int WS_SYSMENU = 0x80000;  [System....
    隐藏最小化、最大化按钮,十分简单,设置属性ResizeMode的值为NoResize即可。
    

    隐藏关闭按钮代码如下:
            private const int GWL_STYLE = -16;
            private const int WS_SYSMENU = 0x80000;
            [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
            private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    然后,在装载事件Window_Loaded中加入以下代码:
            var hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;

            SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);

    引自:http://blog.sina.com.cn/s/blog_7a19640201018wy5.html

    展开全文
  • WPF的消息机制(二)- WPF内部的5个窗口隐藏消息窗口 WPF内部的5个窗口 对于Windows系统来说,它是一个消息系统,消息系统的核心就是窗口。对于WPF来说也是如此。那么WPF内部为什么需要窗口,又存在...
  • (1)隐藏消息窗口 (2)处理激活和关闭的消息的窗口和系统资源通知窗口 (3)用于用户交互的可见窗口 (4)用于UI窗口绘制的可见窗口 WPF的消息机制(三)-WPF输入事件的来源 WPF的消息机制(四)-WPF中UI的...
  • title author date CreateTime categories ... WPF 在 Alt+Tab 隐藏窗口 lindexi 2018-04-15 10:13:40 +0800 2018-3-1 11:32:9 +0800 WPF 最近在开发一个 Toast 窗口,因为这...
  • WPF窗口长时间无人操作鼠标自动隐藏 原文:WPF窗口长时间无人操作鼠标自动隐藏在软件开发中有时会有等待一段时间无人操作后隐藏鼠标,可能原因大致如下: 1.为了安全性,特别是那些需要用到用户名和...
  • wpf 如何让当前窗口隐藏

    千次阅读 2016-01-26 23:28:38
    最后写一个程序,只是一个服务,可是最近一直用Wpf,所以就用wpf写了,可是不能要窗口,想了半天最后发现很单,记录一下 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://sch
  • public partial class MainWindow : Window { #region 窗口贴边隐藏用的变量 //鼠标坐标当前位置 private MousePosition p = new MousePosition(); MousePosition.POINT point; //窗口贴边...
  • 我只是遇到了类似的问题,乔·怀特的解决方案在我看来似乎简单而干净。我重用了它并将其定义为Window的附加属性public class WindowBehavior{private static readonly Type OwnerType = typeof (WindowBehavior);...
  • 我只是遇到了类似的问题,乔·怀特的解决方案在我看来似乎简单而干净。我重用了它并将其定义为Window的附加属性public class WindowBehavior{private static readonly Type OwnerType = typeof (WindowBehavior);...
  • 我用句柄获取隐藏窗口代码如下: IntPtr hscrdc = GetWindowDC(hWnd); //Control control = Control.FromHandle(hWnd); Window xx = (Window)System.Windows.Interop.HwndSource.FromHwnd(hWnd).RootVisual;...
  • 按要求要做一个隐藏在后台通知栏的功能,而目前软件开发所用的wpf不含有NotifyIcon这一控件,研究了一下如何调用winform,效果也算是达到了 头文件 using WinForms = System.Windows.Forms; 预定义几个按钮和通知...
  • WPF全局窗口错误提示框

    千次阅读 2017-12-19 16:50:04
    不管是CS还是BS,在需要用户提交数据的页面上,总是要做一些校验,如果校验有错就要给用户提示,WPF里自然也避免不了这个问题。一开始,我是在窗口上预留了一个TextBlock,并且设置其Visibility=Collapsed,当校验有...

空空如也

空空如也

1 2 3 4 5 ... 10
收藏数 182
精华内容 72
关键字:

wpf隐藏窗口