Esempio n. 1
0
 public static void DwmExtendFrameIntoClientArea(Control c, MARGINS marg)
 {
     if (DwmIsCompositionEnabled())
     {
         DwmExtendFrameIntoClientArea(c.Handle, ref marg);
     }
 }
Esempio n. 2
0
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            // Get the Operating System From Environment Class
            OperatingSystem os = Environment.OSVersion;

            // Get the version information
            Version vs = os.Version;

            if (vs.Major < 6)
                return false;

            if (!DwmIsCompositionEnabled())
                return false;

            IntPtr hwnd = new WindowInteropHelper(window).Handle;
            if (hwnd == IntPtr.Zero)
                throw new InvalidOperationException("Glass cannot be extended before the window is shown.");

            // Set the background to transparent from both the WPF and Win32 perspectives
            window.Background = Brushes.Transparent;
            HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

            MARGINS margins = new MARGINS(margin);
            DwmExtendFrameIntoClientArea(hwnd, ref margins);

            return true;
        }
Esempio n. 3
0
        /// <summary>
        /// Extends the Aero Glass area on a given window.
        /// </summary>
        /// <param name="window">The window to extend glass onto.</param>
        /// <param name="margin">The distances from the border to extend the glass by.</param>
        /// <returns>True if glass was extended successfully, otherwise false.</returns>
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            if (window == null) {
                throw new ArgumentNullException("window");
            }

            bool result = false;
            try {
                if (DwmIsCompositionEnabled()) {

                    IntPtr hwnd = new WindowInteropHelper(window).Handle;
                    if (hwnd == IntPtr.Zero)
                        throw new InvalidOperationException("The Window must be shown before extending glass.");

                    // Set the background to transparent from both the WPF and Win32 perspectives
                    window.Background = Brushes.Transparent;
                    HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

                    MARGINS margins = new MARGINS(margin);
                    DwmExtendFrameIntoClientArea(hwnd, ref margins);
                    result = true;
                }
            } catch { }
            return result;
        }
Esempio n. 4
0
 private void OpenAreo()
 {
     en = 0;
     MARGINS mg = new MARGINS(); //定义透明扩展区域的大小,这里全部-1,即全部透明
     mg.m_Buttom = -1;
     mg.m_Left = -1;
     mg.m_Right = -1;
     mg.m_Top = -1;
     //判断是否Vista及以上的系统
     if (System.Environment.OSVersion.Version.Major >= 6)
     {
         DwmIsCompositionEnabled(ref en);    //检测Aero是否为打开
         if (en > 0)
         {
             DwmExtendFrameIntoClientArea(this.Handle, ref mg);   //透明
         }
         else
         {
             MessageBox.Show("Desktop Composition is Disabled!");  //未开启透明桌面
         }
     }
     else
     {
         MessageBox.Show("Please run this at least on Windows Vista.");  //至少在vista运行
     }
     this.Paint += new PaintEventHandler(Form1_Paint);
 }
Esempio n. 5
0
        private void ConvertMp3_Load(object sender, EventArgs e)
        {
            MARGINS margins = new MARGINS();
            margins.cxLeftWidth = 0;
            margins.cxRightWidth = 0;
            margins.cyTopHeight = 45;
            margins.cyBottomHeight = 0;

            IntPtr hWnd = this.Handle;
            int result = DwmExtendFrameIntoClientArea(hWnd, ref margins);

            Process bacon = new Process();
            ProcessStartInfo p = new ProcessStartInfo();
            string sArgs = String.Format(" -i {0} {1}", SourcePath, TargetPath);
            p.FileName = Directory.GetCurrentDirectory()+@"\ffmpeg.exe";
            p.CreateNoWindow = true;
            p.RedirectStandardOutput = true;
            p.UseShellExecute = false;

            bacon.Exited += new EventHandler(myProcess_Exited);

            p.Arguments = sArgs;
            bacon.StartInfo = p;
            bacon.Start();
            bacon.WaitForExit();
            bacon.StandardOutput.ReadToEnd();
            if (FileToDelte != null)
            {
                try { File.Delete(FileToDelte); }
                catch { }
            }
            this.Close();
        }
Esempio n. 6
0
 public static void ApplyGlass(Form form)
 {
     MARGINS m = new MARGINS(-1, -1, -1, -1);
     //MARGINS m = new MARGINS(1, 1, 1, 1);
     form.Paint += new PaintEventHandler(form_Paint);
     DwmExtendFrameIntoClientArea(form.Handle, m);
 }
 private void Form1_Load(object sender, EventArgs e)
 {
     this.BackColor = Color.Black;
     MARGINS m=new MARGINS();
     m.cxLeftWidth = 20;
     m.cxRightWidth = 20;
     m.cyBottomHeight = 20;
     m.cyTopHeight = 20;
     DwmExtendFrameIntoClientArea(this.Handle,m);
 }
Esempio n. 8
0
        public static void ShowShadowUnderWindow(IntPtr intPtr)
        {
            MARGINS marInset = new MARGINS();
              marInset.m_bottomHeight = -1;
              marInset.m_leftWidth = -1;
              marInset.m_rightWidth = -1;
              marInset.m_topHeight = -1;

              DwmExtendFrameIntoClientArea(intPtr, ref marInset);
        }
Esempio n. 9
0
 public static void AeroEffect(Form f1)
 {
     MARGINS m = new MARGINS()
     {
         left = -1
     };
     DwmExtendFrameIntoClientArea(f1.Handle, ref m);
     Color aeroColor = Color.FromArgb(155, 155, 155);
     f1.TransparencyKey = aeroColor;
     f1.BackColor = aeroColor;
 }
    void WndStart()
    {
        var margins = new MARGINS() { cxLeftWidth = -1 };
        var hwnd = FindWindow(null, "CooldogAssistant");

        SetWindowLong(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);

        DwmExtendFrameIntoClientArea(hwnd, ref margins);

		SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 512, 512, SWP_NOMOVE);
    }
Esempio n. 11
0
        /// <summary>
        /// Define some element properties and init Aero Glass if using Vista or newer
        /// </summary>

        private void Form1_Load(object sender, EventArgs e)
        {
            box_output.ScrollBars = RichTextBoxScrollBars.None;
            box_output.Font = new Font("Consolas", 8);
            box_output.BackColor = Color.White;

            if (Environment.OSVersion.Version.Major >= 6)
            {
                this.BackColor = Color.DarkMagenta; this.TransparencyKey = Color.DarkMagenta;
                MARGINS marg = new MARGINS() { Left = -1, Right = -1, Top = -1, Bottom = -1 };
                DwmExtendFrameIntoClientArea(this.Handle, ref marg);
            }
        }
Esempio n. 12
0
 public static bool GlassifyHwnd(IntPtr ptr)
 {
     if (Environment.OSVersion.Version.Major >= 6 && DwmIsCompositionEnabled())
     {
         MARGINS margins = new MARGINS();
         margins.Left = -1;
         margins.Right = -1;
         margins.Top = -1;
         margins.Bottom = -1;
         return !DwmExtendFrameIntoClientArea(ptr, ref margins);
     }
     return false;
 }
Esempio n. 13
0
 /// <summary>
 /// Extends the window frame into the client area.
 /// </summary>
 /// <param name="hWnd">The handle to the window in which the frame will be extended into the client area.</param>
 /// <param name="left">The left margin.</param>
 /// <param name="top">The top margin.</param>
 /// <param name="right">The right margin.</param>
 /// <param name="bottom">The bottom margin.</param>
 /// <returns></returns>
 public static bool ExtendFrameIntoClientArea(IntPtr hWnd, int left, int top, int right, int bottom)
 {
     if (IsPlatformSupported)
     {
         MARGINS m = new MARGINS();
         m.cxLeftWidth = left;
         m.cyTopHeight = top;
         m.cxRightWidth = right;
         m.cyBottomHeight = bottom;
         return NativeMethods.DwmExtendFrameIntoClientArea(hWnd, ref m).Succeeded;
     }
     return false;
 }
Esempio n. 14
0
        public Form1()
        {
            //MessageBox.Show(Environment.Is64BitOperatingSystem.ToString());
            // check os
            Version v = System.Environment.OSVersion.Version;
            double ver = v.Major + v.Minor / 10.0;

            if (ver <= 6.0)
            {
                MessageBox.Show("This software only run on Windows 7 or later!!!");
                Environment.Exit(0);
                return;
            }

            if (!IsRunAsAdmin())
            {
                // Launch itself as administrator
                ProcessStartInfo proc = new ProcessStartInfo();
                proc.UseShellExecute = true;
                proc.WorkingDirectory = Environment.CurrentDirectory;
                proc.FileName = Application.ExecutablePath;
                proc.Verb = "runas";
                try
                {
                    Process.Start(proc);

                }
                catch(Exception ex)
                {
                    // The user refused to allow privileges elevation.
                    // Do nothing and return directly ...

                }

                Environment.Exit(0);  // Quit itself
                return;
            }
            InitializeComponent();
            if (DwmIsCompositionEnabled())
            {
                MARGINS m = new MARGINS();
                m.Right = m.Bottom = -1;
                m.Left = m.Top = -1;// this.Width + this.Height;
                DwmExtendFrameIntoClientArea(this.Handle, ref m);
            }
            bgWorker = new BGWorkReport(ReportProcess);

            backgroundWorker1.RunWorkerAsync();
            this.BringToFront();
        }
Esempio n. 15
0
 void Start()
 {
    // #if !UNITY_EDITOR
     var margins = new MARGINS() { cxLeftWidth = -1 };
     // Get a handle to the window
     var hwnd = GetActiveWindow();
     // Set properties of the window
     // See: [url]https://msdn.microsoft.com/en-us/library/windows/desktop/ms633591%28v=vs.85%29.aspx[/url]
     SetWindowLong(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
     // Extend the window into the client area
     See:https://msdn.microsoft.com/en-us/library/windows/desktop/aa969512%28v=vs.85%29.aspx[/url]
     DwmExtendFrameIntoClientArea(hwnd, ref margins);
     //#endif
 }
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            if (!DwmIsCompositionEnabled())
                return false;

            IntPtr hwnd = new WindowInteropHelper(window).Handle;

            // Set the background to transparent from both the WPF and Win32 perspectives
            window.Background = Brushes.Transparent;
            HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;

            MARGINS margins = new MARGINS(margin);
            DwmExtendFrameIntoClientArea(hwnd, ref margins);
            return true;
        }
Esempio n. 17
0
 public static int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins)
 {
   var hModule = LoadLibrary("dwmapi");
   if (hModule == IntPtr.Zero)
   {
     return 0;
   }
   var procAddress = GetProcAddress(hModule, "DwmExtendFrameIntoClientArea");
   if (procAddress == IntPtr.Zero)
   {
     return 0;
   }
   var delegateForFunctionPointer = (DwmExtendFrameIntoClientAreaDelegate)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(DwmExtendFrameIntoClientAreaDelegate));
   return delegateForFunctionPointer(hwnd, ref margins);
 }
Esempio n. 18
0
 public static bool SetAreoArea(IntPtr ptr, ref MARGINS margins)
 {
     try
     {
         int hr = DwmExtendFrameIntoClientArea(ptr, ref margins);
         if (hr < 0)
         {
             return false;
         }
     }
     catch (DllNotFoundException)
     {
         return false;
     }
     return true;
 }
Esempio n. 19
0
 public Library()
 {
     InitializeComponent();
     Transition.run(this, "Opacity", 1.0, new TransitionType_EaseInEaseOut(600));
     int val = 2;
     if (Environment.OSVersion.Version.Major > 5)
     {
         DwmSetWindowAttribute(this.Handle, 2, ref val, 4);
         MARGINS m = new MARGINS();
         m.cxLeftWidth = 0;
         m.cxRightWidth = 0;
         m.cyBottomHeight = 0;
         m.cyTopHeight = 1;
         DwmExtendFrameIntoClientArea(this.Handle, ref m);
     }
 }
Esempio n. 20
0
        public static bool ExtendGlassFrame(Window window, Thickness margin)
        {
            if (!DwmIsCompositionEnabled())
                return false;

            IntPtr hwnd = new WindowInteropHelper(window).Handle;
            if (hwnd == IntPtr.Zero)
                throw new InvalidOperationException("The Window must be shown before extending glass.");

            window.Background = Brushes.Transparent;
            HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
            MARGINS margins = new MARGINS(margin);
            DwmExtendFrameIntoClientArea(hwnd, ref margins);

            return true;
        }
Esempio n. 21
0
        public static void ExtendGlass(Window window, Thickness thikness)
        {
            try
            {
                var isGlassEnabled = 0;
                DwmIsCompositionEnabled(ref isGlassEnabled);
                if (Environment.OSVersion.Version.Major > 5 && isGlassEnabled > 0)
                {
                    // Get the window handle
                    var helper = new WindowInteropHelper(window);
                    var source = HwndSource.FromHwnd(helper.Handle);
                    source.AddHook(new HwndSourceHook(
                        delegate(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
                        {
                            if (msg == WM_DWMCOMPOSITIONCHANGED)
                            {
                                ExtendGlass(window, thikness);
                                handled = true;
                            }
                            return IntPtr.Zero;
                        }));
                    source.CompositionTarget.BackgroundColor = Colors.Transparent;
                    window.Background = Brushes.Transparent;

                    // Get the dpi of the screen
                    var desktop = System.Drawing.Graphics.FromHwnd(source.Handle);
                    var dpiX = desktop.DpiX / 96;
                    var dpiY = desktop.DpiY / 96;

                    // Set Margins
                    var margins = new MARGINS()
                    {
                        cxLeftWidth = (int)(thikness.Left * dpiX),
                        cxRightWidth = (int)(thikness.Right * dpiX),
                        cyBottomHeight = (int)(thikness.Bottom * dpiY),
                        cyTopHeight = (int)(thikness.Top * dpiY),
                    };
                    //var hr =
                    DwmExtendFrameIntoClientArea(source.Handle, ref margins);
                }
                else
                {
                    window.Background = SystemColors.WindowBrush;
                }
            }
            catch (DllNotFoundException) { }
        }
Esempio n. 22
0
        public static int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins)
        {
            DwmExtendFrameIntoClientAreaDelegate fnDwmExtendFrameIntoClientArea;
            IntPtr hMod = LoadLibrary("dwmapi");

            if (hMod == IntPtr.Zero)
                return 0;

            IntPtr fn = GetProcAddress(hMod, "DwmExtendFrameIntoClientArea");

            if (fn == IntPtr.Zero)
                return 0;

            fnDwmExtendFrameIntoClientArea = (DwmExtendFrameIntoClientAreaDelegate)Marshal.GetDelegateForFunctionPointer(
                fn, typeof(DwmExtendFrameIntoClientAreaDelegate));

            return fnDwmExtendFrameIntoClientArea(hwnd, ref margins);
        }
Esempio n. 23
0
        public static void MakeVistaFrame(Window window, int top, int bottom)
        {
            try
            {
                if (!IsComposition)
                {
                    // No glass
                    return;
                }

                if (!_prepared)
                {
                    _prepared = true;
                    PrepareVistaFrame(window);
                }

                float DesktopDpiX = _desktop.DpiX;
                //float DesktopDpiY = desktop.DpiY;

                // Set Margins
                MARGINS margins = new MARGINS();

                // Extend glass frame into client area
                // Note that the default desktop Dpi is 96dpi. The  margins are
                // adjusted for the system Dpi.
                margins.cxLeftWidth = Convert.ToInt32(5 * (DesktopDpiX / 96));
                margins.cxRightWidth = Convert.ToInt32(5 * (DesktopDpiX / 96));
                margins.cyTopHeight = Convert.ToInt32((top + 5) * (DesktopDpiX / 96));
                margins.cyBottomHeight = Convert.ToInt32((bottom + 5) * (DesktopDpiX / 96));

                int hr = DwmExtendFrameIntoClientArea(_mainWindowSrc.Handle, ref margins);
                //
                /*if (hr < 0)
                {
                    //DwmExtendFrameIntoClientArea Failed
                }*/
            }
                // If not Vista, paint background white.
            catch (DllNotFoundException)
            {
                // Application.Current.MainWindow.Background = Brushes.White;
            }
        }
Esempio n. 24
0
        public Form1()
        {
            InitializeComponent();

            hook.KeyPressed +=
            new EventHandler<KeyPressedEventArgs>(hook_KeyPressed);

            hook.RegisterHotKey(KBModifierKeys.Win, Keys.Z);

            MARGINS m = new MARGINS();
            m.bottomHeight = -1;
            m.leftWidth = -1;
            m.rightWidth = -1;
            m.topHeight = -1;

            DwmExtendFrameIntoClientArea(Handle, ref m);

            //this.RecreateHandle();
        }
Esempio n. 25
0
 private void Form3_Load(object sender, EventArgs e)
 {
     foreach (Process clsProcess in Process.GetProcesses())
     {
         if (clsProcess.ProcessName.Contains("dwm"))
         {
             MARGINS margins = new MARGINS();
             margins.cxLeftWidth = -1;
             margins.cxRightWidth = -1;
             margins.cyTopHeight = -1;
             margins.cyButtomheight = -1;
             //set all the four value -1 to apply glass effect to the whole window
             //set your own value to make specific part of the window glassy.
             IntPtr hwnd = this.Handle;
             int result = DwmExtendFrameIntoClientArea(hwnd, ref margins);
             this.BackColor = System.Drawing.Color.BlanchedAlmond;
             this.BackgroundImage = null;
         }
     }
 }
Esempio n. 26
0
        /// <summary>
        /// Extend the glass from the top of the window into the application space.
        /// </summary>
        /// <param name="pWindow">The window whos glass we want to extend.</param>
        /// <param name="iMargin">The amount to extend the glass by.</param>
        /// <param name="bTop">True to extend from the top down, false for buttom up.</param>
        public static void Extend(Window pWindow, int iTopMargin, int iBottomMargin)
        {
            try
            {
                // Obtain the window handle for WPF application.
                IntPtr mainWindowPtr = new WindowInteropHelper(pWindow).Handle;
                HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
                mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);

                // Get System Dpi.
                Drawing.Graphics desktop = Drawing.Graphics.FromHwnd(mainWindowPtr);
                float DesktopDpiX = desktop.DpiX;
                float DesktopDpiY = desktop.DpiY;

                // Set Margins.
                // Extend glass frame into client area
                // Note that the default desktop Dpi is 96dpi. The  margins are adjusted for the system Dpi.
                // The default margin size for the window content is 5.
                MARGINS tMargins = new MARGINS();
                tMargins.cxLeftWidth    = Convert.ToInt32(5 * (DesktopDpiX / 96));
                tMargins.cxRightWidth   = Convert.ToInt32(5 * (DesktopDpiX / 96));
                tMargins.cyTopHeight    = Convert.ToInt32((5 + iTopMargin) * (DesktopDpiY / 96));
                tMargins.cyBottomHeight = Convert.ToInt32((5 + iBottomMargin) * (DesktopDpiY / 96));

                // Make the call to extend the frame.
                int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref tMargins);
                if (hr < 0)
                {
                    //DwmExtendFrameIntoClientArea Failed
                    pWindow.Background = Brushes.LightGray;
                }
            }

            // If not Vista, paint background light gray.
            catch (DllNotFoundException)
            {
                pWindow.Background = Brushes.LightGray;
            }
        }
Esempio n. 27
0
        public static bool ExtendFrameIntoClientArea(Window window, int leftMargin, int topMargin, int rightMargin, int bottomMargin)
        {
            try
            {
                // Obtain the window handle for WPF application
                IntPtr windowPtr = new WindowInteropHelper(window).Handle;
                HwndSource windowSrc = HwndSource.FromHwnd(windowPtr);
                windowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);

                // Get system dpi
                System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(windowPtr);
                float desktopDpiX = desktop.DpiX;
                float desktopDpiY = desktop.DpiY;

                // Set Margins
                MARGINS margins = new MARGINS();

                // Extend frame into client area
                // (The default desktop dpi is 96. The margins are adjusted for the system dpi.)
                margins.cxLeftWidth = Convert.ToInt32(leftMargin * (desktopDpiX / 96));
                margins.cxRightWidth = Convert.ToInt32(rightMargin * (desktopDpiX / 96));
                margins.cyTopHeight = Convert.ToInt32(topMargin * (desktopDpiX / 96));
                margins.cyBottomHeight = Convert.ToInt32(bottomMargin * (desktopDpiX / 96));

                int hr = DwmExtendFrameIntoClientArea(windowSrc.Handle, ref margins);
                if (hr < 0)
                {
                    // DwmExtendFrameIntoClientArea failed
                    return false;
                }
                return true;
            }
            catch (DllNotFoundException)
            {
                return false;
            }
        }
Esempio n. 28
0
        public static void MakeGlass(Window wnd)
        {
            Brush originalBackground = wnd.Background;
            wnd.Background = Brushes.Transparent;
            try
            {
                IntPtr mainWindowPtr = new WindowInteropHelper(wnd).Handle;
                HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
                mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
                System.Drawing.Graphics desktop =
                    System.Drawing.Graphics.FromHwnd(mainWindowPtr);
                MARGINS margins = new MARGINS();
                margins.leftWidth = -1;
                margins.rightWidth = -1;
                margins.topHeight = -1;
                margins.bottomHeight = -1;
                DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
            }
            catch (Exception)
            {
                wnd.Background = originalBackground;
            }

        }
Esempio n. 29
0
 public static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margin);
Esempio n. 30
0
 static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margins);
Esempio n. 31
0
    // Use this for initialization
    void Awake()
    {
        Screen.fullScreen = false;

        /*#if UNITY_EDITOR
         *     print("编辑模式不更改窗体");
         #else*/
        switch (WinStyle)
        {
        case enumWinStyle.WinTop:
            isApha          = false;
            isAphaPenetrate = false;
            break;

        case enumWinStyle.Apha:
            isWinTop        = false;
            isApha          = true;
            isAphaPenetrate = false;
            break;

        case enumWinStyle.WinTopApha:
            isApha          = true;
            isAphaPenetrate = false;
            break;

        case enumWinStyle.WinTopAphaPenetrate:
            isApha          = true;
            isAphaPenetrate = true;
            break;

        case enumWinStyle.AphaPenetrate:
            isWinTop        = false;
            isApha          = true;
            isAphaPenetrate = true;
            break;
        }

        //
        IntPtr hwnd = FindWindow(null, strProduct);

        //hwnd = GetActiveWindow();

        //
        if (isApha)
        {
            //去边框并且透明
            SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED);
            int intExTemp = GetWindowLong(hwnd, GWL_EXSTYLE);
            if (isAphaPenetrate)//是否透明穿透窗体
            {
                SetWindowLong(hwnd, GWL_EXSTYLE, intExTemp | WS_EX_TRANSPARENT | WS_EX_LAYERED);
            }
            //
            SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_BORDER & ~WS_CAPTION);

            //保持中间位置:因为是从左上角算起的,所以获得屏幕像素后要减去窗体宽高的一半
            //currentX = Screen.currentResolution.width / 2 - 320 / 2;
            //currentY = Screen.currentResolution.height / 2 - 270 / 2;

            //获取设置当前屏幕分辩率
            Resolution[] resolutions = Screen.resolutions;
            //设置当前分辨率
            Screen.SetResolution(resolutions[resolutions.Length - 1].width, resolutions[resolutions.Length - 1].height, true);


            SetWindowPos(hwnd, -1, currentX, currentY, ResWidth, ResHeight, SWP_SHOWWINDOW);
            var margins = new MARGINS()
            {
                cxLeftWidth = -1
            };
            //
            DwmExtendFrameIntoClientArea(hwnd, ref margins);
        }
        else
        {
            //单纯去边框
            SetWindowLong(hwnd, GWL_STYLE, WS_POPUP);
            SetWindowPos(hwnd, -1, currentX, currentY, ResWidth, ResHeight, SWP_SHOWWINDOW);
        }
        Debug.Log(WinStyle);
        //#endif
    }
Esempio n. 32
0
        protected override void WndProc(ref Message m)
        {
            if (DesignMode)
            {
                base.WndProc(ref m);
                return;
            }
            if (m.Msg == WM_NCCALCSIZE)
            {
                if (m.WParam.ToInt32() == 1)
                {
                    MARGINS borderless = new MARGINS()
                    {
                        cxLeftWidth = 1, cxRightWidth = 1, cyBottomHeight = 1, cyTopHeight = 1
                    };
                    DwmExtendFrameIntoClientArea(Handle, ref borderless);

                    WINDOWPLACEMENT pl = new WINDOWPLACEMENT();
                    GetWindowPlacement(m.HWnd, ref pl);

                    if (pl.ShowCmd == ShowWindowCommands.Maximize)
                    {
                        NCCALCSIZE_PARAMS p = Marshal.PtrToStructure <NCCALCSIZE_PARAMS>(m.LParam);

                        p.rgrc[0].Left   += 7;
                        p.rgrc[0].Right  -= 8;
                        p.rgrc[0].Top    += 7;
                        p.rgrc[0].Bottom -= 8;

                        Marshal.StructureToPtr(p, m.LParam, true);
                    }
                }

                m.Result = IntPtr.Zero;
                return;
            }
            else if (m.Msg == WM_NCHITTEST)
            {
                Point mousePos = PointToClient(new Point((m.LParam.ToInt32() & 0xFFFF), (m.LParam.ToInt32() >> 16)));
                foreach (CaptionButton b in CaptionButtons)
                {
                    if (mousePos.X >= b.X && mousePos.X < b.X + b.Width && mousePos.Y >= b.Y && mousePos.Y < b.Y + b.Height)
                    {
                        m.Result = new IntPtr(b.HitTestCode);
                        return;
                    }
                }
                m.Result = new IntPtr(mousePos.X >= 0 && mousePos.X < Width && mousePos.Y >= 0 && mousePos.Y < Height ? HT_CAPTION : HT_NOWHERE);
                if (SizeBorder && WindowState == FormWindowState.Normal)
                {
                    int res = m.Result.ToInt32();
                    int col = 0;
                    if (mousePos.X >= ClientSize.Width - 5)
                    {
                        col = 2;
                    }
                    else if (mousePos.X > 5)
                    {
                        col = 1;
                    }

                    int row = 0;
                    if (mousePos.Y >= ClientSize.Height - 5)
                    {
                        row = 2;
                    }
                    else if (mousePos.Y > 5)
                    {
                        row = 1;
                    }

                    if (col == 0)
                    {
                        if (row == 0)
                        {
                            res = HT_TOPLEFT;
                        }
                        if (row == 1)
                        {
                            res = HT_LEFT;
                        }
                        if (row == 2)
                        {
                            res = HT_BOTTOMLEFT;
                        }
                    }
                    if (col == 1)
                    {
                        if (row == 0)
                        {
                            res = HT_TOP;
                        }
                        if (row == 2)
                        {
                            res = HT_BOTTOM;
                        }
                    }
                    if (col == 2)
                    {
                        if (row == 0)
                        {
                            res = HT_TOPRIGHT;
                        }
                        if (row == 1)
                        {
                            res = HT_RIGHT;
                        }
                        if (row == 2)
                        {
                            res = HT_BOTTOMRIGHT;
                        }
                    }

                    m.Result = new IntPtr(res);
                }
                return;
            }

            base.WndProc(ref m);
        }
Esempio n. 33
0
        protected override void WndProc(ref Message m)
        {
            const int wmNcHitTest   = 0x84;
            const int htLeft        = 10;
            const int htRight       = 11;
            const int htTop         = 12;
            const int htTopLeft     = 13;
            const int htTopRight    = 14;
            const int htBottom      = 15;
            const int htBottomLeft  = 16;
            const int htBottomRight = 17;

            if (m.Msg == wmNcHitTest)
            {
                int   x          = (int)(m.LParam.ToInt64() & 0xFFFF);
                int   y          = (int)((m.LParam.ToInt64() & 0xFFFF0000) >> 16);
                Point pt         = PointToClient(new Point(x, y));
                Size  clientSize = ClientSize;
                ///allow resize on the lower right corner
                if (pt.X >= clientSize.Width - 16 && pt.Y >= clientSize.Height - 16 && clientSize.Height >= 16)
                {
                    m.Result = (IntPtr)(IsMirrored ? htBottomLeft : htBottomRight);
                    return;
                }
                ///allow resize on the lower left corner
                if (pt.X <= 16 && pt.Y >= clientSize.Height - 16 && clientSize.Height >= 16)
                {
                    m.Result = (IntPtr)(IsMirrored ? htBottomRight : htBottomLeft);
                    return;
                }
                ///allow resize on the upper right corner
                if (pt.X <= 16 && pt.Y <= 16 && clientSize.Height >= 16)
                {
                    m.Result = (IntPtr)(IsMirrored ? htTopRight : htTopLeft);
                    return;
                }
                ///allow resize on the upper left corner
                if (pt.X >= clientSize.Width - 16 && pt.Y <= 16 && clientSize.Height >= 16)
                {
                    m.Result = (IntPtr)(IsMirrored ? htTopLeft : htTopRight);
                    return;
                }
                ///allow resize on the top border
                if (pt.Y <= 16 && clientSize.Height >= 16)
                {
                    m.Result = (IntPtr)(htTop);
                    return;
                }
                ///allow resize on the bottom border
                if (pt.Y >= clientSize.Height - 16 && clientSize.Height >= 16)
                {
                    m.Result = (IntPtr)(htBottom);
                    return;
                }
                ///allow resize on the left border
                if (pt.X <= 16 && clientSize.Height >= 16)
                {
                    m.Result = (IntPtr)(htLeft);
                    return;
                }
                ///allow resize on the right border
                if (pt.X >= clientSize.Width - 16 && clientSize.Height >= 16)
                {
                    m.Result = (IntPtr)(htRight);
                    return;
                }
            }

            switch (m.Msg)
            {
            case WM_NCPAINT:                            // box shadow
                if (m_aeroEnabled)
                {
                    var v = 2;
                    DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                    MARGINS margins = new MARGINS()
                    {
                        bottomHeight = 1,
                        leftWidth    = 1,
                        rightWidth   = 1,
                        topHeight    = 1
                    };
                    DwmExtendFrameIntoClientArea(this.Handle, ref margins);
                }
                break;

            default:
                break;
            }
            base.WndProc(ref m);
        }
Esempio n. 34
0
        protected override void WndProc(ref Message message)
        {
            switch (message.Msg)
            {
            // box shadow
            case WM_NCPAINT:
                if (m_aeroEnabled)
                {
                    var v = 2;
                    DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                    MARGINS margins = new MARGINS()
                    {
                        bottomHeight = 1,
                        leftWidth    = 1,
                        rightWidth   = 1,
                        topHeight    = 1
                    };
                    DwmExtendFrameIntoClientArea(this.Handle, ref margins);
                }
                break;

            default:
                break;
            }

            base.WndProc(ref message);

            if (message.Msg == 0x84) // WM_NCHITTEST
            {
                var cursor = this.PointToClient(Cursor.Position);

                if (TopLeft.Contains(cursor))
                {
                    message.Result = (IntPtr)HTTOPLEFT;
                }
                else if (TopRight.Contains(cursor))
                {
                    message.Result = (IntPtr)HTTOPRIGHT;
                }
                else if (BottomLeft.Contains(cursor))
                {
                    message.Result = (IntPtr)HTBOTTOMLEFT;
                }
                else if (BottomRight.Contains(cursor))
                {
                    message.Result = (IntPtr)HTBOTTOMRIGHT;
                }

                else if (Top.Contains(cursor))
                {
                    message.Result = (IntPtr)HTTOP;
                }
                else if (Left.Contains(cursor))
                {
                    message.Result = (IntPtr)HTLEFT;
                }
                else if (Right.Contains(cursor))
                {
                    message.Result = (IntPtr)HTRIGHT;
                }
                else if (Bottom.Contains(cursor))
                {
                    message.Result = (IntPtr)HTBOTTOM;
                }
            }
        }
Esempio n. 35
0
 public static Thickness ToPresentationThickness(this MARGINS margins)
 {
     return(new Thickness(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight));
 }
Esempio n. 36
0
 public static extern int GetThemeMargins(HandleRef hTheme, HandleRef hDC, int iPartId, int iStateId, int iPropId, NativeMethods.COMRECT prc, ref MARGINS margins);
Esempio n. 37
0
 private void Form2_Load(object sender, EventArgs e)
 {
     foreach (Process clsProcess in Process.GetProcesses())
     {
         if (clsProcess.ProcessName.Contains("dwm"))
         {
             MARGINS margins = new MARGINS();
             margins.cxLeftWidth    = 10;
             margins.cxRightWidth   = 10;
             margins.cyTopHeight    = 90;
             margins.cyButtomheight = 200;
             //set all the four value -1 to apply glass effect to the whole window
             //set your own value to make specific part of the window glassy.
             IntPtr hwnd   = this.Handle;
             int    result = DwmExtendFrameIntoClientArea(hwnd, ref margins);
             this.BackColor       = System.Drawing.Color.BlanchedAlmond;
             this.BackgroundImage = null;
             //label1.ForeColor = Color.White;
         }
     }
     general.Text = rf("config/general.conf");
     if (general.Text == "Show my home page")
     {
         homepage.ReadOnly = false;
     }
     else
     {
         homepage.ReadOnly = true;
     }
     homepage.Text = rf("home");
     if (rf("config/ad.conf") == "1")
     {
         checkBox1.Checked      = true;
         checkBox1.Enabled      = false;
         HttpProxHost.ReadOnly  = true;
         HttpProxPort.ReadOnly  = true;
         HttpsProxHost.ReadOnly = true;
         HttpsProxPort.ReadOnly = true;
         HttpProxHost.Text      = "127.0.0.1";
         HttpProxPort.Text      = "8118";
         HttpProxHost.Text      = rf("config/uproxyip.conf");
         HttpProxPort.Text      = rf("config/uproxyport.conf");
         HttpsProxHost.Text     = rf("config/sproxyip.conf");
         HttpsProxPort.Text     = rf("config/sproxyport.conf");
         abOn.Checked           = true;
     }
     else
     {
         abOn.Checked = false; abOff.Checked = true;
     }
     if (rf("config/proxybool.conf") == "1")
     {
         checkBox1.Checked  = true;
         HttpProxHost.Text  = rf("config/uproxyip.conf");
         HttpProxPort.Text  = rf("config/uproxyport.conf");
         HttpsProxHost.Text = rf("config/sproxyip.conf");
         HttpsProxPort.Text = rf("config/sproxyport.conf");
     }
     if (checkBox1.Checked == true && rf("config/ad.conf") != "1")
     {
         HttpProxHost.ReadOnly  = false;
         HttpProxPort.ReadOnly  = false;
         HttpsProxHost.ReadOnly = false;
         HttpsProxPort.ReadOnly = false;
     }
     else
     {
         HttpProxHost.ReadOnly  = true;
         HttpProxPort.ReadOnly  = true;
         HttpsProxHost.ReadOnly = true;
         HttpsProxPort.ReadOnly = true;
     }
     if (rf("ab") == "a")
     {
         abAggressive.Checked = true;
     }
     else
     {
         abConservative.Checked = true;
     }
     if (Yasfib.Form1.isChinese == true)
     {
         tabPage1.Text       = "常规";
         label1.Text         = "启动时:";
         label2.Text         = "首页:";
         tabPage3.Text       = "隐私";
         label3.Text         = "屏蔽广告:";
         abOff.Text          = "关";
         abOn.Text           = "开";
         button3.Text        = "删除浏览记录";
         tabPage4.Text       = "代理";
         checkBox1.Text      = "使用代理服务器";
         label7.Text         = "端口";
         wsdf.Text           = "快速选择:";
         button4.Text        = "台湾";
         button5.Text        = "美国";
         button6.Text        = "加拿大";
         button7.Text        = "德国";
         this.Text           = "首选项";
         abAggressive.Text   = "全部网页";
         abConservative.Text = "智能";
         label8.Text         = "反封杀模式";
     }
 }
Esempio n. 38
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case 0x0084:
                if (piMaximizeBox.Visible)
                {
                    Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF);
                    vPoint = PointToClient(vPoint);
                    base.WndProc(ref m);
                    if (vPoint.X <= 5)
                    {
                        if (vPoint.Y <= 5)
                        {
                            m.Result = (IntPtr)Guying_HTTOPLEFT;
                        }
                        else if (vPoint.Y >= ClientSize.Height - 5)
                        {
                            m.Result = (IntPtr)Guying_HTBOTTOMLEFT;
                        }
                        else
                        {
                            m.Result = (IntPtr)Guying_HTLEFT;
                        }
                    }
                    else if (vPoint.X >= ClientSize.Width - 5)
                    {
                        if (vPoint.Y <= 5)
                        {
                            m.Result = (IntPtr)Guying_HTTOPRIGHT;
                        }
                        else if (vPoint.Y >= ClientSize.Height - 5)
                        {
                            m.Result = (IntPtr)Guying_HTBOTTOMRIGHT;
                        }
                        else
                        {
                            m.Result = (IntPtr)Guying_HTRIGHT;
                        }
                    }
                    else if (vPoint.Y <= 5)
                    {
                        m.Result = (IntPtr)Guying_HTTOP;
                    }
                    else if (vPoint.Y >= ClientSize.Height - 5)
                    {
                        m.Result = (IntPtr)Guying_HTBOTTOM;
                    }
                }
                else
                {
                    base.WndProc(ref m);
                }
                break;

            case 0x0085:                            // box shadow
                if (m_aeroEnabled)
                {
                    var v = 2;
                    DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                    MARGINS margins = new MARGINS()
                    {
                        bottomHeight = 1,
                        leftWidth    = 1,
                        rightWidth   = 1,
                        topHeight    = 1
                    };
                    DwmExtendFrameIntoClientArea(this.Handle, ref margins);
                }
                break;

            /*
             * case 0x0201: //鼠标左键按下的消息
             * m.Msg = 0x00A1; //更改消息为非客户区按下鼠标
             * m.LParam = IntPtr.Zero; //默认值
             * m.WParam = new IntPtr(2);//鼠标放在标题栏内
             * base.WndProc(ref m);
             * break;
             */
            default:
                base.WndProc(ref m);
                break;
            }
        }
Esempio n. 39
0
 private extern static int GetThemeMargins(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, int iPropId, IntPtr rect, out MARGINS pMargins);
Esempio n. 40
0
 public static extern int DwmExtendFrameIntoClientArea(IntPtr hdc, ref MARGINS marInset);
Esempio n. 41
0
 public static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, MARGINS pMargins);
 private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS mARGINS);
Esempio n. 43
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case WM_NCHITTEST:
                base.WndProc(ref m);
                short x      = (short)((int)m.LParam & 0xFFFF);
                short y      = (short)((int)m.LParam >> 16 & 0xFFFF);
                Point vPoint = new Point(x, y);
                vPoint = PointToClient(vPoint);
                if (vPoint.X <= 5)
                {
                    if (vPoint.Y <= 5)
                    {
                        m.Result = (IntPtr)HTTOPLEFT;
                    }
                    else if (vPoint.Y >= ClientSize.Height - 5)
                    {
                        m.Result = (IntPtr)HTBOTTOMLEFT;
                    }
                    else
                    {
                        m.Result = (IntPtr)HTLEFT;
                    }
                }
                else if (vPoint.X >= ClientSize.Width - 5)
                {
                    if (vPoint.Y <= 5)
                    {
                        m.Result = (IntPtr)HTTOPRIGHT;
                    }
                    else if (vPoint.Y >= ClientSize.Height - 5)
                    {
                        m.Result = (IntPtr)HTBOTTOMRIGHT;
                    }
                    else
                    {
                        m.Result = (IntPtr)HTRIGHT;
                    }
                }
                else if (vPoint.Y <= 5)
                {
                    m.Result = (IntPtr)HTTOP;
                }
                else if (vPoint.Y >= ClientSize.Height - 5)
                {
                    m.Result = (IntPtr)HTBOTTOM;
                }
                break;

            case WM_NCPAINT:                            // box shadow
                if (m_aeroEnabled)
                {
                    var v = 2;
                    DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                    MARGINS margins = new MARGINS()
                    {
                        bottomHeight = 1,
                        leftWidth    = 1,
                        rightWidth   = 1,
                        topHeight    = 1
                    };
                    DwmExtendFrameIntoClientArea(this.Handle, ref margins);
                }
                break;

            default:
                base.WndProc(ref m);
                break;
            }
            if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT)     // drag the form
            {
                m.Result = (IntPtr)HTCAPTION;
            }
        }
Esempio n. 44
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case WM_NCPAINT:                            // box shadow
                if (m_aeroEnabled && ShowShadow)
                {
                    var v = 2;
                    DwmSetWindowAttribute(Handle, 2, ref v, 4);
                    MARGINS margins = new MARGINS()
                    {
                        bottomHeight = 0,
                        leftWidth    = 0,
                        rightWidth   = 0,
                        topHeight    = 1
                    };
                    DwmExtendFrameIntoClientArea(Handle, ref margins);
                }
                base.WndProc(ref m);
                break;

            case 0x0084:
                base.WndProc(ref m);
                Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF);
                vPoint = PointToClient(vPoint);
                if (CanDragReSize && WindowState != FormWindowState.Maximized)
                {
                    if (vPoint.X <= 4)
                    {
                        if (vPoint.Y <= 4)
                        {
                            m.Result = (IntPtr)Guying_HTTOPLEFT;
                        }
                        else if (vPoint.Y >= ClientSize.Height - 4)
                        {
                            m.Result = (IntPtr)Guying_HTBOTTOMLEFT;
                        }
                        else
                        {
                            m.Result = (IntPtr)Guying_HTLEFT;
                        }
                    }
                    else if (vPoint.X >= ClientSize.Width - 4)
                    {
                        if (vPoint.Y <= 4)
                        {
                            m.Result = (IntPtr)Guying_HTTOPRIGHT;
                        }
                        else if (vPoint.Y >= ClientSize.Height - 4)
                        {
                            m.Result = (IntPtr)Guying_HTBOTTOMRIGHT;
                        }
                        else
                        {
                            m.Result = (IntPtr)Guying_HTRIGHT;
                        }
                    }
                    else if (vPoint.Y <= 4)
                    {
                        m.Result = (IntPtr)Guying_HTTOP;
                    }
                    else if (vPoint.Y >= ClientSize.Height - 4)
                    {
                        m.Result = (IntPtr)Guying_HTBOTTOM;
                    }
                }
                break;

            case 0x0201:
                if (CanDrag)
                {
                    m.Msg    = 0x00A1;        //更改消息为非客户区按下鼠标
                    m.WParam = new IntPtr(2); //鼠标放在标题栏内
                }
                base.WndProc(ref m);
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
Esempio n. 45
0
 public static extern Int32 DwmExtendFrameIntoClientArea(
 IntPtr hWnd,
 ref MARGINS pMarInset);
 public extern static Int32 GetThemeMargins(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, int iPropId, IntPtr rect, out MARGINS pMargins);
Esempio n. 47
0
        protected override void WndProc(ref Message m)
        {
            const int RESIZE_HANDLE_SIZE = 10;

            switch (m.Msg)
            {
            case WM_NCPAINT:
                if (m_aeroEnabled)
                {
                    var v = 2;
                    DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                    MARGINS margins = new MARGINS()
                    {
                        bottomHeight = 1,
                        leftWidth    = 0,
                        rightWidth   = 0,
                        topHeight    = 0
                    }; DwmExtendFrameIntoClientArea(this.Handle, ref margins);
                }
                break;

            default: break;

            case 0x0084 /*NCHITTEST*/:

                base.WndProc(ref m);
                if ((int)m.Result == 0x01 /*HTCLIENT*/)
                {
                    if (skeetResizable)
                    {
                        Point screenPoint = new Point(m.LParam.ToInt32());
                        Point clientPoint = this.PointToClient(screenPoint);
                        if (clientPoint.Y <= RESIZE_HANDLE_SIZE)
                        {
                            if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                            {
                                m.Result = (IntPtr)13 /*HTTOPLEFT*/;
                            }
                            else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                            {
                                m.Result = (IntPtr)12 /*HTTOP*/;
                            }
                            else
                            {
                                m.Result = (IntPtr)14 /*HTTOPRIGHT*/;
                            }
                        }
                        else if (clientPoint.Y <= (Size.Height - RESIZE_HANDLE_SIZE))
                        {
                            if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                            {
                                m.Result = (IntPtr)10 /*HTLEFT*/;
                            }
                            else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                            {
                                m.Result = (IntPtr)2 /*HTCAPTION*/;
                            }
                            else
                            {
                                m.Result = (IntPtr)11 /*HTRIGHT*/;
                            }
                        }
                        else
                        {
                            if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                            {
                                m.Result = (IntPtr)16 /*HTBOTTOMLEFT*/;
                            }
                            else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                            {
                                m.Result = (IntPtr)15 /*HTBOTTOM*/;
                            }
                            else
                            {
                                m.Result = (IntPtr)17 /*HTBOTTOMRIGHT*/;
                            }
                        }
                    }
                    else
                    {
                        m.Result = (IntPtr)HTCAPTION;
                    }
                }

                return;
            }

            if (m.Msg == WM_NCLBUTTONDBLCLK)
            {
                m.Result = IntPtr.Zero;
                return;
            }

            base.WndProc(ref m);
            if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT)
            {
                m.Result = (IntPtr)HTCAPTION;
            }
        }
 public static bool WindowBorderlessDropShadow(IntPtr hWnd, int ShadowSize)
 {
     MARGINS Margins = new MARGINS(0, ShadowSize, 0, ShadowSize);
     int result = SafeNativeMethods.DwmExtendFrameIntoClientArea(hWnd, ref Margins);
     return (result == 0);
 }
        private IntPtr HwndHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            IntPtr returnval = IntPtr.Zero;

            switch (message)
            {
            case Constants.WM_NCCALCSIZE:
                /* Hides the border */
                handled = true;
                break;

            case Constants.WM_NCPAINT:
            {
                if (!ShouldHaveBorder())
                {
                    var val = 2;
                    UnsafeNativeMethods.DwmSetWindowAttribute(_mHWND, 2, ref val, 4);
                    var m = new MARGINS {
                        bottomHeight = 1, leftWidth = 1, rightWidth = 1, topHeight = 1
                    };
                    UnsafeNativeMethods.DwmExtendFrameIntoClientArea(_mHWND, ref m);

                    if (Border != null)
                    {
                        Border.BorderThickness = new Thickness(0);
                    }
                }
                else
                {
                    AddBorder();
                }
                handled = true;
            }
            break;

            case Constants.WM_NCACTIVATE:
            {
                /* As per http://msdn.microsoft.com/en-us/library/ms632633(VS.85).aspx , "-1" lParam
                 * "does not repaint the nonclient area to reflect the state change." */
                returnval = UnsafeNativeMethods.DefWindowProc(hWnd, message, wParam, new IntPtr(-1));

                if (!ShouldHaveBorder())
                {
                    if (wParam == IntPtr.Zero)
                    {
                        AddBorder();
                    }
                    else
                    {
                        RemoveBorder();
                    }
                }

                handled = true;
            }
            break;

            case Constants.WM_GETMINMAXINFO:
                /* http://blogs.msdn.com/b/llobo/archive/2006/08/01/maximizing-window-_2800_with-windowstyle_3d00_none_2900_-considering-taskbar.aspx */
                WmGetMinMaxInfo(hWnd, lParam);

                /* Setting handled to false enables the application to process it's own Min/Max requirements,
                 * as mentioned by jason.bullard (comment from September 22, 2011) on http://gallery.expression.microsoft.com/ZuneWindowBehavior/ */
                handled = false;
                break;

            case Constants.WM_NCHITTEST:
                // don't process the message on windows that are maximized as those don't have a resize border at all
                if (this.AssociatedObject.WindowState == WindowState.Maximized)
                {
                    break;
                }

                // don't process the message on windows that can't be resized
                var resizeMode = AssociatedObject.ResizeMode;
                if (resizeMode == ResizeMode.CanMinimize || resizeMode == ResizeMode.NoResize)
                {
                    break;
                }

                // get X & Y out of the message
                var screenPoint = new Point(UnsafeNativeMethods.GET_X_LPARAM(lParam), UnsafeNativeMethods.GET_Y_LPARAM(lParam));

                // convert to window coordinates
                var windowPoint = AssociatedObject.PointFromScreen(screenPoint);
                var windowSize  = AssociatedObject.RenderSize;
                var windowRect  = new Rect(windowSize);
                windowRect.Inflate(-6, -6);

                // don't process the message if the mouse is outside the 6px resize border
                if (windowRect.Contains(windowPoint))
                {
                    break;
                }

                var windowHeight = (int)windowSize.Height;
                var windowWidth  = (int)windowSize.Width;

                // create the rectangles where resize arrows are shown
                var topLeft  = new Rect(0, 0, 6, 6);
                var top      = new Rect(6, 0, windowWidth - 12, 6);
                var topRight = new Rect(windowWidth - 6, 0, 6, 6);

                var left  = new Rect(0, 6, 6, windowHeight - 12);
                var right = new Rect(windowWidth - 6, 6, 6, windowHeight - 12);

                var bottomLeft  = new Rect(0, windowHeight - 6, 6, 6);
                var bottom      = new Rect(6, windowHeight - 6, windowWidth - 12, 6);
                var bottomRight = new Rect(windowWidth - 6, windowHeight - 6, 6, 6);

                // check if the mouse is within one of the rectangles
                if (topLeft.Contains(windowPoint))
                {
                    returnval = (IntPtr)Constants.HTTOPLEFT;
                }
                else if (top.Contains(windowPoint))
                {
                    returnval = (IntPtr)Constants.HTTOP;
                }
                else if (topRight.Contains(windowPoint))
                {
                    returnval = (IntPtr)Constants.HTTOPRIGHT;
                }
                else if (left.Contains(windowPoint))
                {
                    returnval = (IntPtr)Constants.HTLEFT;
                }
                else if (right.Contains(windowPoint))
                {
                    returnval = (IntPtr)Constants.HTRIGHT;
                }
                else if (bottomLeft.Contains(windowPoint))
                {
                    returnval = (IntPtr)Constants.HTBOTTOMLEFT;
                }
                else if (bottom.Contains(windowPoint))
                {
                    returnval = (IntPtr)Constants.HTBOTTOM;
                }
                else if (bottomRight.Contains(windowPoint))
                {
                    returnval = (IntPtr)Constants.HTBOTTOMRIGHT;
                }

                if (returnval != IntPtr.Zero)
                {
                    handled = true;
                }

                break;

            case Constants.WM_INITMENU:
                var window = AssociatedObject as MetroWindow;

                if (window != null)
                {
                    if (!window.ShowMaxRestoreButton)
                    {
                        UnsafeNativeMethods.EnableMenuItem(UnsafeNativeMethods.GetSystemMenu(hWnd, false), Constants.SC_MAXIMIZE, Constants.MF_GRAYED | Constants.MF_BYCOMMAND);
                    }
                    else
                    if (window.WindowState == WindowState.Maximized)
                    {
                        UnsafeNativeMethods.EnableMenuItem(UnsafeNativeMethods.GetSystemMenu(hWnd, false), Constants.SC_MAXIMIZE, Constants.MF_GRAYED | Constants.MF_BYCOMMAND);
                        UnsafeNativeMethods.EnableMenuItem(UnsafeNativeMethods.GetSystemMenu(hWnd, false), Constants.SC_RESTORE, Constants.MF_ENABLED | Constants.MF_BYCOMMAND);
                        UnsafeNativeMethods.EnableMenuItem(UnsafeNativeMethods.GetSystemMenu(hWnd, false), Constants.SC_MOVE, Constants.MF_GRAYED | Constants.MF_BYCOMMAND);
                    }
                    else
                    {
                        UnsafeNativeMethods.EnableMenuItem(UnsafeNativeMethods.GetSystemMenu(hWnd, false), Constants.SC_MAXIMIZE, Constants.MF_ENABLED | Constants.MF_BYCOMMAND);
                        UnsafeNativeMethods.EnableMenuItem(UnsafeNativeMethods.GetSystemMenu(hWnd, false), Constants.SC_RESTORE, Constants.MF_GRAYED | Constants.MF_BYCOMMAND);
                        UnsafeNativeMethods.EnableMenuItem(UnsafeNativeMethods.GetSystemMenu(hWnd, false), Constants.SC_MOVE, Constants.MF_ENABLED | Constants.MF_BYCOMMAND);
                    }

                    if (!window.ShowMinButton)
                    {
                        UnsafeNativeMethods.EnableMenuItem(UnsafeNativeMethods.GetSystemMenu(hWnd, false), Constants.SC_MINIMIZE, Constants.MF_GRAYED | Constants.MF_BYCOMMAND);
                    }

                    if (AssociatedObject.ResizeMode == ResizeMode.NoResize || window.WindowState == WindowState.Maximized)
                    {
                        UnsafeNativeMethods.EnableMenuItem(UnsafeNativeMethods.GetSystemMenu(hWnd, false), Constants.SC_SIZE, Constants.MF_GRAYED | Constants.MF_BYCOMMAND);
                    }
                }
                break;
            }
            return(returnval);
        }
Esempio n. 50
0
 public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS pMarInset);
 public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins);
Esempio n. 52
0
        private void waveshow()
        {
            if (DwmIsCompositionEnabled())
            {
                MARGINS margins = new MARGINS();
                margins.Right  = -1;
                margins.Left   = -1;
                margins.Top    = -1;
                margins.Bottom = -1;
                DwmExtendFrameIntoClientArea(this.Handle, ref margins);
            }
            Bitmap   backgroundimage = new Bitmap(this.Width, this.Height);
            Graphics g = Graphics.FromImage(backgroundimage);

            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            Rectangle           rec1 = new Rectangle(70, 50, this.Width - 100, this.Height - 230);
            Pen                 p    = new Pen(Color.FromArgb(0, 0, 0), 1);
            LinearGradientBrush lgb1 = new LinearGradientBrush(
                new System.Drawing.Point(29, 0),
                new System.Drawing.Point(70, 0),
                Color.FromArgb(0, Color.Transparent),
                Color.FromArgb(180, 255, 255, 255));

            LinearGradientBrush lgb2 = new LinearGradientBrush(
                new System.Drawing.Point(0, 40),
                new System.Drawing.Point(0, 50),
                Color.FromArgb(0, Color.Transparent),
                Color.FromArgb(180, 255, 255, 255));

            LinearGradientBrush lgb3 = new LinearGradientBrush(
                new System.Drawing.Point(0, this.Height - 160),
                new System.Drawing.Point(0, this.Height - 180),
                Color.FromArgb(0, Color.Transparent),
                Color.FromArgb(180, 255, 255, 255));

            LinearGradientBrush lgb4 = new LinearGradientBrush(
                new System.Drawing.Point(this.Width - 20, 0),
                new System.Drawing.Point(this.Width - 30, 0),
                Color.FromArgb(0, Color.Transparent),
                Color.FromArgb(180, 255, 255, 255));



            Rectangle rec2 = new Rectangle(30, 50, 40, this.Height - 230);
            Rectangle rec3 = new Rectangle(70, 40, this.Width - 100, 10);
            Rectangle rec4 = new Rectangle(70, this.Height - 180, this.Width - 100, 20);
            Rectangle rec5 = new Rectangle(this.Width - 30, 50, 10, this.Height - 230);



            g.FillRectangle(new SolidBrush(Color.FromArgb(180, 255, 255, 255)), rec1);
            g.FillRectangle(lgb1, rec2);
            g.FillRectangle(lgb2, rec3);
            g.FillRectangle(lgb3, rec4);
            g.FillRectangle(lgb4, rec5);

            GraphicsPath path = new GraphicsPath();

            path.AddEllipse(30, 40, 80, 20);
            PathGradientBrush pthGrBrush = new PathGradientBrush(path);

            pthGrBrush.CenterColor    = Color.FromArgb(180, 255, 255, 255);
            pthGrBrush.SurroundColors = new Color[] { Color.FromArgb(0, Color.Transparent) };
            g.FillPie(pthGrBrush, 30, 40, 80, 20, 180, 90);

            path = new GraphicsPath();
            path.AddEllipse(30, this.Height - 200, 80, 40);
            pthGrBrush                = new PathGradientBrush(path);
            pthGrBrush.CenterColor    = Color.FromArgb(180, 255, 255, 255);
            pthGrBrush.SurroundColors = new Color[] { Color.FromArgb(0, Color.Transparent) };
            g.FillPie(pthGrBrush, 30, this.Height - 200, 80, 40, 90, 90);

            path = new GraphicsPath();
            path.AddEllipse(this.Width - 40, this.Height - 200, 20, 40);
            pthGrBrush                = new PathGradientBrush(path);
            pthGrBrush.CenterColor    = Color.FromArgb(180, 255, 255, 255);
            pthGrBrush.SurroundColors = new Color[] { Color.FromArgb(0, Color.Transparent) };
            g.FillPie(pthGrBrush, this.Width - 40, this.Height - 200, 20, 40, 0, 90);

            path = new GraphicsPath();
            path.AddEllipse(this.Width - 40, 40, 20, 20);
            pthGrBrush                = new PathGradientBrush(path);
            pthGrBrush.CenterColor    = Color.FromArgb(180, 255, 255, 255);
            pthGrBrush.SurroundColors = new Color[] { Color.FromArgb(0, Color.Transparent) };
            g.FillPie(pthGrBrush, this.Width - 40, 40, 20, 20, 270, 90);


            g.DrawLine(p, 70, 50, 70, this.Height - 180);
            g.DrawLine(p, 70, this.Height - 180, this.Width - 30, this.Height - 180);


            p.Color       = Color.FromArgb(150, 150, 100);
            p.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;
            p.DashPattern = new float[] { 5f, 5f };
            for (int i = 0; i < 10; i++)
            {
                g.DrawLine(p, 70, 50 + (this.Height - 230) * i / 10, this.Width - 30, 50 + (this.Height - 230) * i / 10);
            }
            for (int i = 0; i < 10; i++)
            {
                g.DrawLine(p, 70 + (this.Width - 100) * (i + 1) / 10, 50, 70 + (this.Width - 100) * (i + 1) / 10, this.Height - 180);
            }
            p.DashPattern = new float[] { 2f, 2f };
            for (int i = 0; i < 10; i++)
            {
                g.DrawLine(p, 70, 50 + (this.Height - 230) * (2 * i + 1) / 20, this.Width - 30, 50 + (this.Height - 230) * (2 * i + 1) / 20);
            }
            for (int i = 0; i < 10; i++)
            {
                g.DrawLine(p, 70 + (this.Width - 100) * (2 * i + 1) / 20, 50, 70 + (this.Width - 100) * (2 * i + 1) / 20, this.Height - 180);
            }
            p.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
            drawcalibration(p, g);
            this.BackgroundImage = backgroundimage;

            GC.Collect();
        }
Esempio n. 53
0
 internal static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
Esempio n. 54
0
 public static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS m);
Esempio n. 55
0
 protected static extern int DwmExtendFrameIntoClientArea(
     IntPtr hwnd,
     ref MARGINS pMarInset);
Esempio n. 56
0
        protected override void WndProc(ref Message m)
        {
            if (!p_IsResizable || WindowState == FormWindowState.Maximized)
            {
                base.WndProc(ref m);
                return;
            }

            const int RESIZE_HANDLE_SIZE = 10;

            switch (m.Msg)
            {
            case 0x0084 /*NCHITTEST*/:
                base.WndProc(ref m);

                if ((int)m.Result == 0x01 /*HTCLIENT*/)
                {
                    Point screenPoint = new Point(m.LParam.ToInt32());
                    Point clientPoint = this.PointToClient(screenPoint);
                    if (clientPoint.Y <= RESIZE_HANDLE_SIZE)
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                        {
                            m.Result = (IntPtr)13 /*HTTOPLEFT*/;
                        }
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                        {
                            m.Result = (IntPtr)12 /*HTTOP*/;
                        }
                        else
                        {
                            m.Result = (IntPtr)14 /*HTTOPRIGHT*/;
                        }
                    }
                    else if (clientPoint.Y <= (Size.Height - RESIZE_HANDLE_SIZE))
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                        {
                            m.Result = (IntPtr)10 /*HTLEFT*/;
                        }
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                        {
                            m.Result = (IntPtr)2 /*HTCAPTION*/;
                        }
                        else
                        {
                            m.Result = (IntPtr)11 /*HTRIGHT*/;
                        }
                    }
                    else
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                        {
                            m.Result = (IntPtr)16 /*HTBOTTOMLEFT*/;
                        }
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                        {
                            m.Result = (IntPtr)15 /*HTBOTTOM*/;
                        }
                        else
                        {
                            m.Result = (IntPtr)17 /*HTBOTTOMRIGHT*/;
                        }
                    }
                }
                return;

            case WM_NCPAINT:                            // box shadow
                if (m_aeroEnabled)
                {
                    var v = 2;
                    DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                    MARGINS margins = new MARGINS()
                    {
                        bottomHeight = 1,
                        leftWidth    = 1,
                        rightWidth   = 1,
                        topHeight    = 1
                    };
                    DwmExtendFrameIntoClientArea(this.Handle, ref margins);
                }
                break;
            }
            base.WndProc(ref m);
        }
Esempio n. 57
0
		static extern void DwmExtendFrameIntoClientArea (IntPtr hwnd, ref MARGINS margins);
Esempio n. 58
0
 private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
Esempio n. 59
0
 internal static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
Esempio n. 60
0
 private static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins);