Page 1 of 1

Toolbar button w/ drop down?

Posted: Tue Nov 22, 2011 4:39 pm
by jassing
Am I right in that there is no native "drop down" toolbar item?

Re: Toolbar button w/ drop down?

Posted: Tue Nov 22, 2011 5:41 pm
by IdeasVacuum
Well, there isn't a native toolbar to drop it from.......

Re: Toolbar button w/ drop down?

Posted: Tue Nov 22, 2011 6:03 pm
by Zach
I think he means a selection box, like the selection boxes on an Open File dialog to choose the file type filter, or recall a previously entered path/file

Re: Toolbar button w/ drop down?

Posted: Tue Nov 22, 2011 6:16 pm
by IdeasVacuum
...I think it is an icon toolbar where holding the left-mouse on a toolbar button invokes a drop-down toolbar of other buttons.

Re: Toolbar button w/ drop down?

Posted: Tue Nov 22, 2011 6:21 pm
by Kuron
IdeasVacuum wrote:...I think it is an icon toolbar where holding the left-mouse on a toolbar button invokes a drop-down toolbar of other buttons.
This would be my guess. :wink:

Re: Toolbar button w/ drop down?

Posted: Tue Nov 22, 2011 8:20 pm
by Zach
Oh, those things..

Only place I've seen something similar to them available is in using ProGUI. I think you need to use a Rebar to get those. But assuming you can conjur up a Rebar via API, I would assume it can be done in standard PB.

It is demonstrated in RebarExample2.exe and ToolBarExample.exe from the samples pack download.

Re: Toolbar button w/ drop down?

Posted: Tue Nov 22, 2011 9:40 pm
by netmaestro
It's actually pretty easy with a popup menu, if all you're looking for is a dropdown with options:

Code: Select all

Procedure WinProc(hwnd, msg, wparam, lparam)
  result=#PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NOTIFY
      *nmt.NMTOOLBAR = lparam
      Select *nmt\hdr\code
        Case #TBN_DROPDOWN
          MapWindowPoints_( WindowID(0), 0, *nmt\rcButton, 2)
          DisplayPopupMenu(1, WindowID(0),*nmt\rcButton\left,*nmt\rcButton\bottom)
          ProcedureReturn 0
      EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0, 100, 200, 640, 480, "ToolBar example", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
SetWindowCallback(@WinProc())

bar =  CreateToolBar(0, WindowID(0))
SendMessage_(bar, #TB_SETBUTTONSIZE, 0, 48|24<<16)
SendMessage_(bar, #TB_SETEXTENDEDSTYLE, 0, #TBSTYLE_EX_DRAWDDARROWS)

ToolBarStandardButton(0, #PB_ToolBarIcon_New)
ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
ToolBarStandardButton(2, #PB_ToolBarIcon_Save)

With tbbi.TBBUTTONINFO
  \dwMask = #TBIF_BYINDEX|#TBIF_STYLE
  \cbSize = SizeOf(TBBUTTONINFO)
EndWith
SendMessage_(bar, #TB_GETBUTTONINFO, 2, @tbbi)

tbbi\fsStyle|#BTNS_DROPDOWN

SendMessage_(bar, #TB_SETBUTTONINFO, 2, @tbbi)


If CreateMenu(0, WindowID(0))
  MenuTitle("Project")
  MenuItem(0, "New")
  MenuItem(1, "Open")
  MenuItem(2, "Save")
EndIf

CreatePopupMenu(1)
MenuItem(9,  "Option 1")
MenuItem(10, "Option 2")
MenuItem(11, "Option 3")

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Menu
      MessageRequester("Information", "ToolBar or Menu ID: "+Str(EventMenu()), 0)
    Case #PB_Event_CloseWindow 
      Quit=1
  EndSelect
Until Quit

Re: Toolbar button w/ drop down?

Posted: Tue Nov 22, 2011 11:45 pm
by IdeasVacuum
Well, the first lesson learnt from netmaestro's excellent code is - scroll down to the bottom of the help menu! I never knew CreateToolBar was there (may be because I expected it to be described as a Gadget).

Re: Toolbar button w/ drop down?

Posted: Wed Nov 23, 2011 7:07 pm
by jassing
netmaestro wrote:It's actually pretty easy with a popup menu, if all you're looking for is a dropdown with options:
Thanks for the example... I'm doing some work; and the client is leaning towards RealBasic; so I want to be sure I can do everything their asking in PureBasic...