Dropdown menu with toolbar button

Is there a template that allows for a toolbar button with dropdown options like you see in Outlook?

I’m looking for something quick and easy to implement.

Not what you were looking for but very quick and easy.
I often just open a popup menu at the current cursor position.
With some api calls it should be possible to get the correct coordinated for the bottom edge of a button.

This thread might be of use for positioning a popup.

Just use the POPUP function in response to button’s EVENT:Accept event. The easiest way to determine coordinates of menu’s upper-left corner is to use the GetWindowRect API function. The alternative way is to set PROP:Pixels for a window to 1 and then call GETPOSITION.
popup.zip (819 Bytes)

I use two little procedures to make this easier

   MAP 
PopupBeside         PROCEDURE(LONG CtrlFEQ, STRING PopMenu),LONG
PopupUnder          PROCEDURE(LONG CtrlFEQ, STRING PopMenu),LONG

PopupBeside PROCEDURE(LONG CtrlFEQ, STRING PopMenu)!,LONG
X LONG,AUTO
Y LONG,AUTO
W LONG,AUTO
    CODE
    GETPOSITION(CtrlFEQ,X,Y,W)
    IF CtrlFEQ{PROP:InToolBar} THEN Y -= (0{PROP:ToolBar}){PROP:Height}.    
    RETURN POPUP(PopMenu,X+W,Y,1)

PopupUnder PROCEDURE(LONG CtrlFEQ, STRING PopMenu)!,LONG
X LONG,AUTO
Y LONG,AUTO
H LONG,AUTO
    CODE
    GETPOSITION(CtrlFEQ,X,Y,,H)
    IF CtrlFEQ{PROP:InToolBar} THEN Y -= (0{PROP:ToolBar}){PROP:Height}.
    RETURN POPUP(PopMenu,X,Y+H+1,1) 


Examples


 SnapHow=POPUPunder(?SnapToBtn,'Left{{Top|Center|Bottom}|Center{{Top|Center|Bottom}|Right{{Top|Center|Bottom}')


  OF ?MenuBtn
     EXECUTE POPUPunder(?MenuBtn,'Copy Queue to Clipboard|-|Contract Column Widths|Expand Column Widths' & |
                       '|-|Copy VLB Format String')
     SetClip2Queue(VlbQ) 
     ...

image

GetWindowRect() and Pixels are no longer required if you pass the 4th parameter of POPUP(Text,X,Y,Position) as True or 1 as shown above. You can use GetPosition(). From the Help:

Position
A BYTE value that if set to 1 specifies that the popup coordinates (2nd and 3rd parameters) are treated as relative to the upper left corner of the active window’s client area. If set to 0 (the default), they are screen coordinates.

Hi Leroy,

Feel free to take a look at our Codejock CommandBars wrapper template :-

and a demo is available via https://noyantis.com/downloads/CommandBarsDemo.exe

Any questions, feel free to ask :slight_smile:

Thanks,

Andy
noyantis.com

If you’re writing a common code, coordinates in pixels are required to place POPUP menu in particular position. For example, the program can set PROP:Pixels to TRUE and then change position/size of a control. As result, corners of that control can not match exact coordinates in DLUs. GETPOSITION if PROP:Pixels is FALSE rounds such coordinates. Also, if a control has the SCROLL attribute, X and Y coordinates returned by GETPOSITION must be adjusted with values of PROP:XOrigin and PROP:YOrigin for a window. NB, scrolling offsets of the window’s client area can be not proportinal to DLU units, and they are rounding if PROP:Pixels is not TRUE.

The nice thing about the Codejock CommandBars control is that it conforms to the Microsoft Ribbon UI standards, and can automatically expand grouped items when there is enough space to show, or automatically contract into a popup when there isn’t enough space to show the contents - all without writing any code :slight_smile:

Plus of course, you have the option of Ribbon interface, CommandBars interface or TabbedBar interface.

Plus all the Office, Visual Studio and Windows themes are supported.

Thanks,

Andy
noyantis.com

Addition to previous my message. Windows API functions use coordinates in pixels. If coordinates are not integer numbers because of world coordinate transformations, they are rounding. Clarion RTL calculates DLUs for a WINDOW based on its font. If program uses coordinates/sizes in DLUs, the RTL converts them to pixels and versa if real (in pixels) coordinates/sizes must be returned to the program as values of properties, etc. Such conversion involves rounding and rounding errors may accumulate.

Example. Actual values of DLUs for the font Tahoma,9,Normal are:

  • horizontal - 2=8/4 pixels (8 is actually rounded value 8.192);
  • vertical - 2.25=18/8 pixels.

Because vertical DLU value is not integer, rounding can cause, for example, not equal distances between vertically spread controls: 3 DLUs are converting to 7 pixels, 9 DLUs are converting to 20 pixels.

This is not a Clarion error. This is how DLUs work.

1 Like

Thanks everyone. I’ll have a look at your suggestions.