Toolbar...DropDownButton... How to

Just starting out? Need help? Post your questions and find answers here.
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Toolbar...DropDownButton... How to

Post by morosh »

Hello:
I tried to implement a dropdown button in a toolbar, I tried to use an example from old PBOSL, it didn't run in 64 bits mode. It seems that I need to translate some functions to win api (UpdateTB(), GetTBbuttonRect ).

Any help is appreciated.
thank you

Code: Select all

UsePNGImageDecoder()
Define sizex.a, sizey.a, TB.l, TBIL.l

CatchImage(0,?but1)
CatchImage(1,?but2)

sizex = 4*ImageWidth(0)
sizey= 2*ImageHeight(0)

If CreatePopupMenu(100)
  MenuItem(10, "MenuID 10")
  MenuItem(20, "MenuID 20")
EndIf

Procedure mycallback(hWnd, Msg, wParam, lParam)
  Define Result.l, *nmTB.NMTOOLBAR, rect.RECT
  Result = #PB_ProcessPureBasicEvents
  Select Msg
          Case #WM_SIZE
            UpdateTB(0)
      
    Case #WM_NOTIFY
      *nmTB.NMTOOLBAR = lParam
      Select *nmTB\hdr\code
        Case #TBN_DROPDOWN
          GetTBbuttonRect(*nmTB\iItem,rect.RECT)
          If *nmTB\iItem = 11
            DisplayPopupMenu(100,hWnd,rect\left,rect\bottom)
          EndIf            
          Result = #TBDDRET_DEFAULT
      EndSelect
  EndSelect
  
  ;UpdateTB(0)
  ProcedureReturn Result
EndProcedure

OpenWindow(0,0,0,600,200,"ToolBar",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)

TB = CreateToolBar(1,WindowID(0))
TBIL = SendMessage_(TB, #TB_GETIMAGELIST , 0, 0)
ImageList_SetIconSize_(TBIL,sizex,sizey)
SendMessage_(TB, #TB_SETBUTTONSIZE, 0, (sizex|sizey << 16))
SendMessage_(TB, #TB_AUTOSIZE, 0, 0)
ToolBarImageButton(10,ImageID(0))
ToolBarImageButton(11,ImageID(1))

SetWindowCallback(@mycallback(), 0)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend

DataSection
  but1:
  IncludeBinary #PB_Compiler_Home+"Examples\Sources\Data\ToolBar\new.png"
  but2:
  IncludeBinary #PB_Compiler_Home+"Examples\Sources\Data\ToolBar\open.png"
EndDataSection

PureBasic: Surprisingly simple, diabolically powerful
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Toolbar...DropDownButton... How to

Post by RSBasic »

Image
Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: Toolbar...DropDownButton... How to

Post by Thorsten1867 »

Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
Post Reply