private void AddCustomCaption() { // Setup tray button CustomCaptionButton customButton = new CustomCaptionButton(); customButton.Key = "TrayButton"; customButton.Click += new EventHandler(trayButton_Click); CaptionButtons.Add(customButton); }
private void CreateCaptionButtons() { m_captionButtons.Clear(); m_showIcon = false; m_iconRect = Rectangle.Empty; FormBorderStyle bstyle = m_form.FormBorderStyle; if (bstyle == FormBorderStyle.None || m_form.ControlBox == false) { return; } m_showIcon = !(m_form.ControlBox == false || m_form.ShowIcon == false || bstyle == FormBorderStyle.FixedToolWindow || bstyle == FormBorderStyle.SizableToolWindow || bstyle == FormBorderStyle.FixedDialog); CustomCaptionButton closebtn = new CustomCaptionButton(HitTest.HTCLOSE); m_captionButtons.Add(closebtn); bool toolWindow = m_form.FormBorderStyle == FormBorderStyle.FixedToolWindow || m_form.FormBorderStyle == FormBorderStyle.SizableToolWindow; if (!toolWindow) { if (m_form.MaximizeBox) { m_captionButtons.Add(new CustomCaptionButton(HitTest.HTMAXBUTTON)); } if (m_form.MinimizeBox) { m_captionButtons.Add(new CustomCaptionButton(HitTest.HTMINBUTTON)); } } UpdateBounds(); UpdateCaptionButtons(); }
private void SetHoverState(CustomCaptionButton btn) { bool repaint = false; foreach (var button in m_captionButtons) { if (button == btn) { repaint |= !btn.MouseIn; btn.MouseIn = true; } else { repaint |= button.MouseIn; button.MouseIn = false; } } if (repaint) { PaintTitleBar(m_active); } }
private void DrawButton(CustomCaptionButton button) { if (IsHandleCreated) { // MSDN states that only WINDOW and INTERSECTRGN are needed, // but other sources confirm that CACHE is required on Win9x // and you need CLIPSIBLINGS to prevent painting on overlapping windows. IntPtr hDC = NativeMethods.GetDCEx(this.Handle, (IntPtr)1, (int)(NativeMethods.DCX.DCX_WINDOW | NativeMethods.DCX.DCX_INTERSECTRGN | NativeMethods.DCX.DCX_CACHE | NativeMethods.DCX.DCX_CLIPSIBLINGS)); if (hDC == IntPtr.Zero) hDC = NativeMethods.GetWindowDC(this.Handle); if (hDC != IntPtr.Zero) { using (Graphics g = Graphics.FromHdc(hDC)) { button.DrawButton(g, true, this.TitleBackgroundColor); } } NativeMethods.ReleaseDC(this.Handle, hDC); } }
/// <summary> /// This method handles depressing the titlebar button. It captures the mouse and creates a message loop /// filtring only the mouse buttons until a WM_MOUSEMOVE or WM_LBUTTONUP message is received. /// </summary> /// <param name="currentButton">The button that was pressed</param> /// <returns>true if WM_LBUTTONUP occured over this button; false when mouse was moved away from this button.</returns> private bool DepressButton(CustomCaptionButton currentButton) { try { // callect all mouse events (should do the same as SetCapture()) this.Capture = true; // draw button in pressed mode currentButton.State = CaptionButtonState.Pressed; DrawButton(currentButton); // loop until button is released bool result = false; bool done = false; while (!done) { // NOTE: This struct needs to be here. We had strange error (starting from Beta 2). // when this was defined at begining of this method. also check if types are correct (no overlap). Message m = new Message(); if (NativeMethods.PeekMessage(ref m, IntPtr.Zero, (int)NativeMethods.WindowMessages.WM_MOUSEFIRST, (int)NativeMethods.WindowMessages.WM_MOUSELAST, (int)NativeMethods.PeekMessageOptions.PM_REMOVE)) { Log(MethodInfo.GetCurrentMethod(), "Message = {0}, Button = {1}", (NativeMethods.WindowMessages)m.Msg, currentButton); switch (m.Msg) { case (int)NativeMethods.WindowMessages.WM_LBUTTONUP: { if (currentButton.State == CaptionButtonState.Pressed) { currentButton.State = CaptionButtonState.Normal; DrawButton(currentButton); } Point pt = PointToWindow(PointToScreen(new Point(m.LParam.ToInt32()))); Log(MethodInfo.GetCurrentMethod(), "### Point = ({0}, {1})", pt.X, pt.Y); result = currentButton.Bounds.Contains(pt); done = true; } break; case (int)NativeMethods.WindowMessages.WM_MOUSEMOVE: { Point clientPoint = PointToWindow(PointToScreen(new Point(m.LParam.ToInt32()))); if (currentButton.Bounds.Contains(clientPoint)) { if (currentButton.State == CaptionButtonState.Normal) { currentButton.State = CaptionButtonState.Pressed; DrawButton(currentButton); } } else { if (currentButton.State == CaptionButtonState.Pressed) { currentButton.State = CaptionButtonState.Normal; DrawButton(currentButton); } } // [1531]: These variables need to be reset here although thay aren't changed // before reaching this point result = false; done = false; } break; } } } return result; } finally { this.Capture = false; } }
private void InitSystemButtons() { _closeButton = new CustomCaptionButton(); _closeButton.Key = CaptionButtonKey.Close; _closeButton.Visible = true; _closeButton.HitTestCode = (int)NativeMethods.NCHITTEST.HTCLOSE; _closeButton.SystemCommand = (int)NativeMethods.SystemCommands.SC_CLOSE; _captionButtons.Add(_closeButton); _restoreButton = new CustomCaptionButton(); _restoreButton.Key = CaptionButtonKey.Restore; _restoreButton.Enabled = this.MaximizeBox; _restoreButton.HitTestCode = (int)NativeMethods.NCHITTEST.HTMAXBUTTON; _restoreButton.SystemCommand = (int)NativeMethods.SystemCommands.SC_RESTORE; _captionButtons.Add(_restoreButton); _maximizeButton = new CustomCaptionButton(); _maximizeButton.Key = CaptionButtonKey.Maximize; _maximizeButton.Enabled = this.MaximizeBox; _maximizeButton.HitTestCode = (int)NativeMethods.NCHITTEST.HTMAXBUTTON; _maximizeButton.SystemCommand = (int)NativeMethods.SystemCommands.SC_MAXIMIZE; _captionButtons.Add(_maximizeButton); _minimizeButton = new CustomCaptionButton(); _minimizeButton.Key = CaptionButtonKey.Minimize; _minimizeButton.Enabled = this.MinimizeBox; _minimizeButton.HitTestCode = (int)NativeMethods.NCHITTEST.HTMINBUTTON; _minimizeButton.SystemCommand = (int)NativeMethods.SystemCommands.SC_MINIMIZE; _captionButtons.Add(_minimizeButton); _helpButton = new CustomCaptionButton(); _helpButton.Key = CaptionButtonKey.Help; _helpButton.Visible = this.HelpButton; _helpButton.HitTestCode = (int)NativeMethods.NCHITTEST.HTHELP; _helpButton.SystemCommand = (int)NativeMethods.SystemCommands.SC_CONTEXTHELP; _captionButtons.Add(_helpButton); _settingsButton = new CustomCaptionButton(); _settingsButton.Key = CaptionButtonKey.Settings; _settingsButton.Visible = true; _settingsButton.HitTestCode = (int)NativeMethods.NCHITTEST.HTOBJECT; _settingsButton.SystemCommand = (int)-1; _captionButtons.Add(_settingsButton); _aboutButton = new CustomCaptionButton(); _aboutButton.Key = CaptionButtonKey.About; _aboutButton.Visible = true; _aboutButton.HitTestCode = (int)NativeMethods.NCHITTEST.HTHELP; _aboutButton.SystemCommand = (int)-1; _captionButtons.Add(_aboutButton); OnUpdateWindowState(); }
private void CreateCaptionButtons() { m_captionButtons.Clear(); m_showIcon = false; m_iconRect = Rectangle.Empty; FormBorderStyle bstyle = m_form.FormBorderStyle; if (bstyle == FormBorderStyle.None || m_form.ControlBox == false) return; m_showIcon = !(m_form.ControlBox == false || m_form.ShowIcon == false || bstyle == FormBorderStyle.FixedToolWindow || bstyle == FormBorderStyle.SizableToolWindow || bstyle == FormBorderStyle.FixedDialog); CustomCaptionButton closebtn = new CustomCaptionButton(HitTest.HTCLOSE); m_captionButtons.Add(closebtn); bool toolWindow = m_form.FormBorderStyle == FormBorderStyle.FixedToolWindow || m_form.FormBorderStyle == FormBorderStyle.SizableToolWindow; if (!toolWindow) { if (m_form.MaximizeBox) m_captionButtons.Add(new CustomCaptionButton(HitTest.HTMAXBUTTON)); if (m_form.MinimizeBox) m_captionButtons.Add(new CustomCaptionButton(HitTest.HTMINBUTTON)); } }