Página 1 de 1

Botão com lista de opções na toolbar... (resolvido)

Enviado: 22 Out 2007 08:50
por FARLEY RIBEIRO
Olá galera,

Utilizo uma toolbar e gostaria de criar uma opção de botão com as opções... vejam a imagem abaixo como exemplo.

DEFINE BUTTONBAR oBar SIZE 44, 37 OF oWnd _3D
DEFINE BUTTON OF oBar TOOLTIP "Calculadora" NOBORDER RESOURCE "#8003" ACTION WinExec("CALC.EXE")
DEFINE BUTTON OF oBar TOOLTIP "Muda Operador" NOBORDER RESOURCE "#8005" ACTION fMenuCad() // menu com opções...

Imagem

Desde já agradeço.

abraços

farley

fw2.6/xhb09950/Pelles/MyMake/Med
farleyribeiro@bol.com.br

Enviado: 23 Out 2007 03:09
por rochinha
Amiguinho

Na minha versão de 5Win este recurso não era possivel, então fiz algumas alterações na classe ToolBar.prg para permitir um menu.

Código: Selecionar todos

#xcommand DEFINE TBBUTTON ;
             [ OF <oToolBar> ] ;
             [ ACTION <uAction> ] ;
             [ TOOLTIP <cToolTip> ] ;
             [ PROMPT <cPrompt> ] ;
             [ WHEN <uWhen> ] ;
             [ MESSAGE <cMsg> ] ;
             [ MENU <oPopup> ] ; //********************* KONECTIVA AUTOMACAO
       => ;
          <oToolBar>:AddButton( [<{uAction}>], [<cToolTip>], [<cPrompt>],;
                                [<{uWhen}>], [<cMsg>], [<oPopup>] )      
...
MENU oMenuBar11 POPUP
         MENUITEM "&Ordem de producao"    ACTION pn( oWnd, .f., oBar, 'P' )
         MENUITEM "&Gerencia de produtos" ACTION produtos( oWnd, .f., oBar, 'P' )
         SEPARATOR
         MENUITEM "&Gerencia de Corte"    ACTION corte( oWnd, .f., oBar )
ENDMENU                                           
...
DEFINE TBBUTTON OF oToolBar ACTION fun() ;
                             TOOLTIP "Producao e Custos..." ;
                             PROMPT  "&Producao" MENU oMenuBar11
Classe ToolBar.prg modificada para versão 2.7

Código: Selecionar todos

// Win32 common controls ToolBar

#include "FiveWin.ch"

#define CCS_NORESIZE              4
#define CCS_NODIVIDER            64 // 0x0040
#define CCS_LEFT                129 // 0x0081
#define TBSTYLE_TRANSPARENT   32768 // 0x8000
#define TBSTYLE_FLAT           2048 // 0x0800
#define TBSTYLE_TOOLTIPS        256 // 0x0100

#define TB_CHECKBUTTON         1026
#define TB_ISBUTTONCHECKED     1034
#define TB_SETSTATE            1041
#define TB_AUTOSIZE            1057
#define TB_CHANGEBITMAP        1067
#define TB_SETIMAGELIST        1072
#define TB_SETSTYLE            1080
#define TB_GETSTYLE            1081
#define TB_SETMAXTEXTROWS      1084

#define TBSTATE_CHECKED           1
#define TBSTATE_PRESSED           2 
#define TBSTATE_ENABLED           4

#define TTN_GETDISPINFO        -530
#define TTS_BALLOON              64 // 0x0040
#define WM_ERASEBKGND            20
#define GWL_STYLE               -16

//----------------------------------------------------------------------------//

CLASS TToolBar FROM TControl

   DATA   nBtnWidth, nBtnHeight
   DATA   aButtons
   DATA   oImageList
   DATA   lTTBalloon

   METHOD New( oWnd, nBtnWidth, nBtnHeight, oImageList, lTTBalloon ) CONSTRUCTOR

   METHOD Create()

   METHOD AddButton( bAction, cToolTip, cText, bWhen, cMsg, ;
          oPopup ) //********************* KONECTIVA AUTOMACAO

   METHOD AddSeparator() INLINE TBAddSeparator( ::hWnd )
   
   METHOD ChangeBitmap( nButton, nImage ) INLINE ;
             SendMessage( ::hWnd, TB_CHANGEBITMAP, nButton, nMakeLong( nImage - 1, 0 ) )

   METHOD Command( nWParam, nLParam )

   #ifndef __C3__
      METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint(), 0
   #endif   
   
   METHOD EnableButton( nButton, lOnOff ) INLINE ;
             TBEnableButton( ::hWnd, nButton, lOnOff )

   #ifndef __C3__
      METHOD EraseBkGnd( hDC ) INLINE 1
   #endif   

   METHOD GotFocus() INLINE 1  // To avoid getting focus!
   
   METHOD RButtonDown() VIRTUAL
   
   METHOD MouseMove() VIRTUAL

   METHOD Notify( nIdCtrl, nPtrNMHDR )

   #ifndef __C3__
      METHOD Paint()
   #endif   

   METHOD SetMessage( nButton, cMsg ) INLINE ;
          ::aButtons[ nButton ][ 3 ] := cMsg

   METHOD SetTooltip( nButton, cToolTip ) INLINE ;
          ::aButtons[ nButton ][ 2 ] := cToolTip 
          
   METHOD SetTextRows( nRows ) INLINE ::SendMsg( TB_SETMAXTEXTROWS, nRows, 0 ),;
                                      ::SendMsg( TB_AUTOSIZE, 0, 0 )

   METHOD SetPressed( nButton, lOnOff ) INLINE ;
          ::SendMsg( TB_SETSTATE, nButton, If( lOnOff, TBSTATE_PRESSED, TBSTATE_ENABLED ) )
          
   METHOD SetChecked( nButton, lOnOff ) INLINE ; 
          If( lOnOff, ::SendMsg( TB_CHECKBUTTON, nButton, TBSTATE_CHECKED ),; 
                      ::SendMsg( TB_SETSTATE, nButton, TBSTATE_ENABLED ) )           

   METHOD IsChecked( nButton ) INLINE ::SendMsg( TB_ISBUTTONCHECKED, nButton ) != 0

   METHOD ToggleCheck( nButton ) INLINE ;
      ::SetCheck( nButton, ! ::IsChecked( nButton ) ), ::IsChecked( nButton )

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( oWnd, nBtnWidth, nBtnHeight, oImageList, lTTBalloon ) CLASS TToolBar

   DEFAULT oWnd := GetWndDefault(), nBtnWidth := 33, nBtnHeight := 33,;
           lTTBalloon := .f.

   ::oWnd = oWnd
   ::nId  = ::GetNewId()
   ::nBtnWidth  = nBtnWidth
   ::nBtnHeight = nBtnHeight
   ::aButtons = {}
   ::oImageList = oImageList
   ::lDrag = .f.
   ::lTTBalloon := lTTBalloon

   if Upper( oWnd:ClassName() ) != "TREBAR"
      oWnd:oTop = Self
   endif

   InitCommonControls()

   if ! Empty( oWnd:hWnd )
      ::Create()
      ::nHeight = nBtnHeight + 3
      oWnd:AddControl( Self )
      if oImageList != nil
         SendMessage( ::hWnd, TB_SETIMAGELIST, 0, oImageList:hImageList )
      endif   
   else
      oWnd:DefControl( Self )
   endif

return Self

//----------------------------------------------------------------------------//

METHOD AddButton( bAction, cToolTip, cText, bWhen, cMsg, ;
                  oPopup ) CLASS TToolBar //********************* KONECTIVA AUTOMACAO

   AAdd( ::aButtons, { bAction, cToolTip, cMsg, ;
                       oPopup } ) //********************* KONECTIVA AUTOMACAO
   
   TBAddButton( ::hWnd, Len( ::aButtons ), Len( ::aButtons ), cText )

   if bWhen != nil .and. ! Eval( bWhen )
      ::EnableButton( Len( ::aButtons ), .f. )
   endif         

return nil

//----------------------------------------------------------------------------//

METHOD Create() CLASS TToolBar

   local nTransStyle := If( ! Upper( ::oWnd:ClassName() ) $ ;
                            "TWINDOW,TMDIFRAME,TMDICHILD", TBSTYLE_TRANSPARENT, 0 )    

   ::hWnd = CreateTlBar( ::oWnd:hWnd, ::nId, ::nBtnWidth, ::nBtnHeight )                          
                             
   if ::hWnd == 0
      WndCreateError( Self )
   else
      SendMessage( ::hWnd, TB_SETSTYLE, 0, nOr( SendMessage( ::hWnd, TB_GETSTYLE ),;
         TBSTYLE_FLAT, nTransStyle, TBSTYLE_TOOLTIPS, CCS_NODIVIDER, CCS_NORESIZE ) )
      ::Link()
   endif

return nil

//----------------------------------------------------------------------------//

METHOD Command( nWParam, nLParam ) CLASS TToolBar

   local nNotifyCode, nID, hWndCtl
   local bAction

   #ifdef __CLIPPER__
      nNotifyCode = nHiWord( nLParam )
      nID         = nWParam
      hWndCtl     = nLoWord( nLParam )
   #else
      nNotifyCode = nHiWord( nWParam )
      nID         = nLoWord( nWParam )
      hWndCtl     = nLParam
   #endif

   if GetClassName( hWndCtl ) == "ToolbarWindow32"
      if ( bAction := ::aButtons[ nID ][ 1 ] ) != nil

         //if len(::aPopup) > 0     //********************* KONECTIVA AUTOMACAO
            if ::aButtons[ nID ][ 4 ] != nil // if len(::aPopup) >= nID
               nTop  := ::nBtnHeight
               nLeft := (::nBtnWidth*(nID-1)) + ((::nBtnWidth/3)*(nID-1))
               ::aButtons[ nID ][ 4 ]:Activate( nTop, nLeft, ::oWnd, .f. )
               ::oWnd:oPopup := nil
            else
               Eval( bAction, Self )
            endif
         //else
         //   Eval( bAction, Self )
         //endif                    //********************* KONECTIVA AUTOMACAO

      endif
   endif   

return nil

//----------------------------------------------------------------------------//

METHOD Notify( nIdCtrl, nPtrNMHDR ) CLASS TToolBar

   local nCode := GetNMHDRCode( nPtrNMHDR ), nId, nHWndFrom, nStyle

   do case
      case nCode == TTN_GETDISPINFO
           nId = GetNMHDRIdFrom( nPtrNMHDR )
           TTNSetText( nPtrNMHDR, ::aButtons[ nId ][ 2 ] )
           if ! Empty( ::aButtons[ nId ][ 3 ] )
              ::SetMsg( ::aButtons[ nId ][ 3 ] )
           else
              ::SetMsg( nil )   
           endif             
           if ::lTTBalloon
              nHWndFrom = GetNMHDRHWndFrom( nPtrNMHDR )
              if ! lAnd( nStyle := GetWindowLong( nHWndFrom, GWL_STYLE ), TTS_BALLOON )
                 SetWindowLong( nHWndFrom, GWL_STYLE, TTS_BALLOON ) 
              endif
           endif   
   endcase

return nil

//----------------------------------------------------------------------------//

#ifndef __C3__
METHOD Paint() CLASS TToolBar

   local aInfo := ::DispBegin()

   if ::oBrush != nil
      FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
   else
      CallWindowProc( ::nOldProc, ::hWnd, WM_ERASEBKGND, ::hDC, 0 )
   endif
   CallWindowProc( ::nOldProc, ::hWnd, WM_PAINT, ::hDC, 0 )

   ::DispEnd( aInfo )

return 1
#endif

Enviado: 23 Out 2007 14:07
por FARLEY RIBEIRO

Código: Selecionar todos

MENU mCadPop POPUP ;
     MENUITEM "Empresas"
     MENUITEM "Grupos"
     MENUITEM "Subgrupos"
ENDMENU

DEFINE BUTTON OF oBar GROUP TOOLTIP "Cadastros"   NOBORDER RESOURCE "#8007" MENU mCadPop

Obrigado Rochinha...
mas a solução acima não precisou alterar a classe toolbar e atendeu perfeitamente...

Espero que sirva de ajuda para todos..

Abraços

farley

Enviado: 24 Out 2007 10:39
por FARLEY RIBEIRO
Aproveitando, como faço para colocar o texto abaixo da imagem...

Atenciosamente

Farley

Enviado: 24 Out 2007 13:39
por rochinha
Amiguinho,

No meu caso eu apenas coloquei PROMPT "Clientes" e o controle colocou-o logo abaixo do icone.

Talvez voce tenha que redefinir o tamanho do controle no comando DEFINE TOOLBAR:

Código: Selecionar todos

          DEFINE TOOLBAR oToolBar OF oWnd SIZE 48, 45 ...

Enviado: 24 Out 2007 14:59
por FARLEY RIBEIRO
Não deu certo Rochinha!!!

Imagem

Utilizo o BUTTON... mais a classe C5MENU para construir o menu...
DEFINE BUTTON OF oBar GROUP TOOLTIP "Cadastros" NOBORDER RESOURCE "#8007" MENU mCadPop // o problema está aqui...

Grato

Farley

Enviado: 24 Out 2007 19:37
por rochinha
Amiguinho

Eu não uso C5, mas te pergunto:

Voce usa C5 para criar o menu da janela ou o menu do botão, pois se voce esta usando a classe ToolBar do Fivewin não vai precisar usar outro recurso.

Em relação ao que vi na imagem, volto a dizer que voce precisa aumentar as dimensões do botão de alguma forma, tanto no comando Toolbar com nos Defines de cada botão.

Verifique e retorne.

Enviado: 25 Out 2007 08:35
por ICO
Tente assim..

DEFINE BUTTON OF oBar GROUP PROMPT "Cadastros" TOOLTIP "Cadastros" NOBORDER RESOURCE "#8007" MENU mCadPop TOP

Enviado: 01 Nov 2007 15:51
por FARLEY RIBEIRO
Obrigado Luiz Arruda pela dica parâmetro TOP...

E consegui ajustar a descrição aumentando o tamanho no BUTTONBAR...
DEFINE BUTTONBAR oBar SIZE 80, 47 OF oWnd _3D

Obrigado a todos pela colaboração..

Abraços

Farley