Icônes en bmp à télécharger ici : Minis Bmp au format 13x13 et 16x16
Code : Tout sélectionner
;Jacobus 01/12/2006
;Agrémenter ses menus et popupmenus avec des icônes
;Pour afficher des images correctes elles doivent impérativement être
;au format 13x13 pixels, sinon elles sont tronquées.
;D'où l'intérêt de ce pack d'icônes converties en bmp.
;code d'exemple avec PB4.01 pour windows
;-Constantes
Enumeration
#WIN
#MENU
#Menu1
#Menu2
#Menu3
#Menu4
#Menu5
#Menu6
#Menu7
#Menu8
#Menu9
#Menu10
#Menu11
#Menu12
#Menu13
#POPUP_EXPLORER
#MENU_OPENFILE
#MENU_PACK
#MENU_UNPACK
#MENU_SUPPRIMER
#MENU_DELETE
#MENU_ERASE
#MENU_COPIER
#MENU_DEPLACER
#EXPLORER
EndEnumeration
#PROGNAME = "Menus et icônes"
;-Catch images
Global Image0, Image1, Image2, Image3, Image4, Image5, Image6, Image7, Image8, Image9, Image10
Global Image11, Image12, Image13, Image15, Image15, Image16, Image17, Image18;, Image19, Image20
Image0 = CatchImage(0, ?Image0)
Image1 = CatchImage(1, ?Image1)
Image2 = CatchImage(2, ?Image2)
Image3 = CatchImage(3, ?Image3)
Image4 = CatchImage(4, ?Image4)
Image5 = CatchImage(5, ?Image5)
Image6 = CatchImage(6, ?Image6)
Image7 = CatchImage(7, ?Image7)
Image8 = CatchImage(8, ?Image8)
Image9 = CatchImage(9, ?Image9)
Image10 = CatchImage(10, ?Image10)
Image11 = CatchImage(11, ?Image11)
Image12 = CatchImage(12, ?Image12)
Image13 = CatchImage(13, ?Image13)
Image14 = CatchImage(14, ?Image14)
Image15 = CatchImage(15, ?Image15)
Image16 = CatchImage(16, ?Image16)
Image17 = CatchImage(17, ?Image17)
Image18 = CatchImage(18, ?Image18)
;Image19 = CatchImage(19, ?Image19)
;Image20 = CatchImage(20, ?Image20)
DataSection ;-BMP 13x13
Image0 : IncludeBinary "BmpMENUS\OpenFile.bmp"
Image1 : IncludeBinary "BmpMENUS\zip.bmp"
Image2 : IncludeBinary "BmpMENUS\RecycleBin.bmp"
Image3 : IncludeBinary "BmpMENUS\Copy.bmp"
Image4 : IncludeBinary "BmpMENUS\SendTo.bmp"
Image5 : IncludeBinary "BmpMENUS\DirExplore.bmp"
Image6 : IncludeBinary "BmpMENUS\Replace.bmp"
Image7 : IncludeBinary "BmpMENUS\Shredfile.bmp"
Image8 : IncludeBinary "BmpMENUS\save.bmp"
Image9 : IncludeBinary "BmpMENUS\Rescue.bmp"
Image10 : IncludeBinary "BmpMENUS\Quit3.bmp"
Image11 : IncludeBinary "BmpMENUS\Delete.bmp"
Image12 : IncludeBinary "BmpMENUS\TextFile_2.bmp"
Image13 : IncludeBinary "BmpMENUS\Vers.bmp"
Image14 : IncludeBinary "BmpMENUS\MrGreen.bmp"
Image15 : IncludeBinary "BmpMENUS\OneUser.bmp"
Image16 : IncludeBinary "BmpMENUS\AllUsers.bmp"
Image17 : IncludeBinary "BmpMENUS\Death_brrr.bmp"
Image18 : IncludeBinary "BmpMENUS\WhoIsUser.bmp"
;Image19 : IncludeBinary "BmpMENUS\.bmp"
;Image20 : IncludeBinary "BmpMENUS\.bmp"
EndDataSection
;-------------------------
;- FENETRE <<<
;-------------------------
ExamineDesktops()
Largeur$ = Str(DesktopWidth(0))
Hauteur$ = Str(DesktopHeight(0))
If Val(Largeur$)>800 And Val(Hauteur$)>600
FlagWin = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_TitleBar
Else
FlagWin = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar
EndIf
If OpenWindow(#WIN,0,0,790,550,#PROGNAME ,FlagWin)=0 Or CreateGadgetList(WindowID(#WIN))=0
End
EndIf
SetWindowColor(#WIN, RGB(255, 255, 255))
;-Menu
Menu = CreateMenu(#MENU, WindowID(#WIN))
If Menu
MenuTitle("Projet")
MenuItem(#Menu1, " Ouvrir" +Chr(9)+"Ctrl+O")
MenuBar()
MenuItem(#Menu2, " Enregistrer" +Chr(9)+"Ctrl+E")
MenuBar()
MenuItem(#Menu3, " Sauvegarder" +Chr(9)+"Ctrl+S")
MenuBar()
MenuItem(#Menu4, " Quitter "+#PROGNAME +Chr(9)+"Ctrl+F")
MenuTitle("Edition")
MenuItem(#Menu5, " Editer")
MenuItem(#Menu6, " Copier")
MenuItem(#Menu7, " Remplacer")
MenuBar()
MenuItem(#Menu8, " Supprimer")
MenuTitle("Administration")
MenuItem(#Menu9, " Admin")
MenuBar()
MenuItem(#Menu10, " Utilisateur")
MenuItem(#Menu11, " Tous les utilisateurs")
MenuBar()
MenuItem(#Menu12, " Qui est-ce ?")
MenuItem(#Menu13, " Bannir définitivement")
; SetMenuItemBitmaps_(Menu, #MENU_ITEM, flags, ImageID(Img)=IconUnchecked, ImageID(Img)=IconChecked)
SetMenuItemBitmaps_(Menu, #Menu1, #MF_BYCOMMAND, ImageID(5), ImageID(5))
SetMenuItemBitmaps_(Menu, #Menu2, #MF_BYCOMMAND, ImageID(8), ImageID(8))
SetMenuItemBitmaps_(Menu, #Menu3, #MF_BYCOMMAND, ImageID(9), ImageID(9))
SetMenuItemBitmaps_(Menu, #Menu4, #MF_BYCOMMAND, ImageID(10), ImageID(10))
SetMenuItemBitmaps_(Menu, #Menu5, #MF_BYCOMMAND, ImageID(12), ImageID(12))
SetMenuItemBitmaps_(Menu, #Menu6, #MF_BYCOMMAND, ImageID(3), ImageID(3))
SetMenuItemBitmaps_(Menu, #Menu7, #MF_BYCOMMAND, ImageID(6), ImageID(6))
SetMenuItemBitmaps_(Menu, #Menu8, #MF_BYCOMMAND, ImageID(2), ImageID(2))
SetMenuItemBitmaps_(Menu, #Menu9, #MF_BYCOMMAND, ImageID(14), ImageID(14))
SetMenuItemBitmaps_(Menu, #Menu10, #MF_BYCOMMAND, ImageID(15), ImageID(15))
SetMenuItemBitmaps_(Menu, #Menu11, #MF_BYCOMMAND, ImageID(16), ImageID(16))
SetMenuItemBitmaps_(Menu, #Menu12, #MF_BYCOMMAND, ImageID(18), ImageID(18))
SetMenuItemBitmaps_(Menu, #Menu13, #MF_BYCOMMAND, ImageID(17), ImageID(17))
EndIf
;-Popup Menu
PopUpMenu = CreatePopupMenu(#POPUP_EXPLORER)
If PopUpMenu
MenuItem(#MENU_OPENFILE, " Ouvrir") ;on laisse un espace entre l'icône et le texte
MenuBar() ;mais chacun fait comme il le sent
MenuItem(#MENU_PACK, " Compresser")
MenuItem(#MENU_UNPACK, " Décompresser")
MenuBar()
MenuItem(#MENU_SUPPRIMER," Envoyer à la corbeille")
MenuItem(#MENU_DELETE, " Supprimer")
MenuItem(#MENU_ERASE, " Passer au broyeur")
MenuBar()
MenuItem(#MENU_COPIER, " Copier vers ...")
MenuItem(#MENU_DEPLACER, " Déplacer vers ...")
; SetMenuItemBitmaps_(PopUpMenu, #MENU_ITEM, flags, ImageID(Img)=IconUnchecked, ImageID(Img)=IconChecked)
SetMenuItemBitmaps_(PopUpMenu, #MENU_OPENFILE, #MF_BYCOMMAND, ImageID(0), ImageID(0))
SetMenuItemBitmaps_(PopUpMenu, #MENU_PACK, #MF_BYCOMMAND, ImageID(1), ImageID(1))
SetMenuItemBitmaps_(PopUpMenu, #MENU_UNPACK, #MF_BYCOMMAND, ImageID(1), ImageID(1))
SetMenuItemBitmaps_(PopUpMenu, #MENU_SUPPRIMER, #MF_BYCOMMAND, ImageID(2), ImageID(2))
SetMenuItemBitmaps_(PopUpMenu, #MENU_DELETE, #MF_BYCOMMAND, ImageID(11), ImageID(11))
SetMenuItemBitmaps_(PopUpMenu, #MENU_ERASE, #MF_BYCOMMAND, ImageID(7), ImageID(7))
SetMenuItemBitmaps_(PopUpMenu, #MENU_COPIER, #MF_BYCOMMAND, ImageID(13), ImageID(13))
SetMenuItemBitmaps_(PopUpMenu, #MENU_DEPLACER, #MF_BYCOMMAND, ImageID(4), ImageID(4))
EndIf
ExplorerListGadget(#EXPLORER,0, 0, WindowWidth(#WIN),WindowHeight(#WIN),"c:\",#PB_Explorer_MultiSelect)
ChangeListIconGadgetDisplay(#EXPLORER, #PB_ListIcon_LargeIcon)
;-----Event Gadgets
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #EXPLORER
;Double-clic gauche pour ouvrir un répertoire sinon...
Select EventType()
Case #PB_EventType_RightClick
PosPopup = GetGadgetState(#EXPLORER)
If PosPopup >= 0
Resultat = GetGadgetItemState(#EXPLORER, PosPopup)
If Resultat & #PB_Explorer_Selected And Resultat & #PB_Explorer_File
SelectedFile$ = GetGadgetItemText(#EXPLORER, PosPopup, 0)
extens$ = GetExtensionPart(SelectedFile$)
SetMenuItemText(#POPUP_EXPLORER,#MENU_OPENFILE ," Ouvrir :"+GetFilePart(SelectedFile$))
If extens$ <> "zip"
DisableMenuItem(#POPUP_EXPLORER,#MENU_UNPACK,1)
DisableMenuItem(#POPUP_EXPLORER,#MENU_PACK,0)
Else
DisableMenuItem(#POPUP_EXPLORER,#MENU_UNPACK,0)
DisableMenuItem(#POPUP_EXPLORER,#MENU_PACK,1)
EndIf
DisplayPopupMenu(#POPUP_EXPLORER,WindowID(#WIN))
ElseIf Resultat & #PB_Explorer_Directory
SetMenuItemText(#POPUP_EXPLORER,#MENU_OPENFILE," Ouvrir ce dossier")
DisableMenuItem(#POPUP_EXPLORER,#MENU_UNPACK,1)
DisableMenuItem(#POPUP_EXPLORER,#MENU_PACK,0)
DisplayPopupMenu(#POPUP_EXPLORER,WindowID(#WIN))
EndIf
EndIf
EndSelect
EndSelect
;-----Event Menus
Case #PB_Event_Menu
Select EventMenu()
Case #Menu4 : Event = #PB_Event_CloseWindow
Case #MENU_OPENFILE
ShellExecute_(0,"open",GetGadgetText(#EXPLORER)+GetGadgetItemText(#EXPLORER, GetGadgetState(#EXPLORER) ,0),0,0,1)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End
;-end
Voilà, amusez-vous bien
