See a working example. Please notice how oControl is retrieved from RibbonBarEvent():
- Code: Select all Expand view
#include "FiveWin.ch"
#define xtpControlButton 1
#define xtpFlagRightAlign 1
#define ID_ADDTAB 10
#define ID_ADDGROUP 20
#define ID_ADDBUTTON 30
static oRb
function Main()
local oWnd, oAct, oMenu, oTabs, oGroups, oControls
DEFINE WINDOW oWnd TITLE "Visual RibbonBar"
@ 0, 0 ACTIVEX oAct PROGID "Codejock.CommandBarsFrame.12.1.1" OF oWnd SIZE 0, 0
oAct:bOnEvent = { | cEvent, aParams | RibbonBarEvent( cEvent, aParams ) }
oAct:Do( "AttachToWindow", oWnd:hWnd )
oRb = oAct:Do( "AddRibbonBar", "fwh" )
oMenu = oRb:Controls:Add( 2, 0, "Menu" )
oMenu:Flags = xtpFlagRightAlign
oTabs = oMenu:CommandBar:Controls:Add( 2, 0, "Tabs" )
oTabs:CommandBar:Controls:Add( 1, ID_ADDTAB, "Add" )
oGroups = oMenu:CommandBar:Controls:Add( 3, 0, "Groups" )
oGroups:CommandBar:Controls:Add( 1, ID_ADDGROUP, "Add" )
oControls = oMenu:CommandBar:Controls:Add( 3, 0, "Controls" )
oControls:CommandBar:Controls:Add( 1, ID_ADDBUTTON, "Add Button" )
ACTIVATE WINDOW oWnd
return nil
function RibbonBarEvent( cEvent, aParams )
local oControl, oTab, oGroup, oItem
do case
case cEvent == "Execute"
oControl = aParams[ 1 ]
do case
case oControl:Id == ID_ADDTAB
oControl = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) )
oControl:Id = oRb:TabCount
oControl:Selected = .T.
case oControl:Id == ID_ADDGROUP
if oRb:TabCount > 0
oGroup = oRb:SelectedTab:Groups:AddGroup( "Group " + AllTrim( Str( oRb:SelectedTab:Groups:GroupCount + 1 ) ),;
( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount + 1 )
endif
case oControl:Id == ID_ADDBUTTON
if oRb:SelectedTab:Groups:GroupCount > 0
oGroup = oRb:FindGroup( ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount )
oItem = oGroup:Add( xtpControlButton, 1, nil )
oItem:Caption = "Button " + AllTrim( Str( oGroup:Count ) )
endif
otherwise
if ! Empty( oControl:Caption )
MsgInfo( oControl:Caption )
endif
endcase
endcase
return nil