Page 1 of 1

Popupmenu with icons

Posted: Tue Feb 25, 2003 12:10 pm
by BackupUser
Code updated for 5.20+. Same as MenuItem() with ImageID parameter.

Restored from previous forum. Originally posted by dige.

maybe someone need this:

Code: Select all

; Create a popupmenu with images
hWnd = OpenWindow(0, 100, 200, 300, 100, "Popmenu with Icons", #PB_Window_SystemMenu)

mHandle = CreatePopupMenu (0)

MenuItem(10, "With Icon")
MenuItem(20, "Without Icon")
MenuItem(30, "With Icon")
MenuItem(40, "Standard Icon")

ButtonGadget ( 3, 50, 30, 200, 50, "click here for popup" )

hChk    = LoadImage_(0, #PB_Compiler_Home + "Examples/Sources/Data/File.bmp",0,0,0,#LR_LOADTRANSPARENT | #LR_LOADFROMFILE )
hUnChl  = LoadImage_(0, #PB_Compiler_Home + "Examples/Sources/Data/Drive.bmp",0,0,0,#LR_LOADTRANSPARENT | #LR_LOADFROMFILE )

SetMenuItemBitmaps_(mHandle, 10, $10, hChk, hUnChk)
SetMenuItemBitmaps_(mHandle, 30, $10, hChk, hUnChk)

SetMenuItemState(0, 30, 1 )
SetMenuItemState(0, 40, 1 )

Repeat
  EventID = WaitWindowEvent()
  If EventID = #PB_Event_Gadget
    DisplayPopupMenu(0, hWnd)
  EndIf
Until EventID = #PB_Event_CloseWindow
End
regards, dige

Posted: Tue Feb 25, 2003 2:12 pm
by BackupUser
Restored from previous forum. Originally posted by blueb.

Dige,

I'm not sure, but PureBasic's built-in commands take
care of this for you. I deleted some lines from the
above sample and it works fine.

Code: Select all

; Create a popupmenu with images
hWnd.l = OpenWindow (0, 100, 200, 300, 100, #PB_Window_SystemMenu , "Popmenu with Icons" )

CreateGadgetList( hWnd )

mHandle.l = CreatePopupMenu (0)

MenuItem(10, "With Icon")
MenuItem(20, "Without Icon")
MenuItem(30, "With Icon")
MenuItem(40, "Standard Icon")

ButtonGadget ( 3, 50, 30, 200, 50, "click here for popup" )
SetMenuItemState(0, 30, 1 ) 
SetMenuItemState(0, 40, 1 ) 

Repeat
  EventID = WaitWindowEvent()
  If EventID = #PB_Event_Gadget
    DisplayPopupMenu(0, hWnd) 
  EndIf
Until EventID = #PB_Event_CloseWindow
End

Regards,
--blueb

Posted: Tue Feb 25, 2003 6:05 pm
by BackupUser
Restored from previous forum. Originally posted by plouf.

But your Code does not have icons
i.e. dige's code loads chk.bmp (must exist in your drawer)
and displays it to the left of the pop up

nice snippet btw :)

Christos