PopupMenu 4 ToolBar buttons

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
zxtunes.com
Enthusiast
Enthusiast
Posts: 375
Joined: Wed Apr 23, 2008 7:51 am
Location: Saint-Petersburg, Russia
Contact:

PopupMenu 4 ToolBar buttons

Post by zxtunes.com »

I have window with MDI gadget, menu and toolbar.

I do graphic editor. In some cases it is convenient when you press the left mouse button on the toolbar button to open popup menu (like photoshop).
But it seems it is not possible.
It could be a loophole and set menu on the coordinates of the buttons. But they can not learn. I tried to simulate the toolbar, but MDI gadget ignores coordinates and is always on top window, thus nowhere to show imagebutton gadget.

Purebasic drove me to a standstill. :?

Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: PopupMenu 4 ToolBar buttons

Post by srod »

**EDIT : sorry if posting code here is/was inappropriate. For some reason I decided that this was a coding question and I was in the coding forum! More coffee needed...

=========================


I would recommend that you use the nxToolbar library (or one of Eddy's toolbar libs).

However, if a hack will suffice...

Code: Select all

Procedure callback(hWnd, uMsg, wParam, lParam)
  Protected result, *nmt.NMTOOLBAR, rc.RECT
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *nmt = lParam
      If *nmt\hdr\code = #TBN_DROPDOWN ;User has clicked our toolbar button's drop down arrow.
        ;Get screen co-ordinates of the button.
          SendMessage_(*nmt\hdr\hwndFrom, #TB_GETRECT, *nmt\iItem, rc)
          MapWindowPoints_(*nmt\hdr\hwndFrom, 0, rc, 2)
        ;Display pop-up menu.
          DisplayPopupMenu(0, WindowID(0), rc\left, rc\bottom)
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure


If OpenWindow(0, 0, 0, 150, 25, "ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ;Create a pop-up menu.
    If CreatePopupMenu(0)
      MenuItem(100, "Cut")
      MenuItem(101, "Copy")
      MenuItem(102, "Paste")
    EndIf
  ;Create our toolbar.
    hTb = CreateToolBar(0, WindowID(0))
    If hTb
      ToolBarStandardButton(0, #PB_ToolBarIcon_New)
      ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
      ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
      ;Add a drop down button.
        fStyle = SendMessage_(hTb,#TB_GETEXTENDEDSTYLE,0,0)
        SendMessage_(hTb, #TB_SETEXTENDEDSTYLE, 0, fSTyle | #TBSTYLE_EX_DRAWDDARROWS)
        With btn.TBBUTTON
          \iBitmap   = #PB_ToolBarIcon_Print+1
          \idCommand = 3
          \fsState   = #TBSTATE_ENABLED
          \fsStyle   = $8|#BTNS_SHOWTEXT|#TBSTYLE_AUTOSIZE
          \dwData    = 0
          \iString   = -1
          SendMessage_(hTb, #TB_ADDBUTTONS,1, btn)
        EndWith
    EndIf

  SetWindowCallback(@callback())

  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Menu
      Debug "Menu ID: "+Str(EventMenu())
    EndIf
  Until Event = #PB_Event_CloseWindow 
EndIf
I say 'hack' because you have some work to do if you wish to add a custom image button having a drop down arrow. :wink:
I may look like a mule, but I'm not a complete ass.
Post Reply