Print Page | Close Window

RibbonBar Systembutton

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=16307
Printed Date: 18 September 2025 at 4:41am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: RibbonBar Systembutton
Posted By: moe188
Subject: RibbonBar Systembutton
Date Posted: 27 February 2010 at 4:32pm
Hello,
I am adding a RibbonBar SystemButton to my form, but without any submenu, and I want the form to close once the user clicks the SystemButton. How can I do this?
Thank you


-------------
Visual Baisc 6 SP6

Windows XP Pro Sp3, Windows 7
Codejock Xtreme SuitePro ActiveX 15.1.3



Replies:
Posted By: jpbro
Date Posted: 27 February 2010 at 9:14pm
This turns out to be a bit trickier than you might expect for a couple of reasons:

1) Clicking the System Button doesn't fire the Execute event, so you can't test for it there.
2) You can test for the System Button in the InitCommandsPopup event, but if you call Unload Me in that event then the IDE (and likely compiled EXE) will crash.

Fortunately, you can safely use the PostMessage API with WM_CLOSE on the form hWnd to close the window in the InitCommandsPopup event. The following code works in my limited testing (assuming a form with a command bars control named CommandBars1):


Option Explicit

Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE As Long = &H10

Private mo_SysBtn As CommandBarControl ' Reference to the System Button control

Private Sub CommandBars1_InitCommandsPopup(ByVal CommandBar As XtremeCommandBars.ICommandBar)
   If CommandBar Is mo_SysBtn.CommandBar Then
      ' The system button is about to show its popup
      ' This should mean that it was clicked.
     
      PostMessage Me.hwnd, WM_CLOSE, 0, 0 ' Unload Me will crash the IDE! PostMessage is the safe way to close the app in the InitCommandsPopup
   End If
End Sub

Private Sub Form_Load()
   With Me.CommandBars1
      .EnableOffice2007Frame True
      .VisualTheme = xtpThemeRibbon
  
      With .AddRibbonBar("Ribbon")
         ' Create system button, and store a reference
         Set mo_SysBtn = .AddSystemButton
        
         .EnableFrameTheme
      End With
   End With
End Sub



-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: moe188
Date Posted: 28 February 2010 at 6:10pm
Thank you it works fine

-------------
Visual Baisc 6 SP6

Windows XP Pro Sp3, Windows 7
Codejock Xtreme SuitePro ActiveX 15.1.3



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net