Page 6 of 8

Re: Codejock RibbonBar first tests

Posted: Fri Apr 03, 2009 2:15 pm
by richard-service
Hi Antonio,

I post my last paste picture below source code.

Thanks post my code.

Regards,

Richard

Re: Codejock RibbonBar first tests

Posted: Fri Apr 03, 2009 2:17 pm
by Antonio Linares
Richard,

Ok, thanks :-)

Re: Codejock RibbonBar first tests

Posted: Fri Apr 03, 2009 3:11 pm
by Antonio Linares
A very early Visual RibbonBar designer prototype. The idea is to interactively desing the RibbonBar and than its source code could be automatically generated:

RibonBar.prg

Code: Select all

#include "FiveWin.ch"

static oRb

function Main()

   local oWnd, oAct, oMenu, aControls := {}

   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, pParams | RibbonBarEvent( cEvent, aParams, pParams, aControls ) }

   oAct:Do( "AttachToWindow", oWnd:hWnd )

   oRb = oAct:Do( "AddRibbonBar", "fwh" )

   oMenu = oRb:Controls:Add( 2, 0, "Menu" )
   oMenu:Flags = 1  && xtpFlagRightAlign

   oTabs = oMenu:CommandBar:Controls:Add( 2, 0, "Tabs" )
   AAdd( aControls, oTabs:CommandBar:Controls:Add( 1, 3000, "Add" ) )

   oGroups = oMenu:CommandBar:Controls:Add( 3, 0, "Groups" )
   AAdd( aControls, oGroups:CommandBar:Controls:Add( 1, 4000, "Add" ) )

   ACTIVATE WINDOW oWnd

return nil

function RibbonBarEvent( cEvent, aParams, pParams, aControls )

   local oTab 

   static nTab := 1, nGroup := 1

   do case
      case cEvent == "Execute" .and. Len( aControls ) > 0
           do case
              case aControls[ 1 ]:hObj == aParams[ 1 ]
                   oTab = oRb:InsertTab( nTab, "Tab " + AllTrim( Str( nTab++ ) ) )
                   oTab:Selected = .T.

              case aControls[ 2 ]:hObj == aParams[ 1 ]
                   MsgInfo( "Insert Group" )

           endcase
   endcase
   
return nil             
 
Image

Re: Codejock RibbonBar first tests

Posted: Fri Apr 03, 2009 5:52 pm
by Antonio Linares
Visual RibbonBar: Dynamically adding tabs and groups

RibbonBar.prg

Code: Select all

#include "FiveWin.ch"

static oRb

function Main()

   local oWnd, oAct, oMenu, aControls := {}

   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, pParams | RibbonBarEvent( cEvent, aParams, pParams, aControls ) }

   oAct:Do( "AttachToWindow", oWnd:hWnd )

   oRb = oAct:Do( "AddRibbonBar", "fwh" )

   oMenu = oRb:Controls:Add( 2, 0, "Menu" )
   oMenu:Flags = 1  && xtpFlagRightAlign

   oTabs = oMenu:CommandBar:Controls:Add( 2, 0, "Tabs" )
   AAdd( aControls, oTabs:CommandBar:Controls:Add( 1, 3000, "Add" ) )

   oGroups = oMenu:CommandBar:Controls:Add( 3, 0, "Groups" )
   AAdd( aControls, oGroups:CommandBar:Controls:Add( 1, 4000, "Add" ) )

   ACTIVATE WINDOW oWnd

return nil

function RibbonBarEvent( cEvent, aParams, pParams, aControls )

   local oTab 

   do case
      case cEvent == "Execute" .and. Len( aControls ) > 0
           do case
              case aControls[ 1 ]:hObj == aParams[ 1 ]
                   oTab = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) )
                   oTab:Selected = .T.

              case aControls[ 2 ]:hObj == aParams[ 1 ]
                   if oRb:TabCount > 0
                      oRb:SelectedTab:Groups:AddGroup( "&Group", Len( oRb:SelectedTab:Groups ) + 1 )
                   endif 

           endcase
   endcase
   
return nil             
 

Re: Codejock RibbonBar first tests

Posted: Fri Apr 03, 2009 7:15 pm
by Antonio Linares
Visual RibbonBar: enhanced version

RibbonBar.prg

Code: Select all

#include "FiveWin.ch"

static oRb

function Main()

   local oWnd, oAct, oMenu, aControls := {}

   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, pParams | RibbonBarEvent( cEvent, aParams, pParams, aControls ) }

   oAct:Do( "AttachToWindow", oWnd:hWnd )

   oRb = oAct:Do( "AddRibbonBar", "fwh" )

   oMenu = oRb:Controls:Add( 2, 0, "Menu" )
   oMenu:Flags = 1  && xtpFlagRightAlign

   oTabs = oMenu:CommandBar:Controls:Add( 2, 0, "Tabs" )
   AAdd( aControls, oTabs:CommandBar:Controls:Add( 1, 3000, "Add" ) )

   oGroups = oMenu:CommandBar:Controls:Add( 3, 0, "Groups" )
   AAdd( aControls, oGroups:CommandBar:Controls:Add( 1, 4000, "Add" ) )

   ACTIVATE WINDOW oWnd

return nil

function RibbonBarEvent( cEvent, aParams, pParams, aControls )

   local oTab 

   do case
      case cEvent == "Execute" .and. Len( aControls ) > 0
           do case
              case aControls[ 1 ]:hObj == aParams[ 1 ]
                   oTab = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) )
                   oTab:Selected = .T.

              case aControls[ 2 ]:hObj == aParams[ 1 ]
                   if oRb:TabCount > 0
                      oRb:SelectedTab:Groups:AddGroup( "Group " + AllTrim( Str( oRb:SelectedTab:Groups:GroupCount + 1 ) ),;
                                                       oRb:SelectedTab:Groups:GroupCount + 1 )
                   endif   

           endcase
   endcase
   
return nil             
 

Re: Codejock RibbonBar first tests

Posted: Sat Apr 04, 2009 1:32 am
by Antonio Linares
Visual RibbonBar: adding controls (buttons), developed together with Daniel :-)

RibonBar.prg

Code: Select all

#include "FiveWin.ch"

#define xtpControlButton     1

static oRb

function Main()

   local oWnd, oAct, oMenu, oGroups, oControls, aControls := {}

   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, pParams | RibbonBarEvent( cEvent, aParams, pParams, aControls ) }

   oAct:Do( "AttachToWindow", oWnd:hWnd )

   oRb = oAct:Do( "AddRibbonBar", "fwh" )

   oMenu = oRb:Controls:Add( 2, 0, "Menu" )
   oMenu:Flags = 1  && xtpFlagRightAlign

   oTabs = oMenu:CommandBar:Controls:Add( 2, 0, "Tabs" )
   AAdd( aControls, oTabs:CommandBar:Controls:Add( 1, 3000, "Add" ) )

   oGroups = oMenu:CommandBar:Controls:Add( 3, 0, "Groups" )
   AAdd( aControls, oGroups:CommandBar:Controls:Add( 1, 4000, "Add" ) )

   oControls = oMenu:CommandBar:Controls:Add( 3, 0, "Controls" )
   AAdd( aControls, oControls:CommandBar:Controls:Add( 1, 5000, "Add Button" ) )

   ACTIVATE WINDOW oWnd

return nil

function RibbonBarEvent( cEvent, aParams, pParams, aControls )

   local oTab, oGroup, oControl 

   do case
      case cEvent == "Execute" .and. Len( aControls ) > 0
           do case
              case aControls[ 1 ]:hObj == aParams[ 1 ]
                   oTab = oRb:InsertTab( oRb:TabCount + 1, "Tab " + AllTrim( Str( oRb:TabCount + 1 ) ) )
                   oTab:Id = oRb:TabCount
                   oTab:Selected = .T.

              case aControls[ 2 ]:hObj == aParams[ 1 ]
                   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 aControls[ 3 ]:hObj == aParams[ 1 ]
                   if oRb:SelectedTab:Groups:GroupCount > 0
                      oGroup = oRb:FindGroup( ( oRb:SelectedTab:Index * 10 ) + oRb:SelectedTab:Groups:GroupCount )
                      oControl = oGroup:Add( xtpControlButton, 1, nil )
                      oControl:Caption = "Button " + AllTrim( Str( oGroup:Count ) )
                   endif   

           endcase
   endcase
   
return nil             
 
Image

Re: Codejock RibbonBar first tests

Posted: Sat Apr 04, 2009 7:42 am
by anserkk
Hi ,

Anybody here tried to run the generated Sample Exe on a PC other than the Development PC (ie On a PC where the CodeJock Setup is not installed).

For me it is giving the following error.
Image

Regards

Anser

Re: Codejock RibbonBar first tests

Posted: Sat Apr 04, 2009 8:33 am
by Antonio Linares
Anser,

I think that first you have to register the ActiveX as an administrator. But not 100% sure about it.

Also, you can check if the ActiveX is available before using it:

Code: Select all

if ! IsActiveX( "Codejock.CommandBars.v13.0.0.ocx" )
   MsgStop( "ActiveX missing" )
   return nil
endif
 

Re: Codejock RibbonBar first tests

Posted: Sat Apr 04, 2009 9:26 am
by anserkk
Dear Mr.Antonio,
I think that first you have to register the ActiveX as an administrator. But not 100% sure about it.
I am testing the problem in Win XP as Administrator.

Another Problem which I have seen is that IsActivex() is always returning .F.

Code: Select all

If IsActivex("Codejock.CommandBars.v12.1.1.ocx")
    MsgInfo("Activex is already Registerd")
else // If not registered then Display the msg and REgister the OCX
    MSgInfo("Activex is NOT Registerd, Now it will Register")  // This line is getting executed
    RegisterServer( "Codejock.CommandBars.v12.1.1.ocx" ) 
Endif

// After REsgisterServer, IsActivex() should return .T., but it is returning .F.
If IsActivex("Codejock.CommandBars.v12.1.1.ocx")
    MSgInfo("Activex is Successful")
else
    MSgInfo("Unable to register the Activex") // This line is getting executed
endif

 
The OCX contorl and my Test.Exe is available in the Same folder

To re-check, I manually registered the OCX Control and run the Test.Exe again, but the fuction IsActivex() is always returning .F.

I can't understand where I have gone wrong ?

Regards

Anser

Re: Codejock RibbonBar first tests

Posted: Sat Apr 04, 2009 2:50 pm
by Antonio Linares
Anser,

Please call this function CoInitialize() before calling IsActiveX( cProgId ):

Code: Select all

#pragma BEGINDUMP

#include <hbapi.h>

unsigned long CoInitialize( void * );

HB_FUNC( COINITIALIZE )
{
   hb_retnl( CoInitialize( NULL ) );
}

#pragma ENDDUMP
 

Re: Codejock RibbonBar first tests

Posted: Sat Apr 04, 2009 8:02 pm
by frose
Anser,

perhaps you have the same problem on some machines as I, so here my solution:

What happens: By executing the method 'AttachToWindow', the RibbonBar begins to fire events, so the code block 'RibbonBarEvent' will be executed and failed 'in the line 'case cEvent == "Execute"' with the error '==' because <cEvent> is numerical!

Solution: Put in the following code:

Code: Select all

function RibbonBarEvent( cEvent, aParams, pParams, aButtons, oWnd )

    IF Valtype( cEvent ) == "N"
       DO CASE
          CASE cEvent == 1
            cEvent := "Execute"
          OTHERWISE
            cEvent := ""
       ENDCASE
   ENDIF
 
HTH

Re: Codejock RibbonBar first tests

Posted: Sat Apr 04, 2009 9:09 pm
by frose
Fafi,

you can assign a code block to <oact:bOnEvent>. When an event in the RibbonBar occurs, this code block will be executed. If a button was clicked by the user, the variable <cEvent> has 'normally' the value "Execute". All buttons resides in the array <aButtons>, if 'aButtons[ 1 ]:hObj == aParams[ 1 ]' you know which button was pressed!

I really want to know, how Lailton, Richard, or who else has discovered this know how, compliments to them. Perhaps I have to read the Codejack help file more systematically :wink:

BTW, sometimes <cEvent> is numerical, if so on your machine, the code crashes the first time (after 'AttachToWindow') your code block is executed!

Re: Codejock RibbonBar first tests

Posted: Sat Apr 04, 2009 9:18 pm
by Antonio Linares
Frank,

> I really want to know, how Lailton, Richard, or who else has discovered this know how

You can inspect all properties, methods and events from Microsoft Word VBA:

http://forums.fivetechsupport.com/viewt ... 087#p78087

Re: Codejock RibbonBar first tests

Posted: Mon Apr 06, 2009 6:22 am
by anserkk
Dear Mr. Frank,

I tried your solution but did not work. My app is crashing when it reaches the point

Code: Select all

oAct := TActiveX():New( oWnd, "Codejock.CommandBarsFrame.12.1.1", 0, 0, 0, 0 )  
I tried to check the ValType of cEvent, but the application crashes before reaching that point

Code: Select all

Function RibbonBarEvent( cEvent, aParams, pParams, aButtons )
MsgInfo(ValType(cEvent))
Dear Mr.Antonio,

As suggested by you I tried CoInitialize() before calling IsActiveX( cProgId ) but still IsActivex() is always returning .F.

I tried a utility named RegDllView, to check whether the OCX is registered, and it shows that the OCX is regsitered in the system. I am using Windows XP SP3

I tested this in 2 other Win XP Pc's and 1 Windows 7 PC.

I even doubt the licence issue as said in this thread http://forums.fivetechsupport.com/viewt ... =3&t=13351
I am looking for a code to pass the licence key when the contols are used in Client PC (when we use the control on a PC where the CodeJock setup.exe is not installed). In the write up it is said that the valid license key should be used on Form Initialiase using the property GlobalSetting:Licence of the CodeJock Control, but the app is crashing before I can access the Property's of the Control at TActivex initialize itself

Thanks & REgards

Anser

Re: Codejock RibbonBar first tests

Posted: Mon Apr 06, 2009 7:10 am
by Antonio Linares
Anser,

Are you using 12.1.1 or 13.0.0 ?

Have you tried both ?