Toolbar : DropDown Arrow button

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Toolbar : DropDown Arrow button

Post by eddy »

How to create :

Code: Select all

   *TB=CreateToolBar(#TOOLBAR_Main,*MainWindow) 
   LoadImage(#MENU_button,"buttonICO.ico")
   ToolBarImageButton(#MENU_button,ImageID())
   ToolBarDropDownArrow()                      ;before Tooltip init
   ToolBarToolTip(#MENU_button,"button")   

Code: Select all

; ////////////// 
; New ToolBar Procedure & Constants :  
; ////////////// 

#TBN_DROPDOWN=-710 
#TB_GETRECT=$400+51

#TBSTYLE_DROPDOWN=$8   
#TBSTYLE_EX_DRAWDDARROWS=$1
#TB_SETEXTENDEDSTYLE=$400+84
#TB_GETEXTENDEDSTYLE=$400+85
   
Procedure ToolBarDropDownArrow()
   *currentTB=FindWindowEx_(WindowID(), 0, "ToolbarWindow32", 0)

   ;change toolbar exStyle
   exstyle=SendMessage_(*currentTB,#TB_GETEXTENDEDSTYLE,0,0)
   SendMessage_(*currentTB,#TB_SETEXTENDEDSTYLE,0,exstyle | #TBSTYLE_EX_DRAWDDARROWS)
   
   ;change button style
   pos=SendMessage_(*currentTB,#TB_BUTTONCOUNT,0,0)-1
   SendMessage_(*currentTB,#TB_GETBUTTON,pos,button.TBBUTTON)   
   button\fsStyle=button\fsStyle | #TBSTYLE_DROPDOWN
   SendMessage_(*currentTB,#TB_DELETEBUTTON,pos,0)
   SendMessage_(*TB,#TB_INSERTBUTTON,pos+1,button)
EndProcedure
How to use :
You need a callback procedure to detect a click on arrow...

Code: Select all

Procedure WindowCallBack(Window, Message, wParam, lParam)
      If Message = #WM_Notify            

         ; ===============
         ; Toolbar Notification
         ; ===============

         *msgTB.nmToolbar=lParam         

         If *msgTB\hdr\hwndfrom = *TB
            Select *msgTB\hdr\code
               ;bouton pickcolor
               Case #TBN_DROPDOWN ;clicked on arrow !!

                  ;///// Get asbolute position of the button

                  SendMessage_(*TB, #TB_GETRECT, *msgTB\iItem, @rc.RECT)
                  MapWindowPoints_(*TB,0, @rc, 2);          
                               
                  ;///// Display Popup at position

                  DisplayPopupMenu(#MENU_Popup, *MainWindow, rc\left,rc\bottom)

                  ReturnValue = 0
            EndSelect
         EndIf

   ProcedureReturn ReturnValue
EndProcedure 
N.B. : I've not fund any ToolBarID command to retrieve the current TOOLBAR Handle. :?
That's why I use FindWindowEx

Image
Last edited by eddy on Mon Jun 23, 2003 9:40 am, edited 13 times in total.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

:arrow: notification bug fixed : aboslute position of popupmenu
Last edited by eddy on Mon Jun 23, 2003 9:43 am, edited 1 time in total.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

I fund a bug :
when I click on menu item (e.g. file), the arrow button is not released.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

:arrow: DropDown Arrow Bug fixed : the arrow is released now

It works perfectly now :D
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

if you want to show a submenu of main menu :

Code: Select all

#TPM_VERTICAL=$40

*DropDownMenu = GetSubMenu_(GetSubMenu_(*MainMenu,3),5)
tpm.TPMPARAMS
tpm\cbSize = SizeOf(TPMPARAMS)
tpm\rcExclude\top    = rc\top
tpm\rcExclude\bottom = rc\bottom
tpm\rcExclude\left   = rc\left
tpm\rcExclude\right  = rc\right
TrackPopupMenuEx_(*DropDownMenu,#TPM_LEFTALIGN|#TPM_LEFTBUTTON|#TPM_VERTICAL,rc\left, rc\bottom, windowID(), @tpm)
DominiqueB
Enthusiast
Enthusiast
Posts: 103
Joined: Fri Apr 25, 2003 4:00 pm
Location: France

Hello !

Post by DominiqueB »

Eddy, the screenshots of your editor is better and better ! ! !
Any way to have a try ?
Will you do it to work for PB to ?

Thank's

Dominique
Dominique

Windows 10 64bits. Pure basic 32bits
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Eddy, the screenshots of your editor is better and better ! ! !
Any way to have a try ?
Thanks. :)
It's not complete.
more infos here
Will you do it to work for PB to ?
I think already about it, perhaps a hack of SciPB.
PB will need a single interface. :)

I must design some new icons
Post Reply