Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Picture/Icon/Icons in List and Menu
Function:
Required plugins for this example: MBS Picture Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Picture/Icon/Icons in List and Menu
This example is the version from Thu, 16th Nov 2016.
Project "Icons in List and Menu.rbp"
Class Window1 Inherits Window
Control PopupMenu1 Inherits PopupMenu
ControlInstance PopupMenu1 Inherits PopupMenu
EventHandler Sub Open() dim f,g as FolderItem dim i,c as integer dim m as MenuMBS dim icon as IconMBS // This works in RB 4.5, but not in RB 5.5. Sorry. m=PopupMenu1.MenuMBS if m=nil then MsgBox "Can't fill the Popupmenu :-(" else // find the folder f=ApplicationsFolderMBS(0) // walk through files c=f.Count for i=1 to c g=f.TrueItem(i) if left(g.Name,1)<>"." and g.Visible then PopupMenu1.AddRow g.DisplayName // Make the Icon icon=new IconMBS(g) if icon.Valid then // if ok, set the handle m.SetIconRefHandle m.Count, icon.Handle // save for later releaseing (to avoid leak) icons.Append icon end if end if next end if End EventHandler
End Control
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
EventHandler Sub Open() dim f,g as FolderItem dim i,c as integer // find the folder f=ApplicationsFolderMBS(0) // walk through files c=f.Count for i=1 to c g=f.TrueItem(i) if left(g.Name,1)<>"." and g.Visible then // Just add to listbox ListBox1.AddRow g.DisplayName ListBox1.RowPicture(ListBox1.LastIndex)=GetIcon(g) end if next End EventHandler
End Control
Function GetIcon(f as folderitem) As picture // make an icon with mask from the file dim m,p as Picture dim q as Picture p=f.IconImageMBS(16) m=f.IconMaskMBS(16) q = new Picture(16,16,32) q.Graphics.DrawPicture p,0,0 q.Mask.Graphics.DrawPicture m,0,0 Return q End Function
Property Protected icons(0) As IconMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Picture Plugin.




Links
MBS FileMaker blog