Example #1
0
        protected override void WndProc(ref Message m)
        {
            //const long WM_SIZING = 0x214;
            //const int WMSZ_LEFT = 1;
            //const int WMSZ_RIGHT = 2;
            //const int WMSZ_TOP = 3;
            //const int WMSZ_TOPLEFT = 4;
            //const int WMSZ_TOPRIGHT = 5;
            //const int WMSZ_BOTTOM = 6;
            //const int WMSZ_BOTTOMLEFT = 7;
            //const int WMSZ_BOTTOMRIGHT = 8;
            const int WM_SYSCHAR = 0x106;

            // Hande 'beep'
            if (m.Msg == WM_SYSCHAR)
            {
                return;
            }

            // Albert, 2010-03-13: The following code can be used to make the window always maintain a fixed aspect ratio.
            // It was commented out because it doesn't really help. At least in the fullscreen mode, the aspect ratio is determined
            // by the screen and not by any other desired aspect ratio. I think we should not use the code, that's why I comment
            // it out.
            // When it should be used, the field _fixed_aspect_ratio must be initialized with a sensible value, for example
            // the aspect ratio from the skin.
            //if (m.Msg == WM_SIZING && m.HWnd == Handle)
            //{
            //  if (WindowState == FormWindowState.Normal)
            //  {
            //    Rect r = (Rect) Marshal.PtrToStructure(m.LParam, typeof(Rect));

            //    // Calc the border offset
            //    Size offset = new Size(Width - ClientSize.Width, Height - ClientSize.Height);

            //    // Calc the new dimensions.
            //    float wid = r.Right - r.Left - offset.Width;
            //    float hgt = r.Bottom - r.Top - offset.Height;
            //    // Calc the new aspect ratio.
            //    float new_aspect_ratio = hgt / wid;

            //    // See if the aspect ratio is changing.
            //    if (_fixed_aspect_ratio != new_aspect_ratio)
            //    {
            //      Int32 dragBorder = m.WParam.ToInt32();
            //      // To decide which dimension we should preserve,
            //      // see what border the user is dragging.
            //      if (dragBorder == WMSZ_TOPLEFT || dragBorder == WMSZ_TOPRIGHT ||
            //          dragBorder == WMSZ_BOTTOMLEFT || dragBorder == WMSZ_BOTTOMRIGHT)
            //      {
            //        // The user is dragging a corner.
            //        // Preserve the bigger dimension.
            //        if (new_aspect_ratio > _fixed_aspect_ratio)
            //          // It's too tall and thin. Make it wider.
            //          wid = hgt / _fixed_aspect_ratio;
            //        else
            //          // It's too short and wide. Make it taller.
            //          hgt = wid * _fixed_aspect_ratio;
            //      }
            //      else if (dragBorder == WMSZ_LEFT || dragBorder == WMSZ_RIGHT)
            //        // The user is dragging a side.
            //        // Preserve the width.
            //        hgt = wid * _fixed_aspect_ratio;
            //      else if (dragBorder == WMSZ_TOP || dragBorder == WMSZ_BOTTOM)
            //        // The user is dragging the top or bottom.
            //        // Preserve the height.
            //        wid = hgt / _fixed_aspect_ratio;
            //      // Figure out whether to reset the top/bottom
            //      // and left/right.
            //      // See if the user is dragging the top edge.
            //      if (dragBorder == WMSZ_TOP || dragBorder == WMSZ_TOPLEFT ||
            //          dragBorder == WMSZ_TOPRIGHT)
            //        // Reset the top.
            //        r.Top = r.Bottom - (int)(hgt + offset.Height);
            //      else
            //        // Reset the bottom.
            //        r.Bottom = r.Top + (int)(hgt + offset.Height);
            //      // See if the user is dragging the left edge.
            //      if (dragBorder == WMSZ_LEFT || dragBorder == WMSZ_TOPLEFT ||
            //          dragBorder == WMSZ_BOTTOMLEFT)
            //        // Reset the left.
            //        r.Left = r.Right - (int)(wid + offset.Width);
            //      else
            //        // Reset the right.
            //        r.Right = r.Left + (int)(wid + offset.Width);
            //      // Update the Message object's LParam field.
            //      Marshal.StructureToPtr(r, m.LParam, true);
            //    }
            //  }
            //}
            // Send windows message through the system if any component needs to access windows messages
            WindowsMessaging.BroadcastWindowsMessage(ref m);
            base.WndProc(ref m);
        }
Example #2
0
        protected override void WndProc(ref Message m)
        {
            const long WM_SIZING        = 0x214;
            const int  WMSZ_LEFT        = 1;
            const int  WMSZ_RIGHT       = 2;
            const int  WMSZ_TOP         = 3;
            const int  WMSZ_TOPLEFT     = 4;
            const int  WMSZ_TOPRIGHT    = 5;
            const int  WMSZ_BOTTOM      = 6;
            const int  WMSZ_BOTTOMLEFT  = 7;
            const int  WMSZ_BOTTOMRIGHT = 8;
            const int  WM_SYSCHAR       = 0x106;
            const int  WM_DISPLAYCHANGE = 0x007E;

            // Hande 'beep'
            if (m.Msg == WM_SYSCHAR)
            {
                return;
            }

            // Message thrown by another MP2-Client instance -> Bring current instance to front
            if (m.Msg == SingleInstanceHelper.SHOW_MP2_CLIENT_MESSAGE)
            {
                ServiceRegistration.Get <ILogger>().Info("SkinEngine MainForm: Another instance of MP2-Client.exe tried to start. Bring current instance to front.");
                // Restore if minimized
                Restore();
                // Set active window
                this.SafeActivate();
                CheckTopMost();
                return;
            }

            // Handle display changes. There are different cases which lead to this message:
            // 1. When changing the screen resolution, wanted or unwanted (i.e. some graphic cards reset to 1024x768 during resume from standby)
            // 2. When the refresh rate is changed, but other parameters remain the same (i.e. can happen by RefreshRateChanger plugin)
            // In 1st case we need to reset the DX device, in 2nd this leads to interuption of workflow and is not required.
            if (m.Msg == WM_DISPLAYCHANGE)
            {
                int bitDepth     = m.WParam.ToInt32();
                int screenWidth  = m.LParam.ToInt32() & 0xFFFF;
                int screenHeight = m.LParam.ToInt32() >> 16;
                if (bitDepth != _screenBpp || screenWidth != _screenSize.Width || screenWidth != _screenSize.Width)
                {
                    _screenSize = new Size(screenWidth, screenHeight);
                    _screenBpp  = bitDepth;

                    ServiceRegistration.Get <ILogger>().Info("SkinEngine MainForm: Display changed to {0}x{1}@{2}.", screenWidth, screenHeight, bitDepth);
                    SetScreenSize(System.Windows.Forms.Screen.FromControl(this));
                    AdaptToSize(); // Also recreates the DX device
                }
                else
                {
                    ServiceRegistration.Get <ILogger>().Info("SkinEngine MainForm: Display changed refresh rate, size remained {0}x{1}@{2}.", screenWidth, screenHeight, bitDepth);
                }
            }

            // Albert, 2010-03-13: The following code can be used to make the window always maintain a fixed aspect ratio.
            // It was commented out because it doesn't really help. At least in the fullscreen mode, the aspect ratio is determined
            // by the screen and not by any other desired aspect ratio. I think we should not use the code, that's why I comment
            // it out.
            // When it should be used, the field _fixed_aspect_ratio must be initialized with a sensible value, for example
            // the aspect ratio from the skin.
            if (m.Msg == WM_SIZING && m.HWnd == Handle)
            {
                if (WindowState == FormWindowState.Normal)
                {
                    var  fixedAspectRatio = SkinContext.SkinResources.SkinHeight / (float)SkinContext.SkinResources.SkinWidth;
                    Rect r = (Rect)Marshal.PtrToStructure(m.LParam, typeof(Rect));

                    // Calc the border offset
                    Size offset = new Size(Width - ClientSize.Width, Height - ClientSize.Height);

                    // Calc the new dimensions.
                    float wid = r.Right - r.Left - offset.Width;
                    float hgt = r.Bottom - r.Top - offset.Height;
                    // Calc the new aspect ratio.
                    float newAspectRatio = hgt / wid;

                    // See if the aspect ratio is changing.
                    if (fixedAspectRatio != newAspectRatio)
                    {
                        Int32 dragBorder = m.WParam.ToInt32();
                        // To decide which dimension we should preserve,
                        // see what border the user is dragging.
                        if (dragBorder == WMSZ_TOPLEFT || dragBorder == WMSZ_TOPRIGHT ||
                            dragBorder == WMSZ_BOTTOMLEFT || dragBorder == WMSZ_BOTTOMRIGHT)
                        {
                            // The user is dragging a corner.
                            // Preserve the bigger dimension.
                            if (newAspectRatio > fixedAspectRatio)
                            {
                                // It's too tall and thin. Make it wider.
                                wid = hgt / fixedAspectRatio;
                            }
                            else
                            {
                                // It's too short and wide. Make it taller.
                                hgt = wid * fixedAspectRatio;
                            }
                        }
                        else if (dragBorder == WMSZ_LEFT || dragBorder == WMSZ_RIGHT)
                        {
                            // The user is dragging a side.
                            // Preserve the width.
                            hgt = wid * fixedAspectRatio;
                        }
                        else if (dragBorder == WMSZ_TOP || dragBorder == WMSZ_BOTTOM)
                        {
                            // The user is dragging the top or bottom.
                            // Preserve the height.
                            wid = hgt / fixedAspectRatio;
                        }
                        // Figure out whether to reset the top/bottom
                        // and left/right.
                        // See if the user is dragging the top edge.
                        if (dragBorder == WMSZ_TOP || dragBorder == WMSZ_TOPLEFT ||
                            dragBorder == WMSZ_TOPRIGHT)
                        {
                            // Reset the top.
                            r.Top = r.Bottom - (int)(hgt + offset.Height);
                        }
                        else
                        {
                            // Reset the bottom.
                            r.Bottom = r.Top + (int)(hgt + offset.Height);
                        }
                        // See if the user is dragging the left edge.
                        if (dragBorder == WMSZ_LEFT || dragBorder == WMSZ_TOPLEFT ||
                            dragBorder == WMSZ_BOTTOMLEFT)
                        {
                            // Reset the left.
                            r.Left = r.Right - (int)(wid + offset.Width);
                        }
                        else
                        {
                            // Reset the right.
                            r.Right = r.Left + (int)(wid + offset.Width);
                        }
                        // Update the Message object's LParam field.
                        Marshal.StructureToPtr(r, m.LParam, true);
                    }
                }
            }
            // Send windows message through the system if any component needs to access windows messages
            WindowsMessaging.BroadcastWindowsMessage(ref m);
            base.WndProc(ref m);
        }