代码之家  ›  专栏  ›  技术社区  ›  dbkk

在Windows7中保留屏幕区域

  •  5
  • dbkk  · 技术社区  · 17 年前

    是否可以在Windows 7中为您的应用程序保留靠近屏幕边缘的屏幕区域?它的行为类似于Windows任务栏(即最大化的窗口不会与其重叠)。

    Ulltramon , DisplayFusion )我知道Win7的工作,没有一个是开源的。

    2 回复  |  直到 17 年前
        1
  •  5
  •   dbkk    17 年前

    C# code sample .

    using System;
    using System.Runtime.InteropServices;
    
    public class WorkArea
    {
      [System.Runtime.InteropServices.DllImport("user32.dll",  EntryPoint="SystemParametersInfoA")]
      private static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, IntPtr lpvParam, Int32 fuWinIni);
    
      private const Int32 SPI_SETWORKAREA = 47;
      public WorkArea(Int32 Left,Int32 Right,Int32 Top,Int32 Bottom)
      {
        _WorkArea.Left = Left;
        _WorkArea.Top = Top;
        _WorkArea.Bottom = Bottom;
        _WorkArea.Right = Right;
      }
    
      public struct RECT
      {
        public Int32 Left;
        public Int32 Right;
        public Int32 Top;
        public Int32 Bottom;
      }
    
      private RECT _WorkArea;
      public void SetWorkingArea()
      {
        IntPtr ptr = IntPtr.Zero;
        ptr = Marshal.AllocHGlobal(Marshal.SizeOf(_WorkArea));
        Marshal.StructureToPtr(_WorkArea,ptr,false);
        int i = SystemParametersInfo(SPI_SETWORKAREA,0,ptr,0);
      }
    }
    
        2
  •  3
  •   Michael    17 年前

    我不确定如何在C#中直接实现这一点,但在本机代码中,您可以使用SPI#U SETWORKAREA调用SystemParametersInfo。这就是任务栏、侧边栏等应用程序防止最大化窗口重叠的方法。

    http://msdn.microsoft.com/en-us/library/ms724947.aspx 是SystemParametersInfo的文档。

    http://social.msdn.microsoft.com/forums/en-US/winforms/thread/9fe831e5-ccfb-4e8d-a129-68c301c83acb

    推荐文章