LoadMenu Function (+Example)

Share your advanced PureBasic knowledge/code with the community.
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

LoadMenu Function (+Example)

Post by Dr. Dri »

For 2k6 i offer you a small sweet function ^^
It loads a resource menu and make it like a native PB menu

it means
-you can use it with any PB menu function
-your menu can be availlable in several languages

i also made a small example program ^^
File:1->Menu.zip
Image

Code: Select all

Procedure.l LoadMenu(Library.l, Index.l)
  Protected Load.l, LibraryID.l
  Protected *MenuID.Long, MenuID.l
  Static    ModuleID.l
  
  
  If ModuleID = #Null
    ModuleID = GetModuleHandle_(#Null)
  EndIf
  
  If Library = #PB_Default
    LibraryID = ModuleID
  Else
    If IsLibrary(Library)
      LibraryID = LibraryID(Library)
    EndIf
  EndIf
  
  If LibraryID
    MenuID = LoadMenu_(LibraryID, Index)
    
    CreateMenu( Index, WindowID() )
    *MenuID = IsMenu(Index)
    
    SetMenu_(WindowID(), MenuID)
    DestroyMenu_(*MenuID\l)
    *MenuID\l = MenuID
  EndIf
  
  ProcedureReturn MenuID
EndProcedure
Dri ;)