Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Picture/Icon/Custom Icon Test
Function:
Required plugins for this example: MBS MacClassic Plugin, 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/Custom Icon Test
This example is the version from Thu, 6th Apr 2016.
Project "Custom Icon Test.rbp"
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() TestFile End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() TestFolder End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() TestVolume End EventHandler
End Control
Protected Function ScalePicture(p as picture, w as integer) As picture dim q as Picture q=new Picture(w,w,32) q.Graphics.DrawPicture p,0,0,w,w,0,0,p.Width,p.Height Return q End Function
Protected Sub TestFile() dim ps,ms,p,m as Picture dim i as IconFamilyMBS dim f as FolderItem dim n as Integer dim t as TextOutputStream p=new Picture(1024,1024,32) p.Graphics.ForeColor=rgb(rnd*256,rnd*256,rnd*256) p.Graphics.FillOval 0,0,1024,1024 p.Graphics.ForeColor=rgb(rnd*256,rnd*256,rnd*256) p.Graphics.FillOval 128,128,256,256 m=new Picture(1024,1024,32) m.Graphics.ForeColor=rgb(0,0,0) m.Graphics.FillOval 0,0,1024,1024 i=NewIconFamilyMBS i.dither=true // For Mac OS X i.Thumbnail32BitData=p i.Thumbnail8BitMask=m // For Mac OS 9: i.Large8BitData=p i.Large1BitMask=m i.Large1BitData=p i.Large4BitData=p i.Large32BitData=p i.Large8BitMask=m // 1024, 512, 256, 128 Pixel images for Leopard ps=ScalePicture(p,1024) ms=ScalePicture(m,1024) call i.SetIconImage(ps,ms) ps=ScalePicture(p,512) ms=ScalePicture(m,512) call i.SetIconImage(ps,ms) ps=ScalePicture(p,256) ms=ScalePicture(m,256) call i.SetIconImage(ps,ms) ps=ScalePicture(p,128) ms=ScalePicture(m,128) call i.SetIconImage(ps,ms) f=SpecialFolder.Desktop.Child("testfile") if not f.Exists then t=f.CreateTextFile t.Close end if n=f.AddCustomIconMBS(i,true) if n=0 then MsgBox "ok" else MsgBox "error: "+str(n) end if End Sub
Protected Sub TestFolder() dim ps,ms,p,m as Picture dim i as IconFamilyMBS dim f as FolderItem dim n as Integer dim t as TextOutputStream dim d as FolderItem p=new Picture(1024,1024,32) p.Graphics.ForeColor=rgb(rnd*256,rnd*256,rnd*256) p.Graphics.FillOval 0,0,1024,1024 p.Graphics.ForeColor=rgb(rnd*256,rnd*256,rnd*256) p.Graphics.FillOval 128,128,256,256 m=new Picture(1024,1024,32) m.Graphics.ForeColor=rgb(0,0,0) m.Graphics.FillOval 0,0,1024,1024 i=NewIconFamilyMBS i.dither=true // For Mac OS X i.Thumbnail32BitData=p i.Thumbnail8BitMask=m // For Mac OS 9: i.Large8BitData=p i.Large1BitMask=m i.Large1BitData=p i.Large4BitData=p i.Large32BitData=p i.Large8BitMask=m // 1024, 512, 256, 128 Pixel images for Leopard ps=ScalePicture(p,1024) ms=ScalePicture(m,1024) call i.SetIconImage(ps,ms) ps=ScalePicture(p,512) ms=ScalePicture(m,512) call i.SetIconImage(ps,ms) ps=ScalePicture(p,256) ms=ScalePicture(m,256) call i.SetIconImage(ps,ms) ps=ScalePicture(p,128) ms=ScalePicture(m,128) call i.SetIconImage(ps,ms) d=SpecialFolder.Desktop.Child("testfolder") // create folder d.CreateAsFolder f=d.child("icon"+chr(13)) // create icon file inside if not f.Exists then t=f.CreateTextFile t.Close end if f.Visible=false f.MacType="icon" f.MacCreator="MACS" n=f.AddCustomIconMBS(i,true) // add icon to this icon file n=d.GetFolderFlagsMBS if n>=0 then n=Bitwiseor(n,&H0400) // set bundle bit for folder n=d.SetFolderFlagsMBS(n) end if n=f.GetFolderFlagsMBS if n>=0 then n=Bitwiseand(n,BitwiseNotMBS(&H0400)) // set bundle bit n=f.SetFolderFlagsMBS(n) end if n=d.FinderUpdateMBS MsgBox "done." End Sub
Protected Sub TestVolume() dim p,m as Picture dim i as IconFamilyMBS dim f as FolderItem dim n as Integer dim t as TextOutputStream dim d as FolderItem dim ps,ms as Picture p=new Picture(1024,1024,32) p.Graphics.ForeColor=rgb(rnd*256,rnd*256,rnd*256) p.Graphics.FillOval 0,0,1024,1024 p.Graphics.ForeColor=rgb(rnd*256,rnd*256,rnd*256) p.Graphics.FillOval 128,128,256,256 m=new Picture(1024,1024,32) m.Graphics.ForeColor=rgb(0,0,0) m.Graphics.FillOval 0,0,1024,1024 i=NewIconFamilyMBS i.dither=true // For Mac OS X i.Thumbnail32BitData=p i.Thumbnail8BitMask=m // For Mac OS 9: i.Large8BitData=p i.Large1BitMask=m i.Large1BitData=p i.Large4BitData=p i.Large32BitData=p i.Large8BitMask=m // 1024, 512, 256, 128 Pixel images for Leopard ps=ScalePicture(p,1024) ms=ScalePicture(m,1024) call i.SetIconImage(ps,ms) ps=ScalePicture(p,512) ms=ScalePicture(m,512) call i.SetIconImage(ps,ms) ps=ScalePicture(p,256) ms=ScalePicture(m,256) call i.SetIconImage(ps,ms) ps=ScalePicture(p,128) ms=ScalePicture(m,128) call i.SetIconImage(ps,ms) d=findvolume("test") // create folder if d=nil then MsgBox "Please make a disc image named test and mount it." quit end if // for Mac OS 9: f=d.child("icon"+chr(13)) // create icon file inside if not f.Exists then t=f.CreateTextFile t.Close end if f.Visible=false f.MacType="icon" f.MacCreator="MACS" n=f.AddCustomIconMBS(i,true) // add icon to this icon file n=d.GetFolderFlagsMBS if n>=0 then n=Bitwiseor(n,&H0400) // set bundle bit for folder n=d.SetFolderFlagsMBS(n) end if n=f.GetFolderFlagsMBS if n>=0 then n=Bitwiseand(n,BitwiseNotMBS(&H0400)) // set bundle bit n=f.SetFolderFlagsMBS(n) end if // For Mac OS X: f=d.child(".VolumeIcon.icns") // create icon file inside i.WriteFile f f.Visible=false n=d.FinderUpdateMBS MsgBox "done." End Sub
Protected Function findvolume(name as string) As folderitem dim i,c as integer dim f as FolderItem c=VolumeCount-1 for i=0 to c f=volume(i) if f.name="test" then Return f end if next End Function
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

Feedback, Comments & Corrections

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




Links
MBS Xojo tutorial videos