Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - RibbonBar Systembutton
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

RibbonBar Systembutton

 Post Reply Post Reply
Author
Message
moe188 View Drop Down
Senior Member
Senior Member


Joined: 27 March 2006
Status: Offline
Points: 220
Post Options Post Options   Thanks (0) Thanks(0)   Quote moe188 Quote  Post ReplyReply Direct Link To This Post Topic: RibbonBar Systembutton
    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
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
moe188 View Drop Down
Senior Member
Senior Member


Joined: 27 March 2006
Status: Offline
Points: 220
Post Options Post Options   Thanks (0) Thanks(0)   Quote moe188 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.125 seconds.