Exemple #1
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == WM_BLOCKED)
            {
                WM_BLOCKED = -1;
                return;
            }

            switch (m.Msg)
            {
            case 0x0219:     /*WM_DEVICECHANGE*/
                WM_BLOCKED = m.Msg;
                Task.Run(delegate()
                {
                    if (RuntimeVariables.DeviceProperties.IsConnected && SerialIO.Ports.All(p => p != RuntimeVariables.DeviceProperties.SerialPort))
                    {
                        RuntimeVariables.DeviceProperties.IsConnected = false;
                        HomePage.Instance.Invoke(new Action(delegate()
                        {
                            HomePage.Instance.pbxUsb.Image = Resources.usb_bad;

                            HomePage.Instance.pbxFlash.Image      = Resources.bolt_gray;
                            HomePage.Instance.eBtnFlash.Gradient  = true;
                            HomePage.Instance.eBtnFlash.Enabled   = false;
                            HomePage.Instance.eBtnFlash.TextColor = Color.FromArgb(100, 100, 100);
                        }));
                    }
                    else if (!RuntimeVariables.DeviceProperties.IsConnected && SerialIO.Ports.Any(p => p == RuntimeVariables.DeviceProperties.SerialPort))
                    {
                        RuntimeVariables.DeviceProperties.IsConnected = true;
                        HomePage.Instance.Invoke(new Action(delegate()
                        {
                            HomePage.Instance.pbxUsb.Image = Resources.usb_ok;

                            HomePage.Instance.pbxFlash.Image      = Resources.bolt_white;
                            HomePage.Instance.eBtnFlash.Gradient  = false;
                            HomePage.Instance.eBtnFlash.Enabled   = true;
                            HomePage.Instance.eBtnFlash.TextColor = Color.White;
                        }));
                    }

                    RuntimeVariables.DeviceTable = SerialIO.Devices;
                });
                break;

            case 0x0085:     /*WM_NCPAINT*/
                int attr = 2;
                NativeMethods.DwmSetWindowAttribute(Handle, 2, ref attr, 4);
                MARGINS wRgn = new MARGINS()
                {
                    bH = 1,
                    lW = 1,
                    rW = 1,
                    tH = 1
                };
                NativeMethods.DwmExtendFrameIntoClientArea(Handle, ref wRgn);
                break;

            case 0x0084:     /*WM_NCHITTEST*/
                int RESIZE_HANDLE_SIZE = 10;
                if ((int)m.Result is 0x01)
                {
                    var screenPoint = new Point(m.LParam.ToInt32());
                    var clientPoint = PointToClient(screenPoint);

                    if (clientPoint.Y <= RESIZE_HANDLE_SIZE)
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                        {
                            m.Result = (IntPtr)13;
                        }
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                        {
                            m.Result = (IntPtr)12;
                        }
                        else
                        {
                            m.Result = (IntPtr)14;
                        }
                    }
                    else if (clientPoint.Y <= (Size.Height - RESIZE_HANDLE_SIZE))
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                        {
                            m.Result = (IntPtr)10;
                        }
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                        {
                            m.Result = (IntPtr)2;
                        }
                        else
                        {
                            m.Result = (IntPtr)11;
                        }
                    }
                    else
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                        {
                            m.Result = (IntPtr)16;
                        }
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                        {
                            m.Result = (IntPtr)15;
                        }
                        else
                        {
                            m.Result = (IntPtr)17;
                        }
                    }
                }
                return;
            }
        }
Exemple #2
0
 public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);