Page 1 of 1

SetMenuItemInfo_ seems not to work on ...ImageMenu

Posted: Tue Jun 24, 2008 11:07 pm
by sverson
I only get bold menu items when i use CreateMenu/CreatePopupMenu.
Image
It does not work with CreateImageMenu/CreatePopupImageMenu. :?
Image

Code: Select all

Enumeration
  #MenuBar
  #PopupMenu
EndEnumeration

Enumeration
  #MenuBold
  #MenuOpen
  #MenuClose
  #MenuPopup
  #MenuQuit
EndEnumeration

Procedure.l SetMenuItemBold(MenuID.l,MenuItemPos.l)
  #MIIM_STATE=1
  #MFS_DEFAULT=4096
  Protected mib.MENUITEMINFO
  mib\cbSize=SizeOf(mib)
  mib\fMask=#MIIM_STATE
  mib\fState=#MFS_DEFAULT
  SetMenuItemInfo_(MenuID,MenuItemPos,#False,mib)
EndProcedure

If OpenWindow(0,0,0,400,400,"BoldMenuItem",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;  If CreateImageMenu(#MenuBar,WindowID(0)) <-- no bold item!!!
  If CreateMenu(#MenuBar,WindowID(0))
    MenuTitle("&BoldItem")
    MenuItem(#MenuOpen,"&Open")
    MenuItem(#MenuClose,"&Close")
    MenuBar()
    MenuItem(#MenuPopup,"&Popup")
    MenuBar()
    MenuItem(#MenuQuit,"&Quit")
    SetMenuItemBold(MenuID(#MenuBar),#MenuPopup)
  EndIf
  ;  If CreatePopupImageMenu(#PopupMenu) <-- no bold item!!!
  If CreatePopupMenu(#PopupMenu)
    MenuItem(#MenuOpen,"Open")
    MenuItem(#MenuClose,"Close")
    MenuBar()
    MenuItem(#MenuBold,"- bold -")
    MenuBar()
    MenuItem(#MenuQuit,"Quit")
    SetMenuItemBold(MenuID(#PopupMenu),#MenuBold) 
  EndIf
  Repeat
    Select WaitWindowEvent()
      Case #WM_RBUTTONDOWN : DisplayPopupMenu(#PopupMenu,WindowID(0))
      Case #PB_Event_Menu
        Select EventMenu()  ; To see which menu has been selected
          Case #MenuOpen  : MessageRequester("Info!", "OPEN", #MB_OK|#MB_ICONINFORMATION)
          Case #MenuClose : MessageRequester("Info!", "CLOSE", #MB_OK|#MB_ICONINFORMATION)
          Case #MenuBold  : MessageRequester("Info!", "BOLD", #MB_OK|#MB_ICONINFORMATION)
          Case #MenuPopup : DisplayPopupMenu(#PopupMenu,WindowID(0),WindowX(0)+10,WindowY(0)+60)
          Case #MenuQuit  : Quit = 1
        EndSelect
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
  Until Quit = 1
EndIf

End
Please help...

PB4.20 - jaPBe V3 - WIN XP Pro SP3

Posted: Wed Jun 25, 2008 12:54 pm
by Sparkie
CreateImageMenu(#MenuBar,WindowID(0)) causes the menu to be ownerdrawn. PureBasic only supports a state of 0 or 1 which translates to checked or unchecked items, with no ownerdraw support for bold items.

Posted: Wed Jun 25, 2008 1:28 pm
by sverson
Thx Sparkie :)

- - so i have to create my own ownerdrawn menu to get bold items with icons :?

Posted: Wed Jun 25, 2008 1:39 pm
by Sparkie
... or put in a request for PB support for #MFS_DEFAULT (bold) :wink:

When I get home tonight I'll see if there is in fact a workaround for this.

Posted: Wed Jun 25, 2008 1:45 pm
by srod
Well, although the #MFS_DEFAULT style cannot be set without using API, it is nevertheless a valid window's menuitem style. Consider putting in a request for PB to support this style through the ownerdrawn image menus. **EDIT : too late, beaten by the Sparkie! :)

A better thought, considering that this style is not cross-platform, is to instead request that, for image menus, the MenuItem() command be extended with an optional fontID parameter. This would then allow you to apply just about any style to individual items and could probably be made crossplatform. The only issue then would be in ensuring that the menu item heights were sufficient to accommodate whichever fonts you throw at them etc.

Yes, this would be a nice addition. :)

Posted: Wed Jun 25, 2008 1:53 pm
by Sparkie
Nice idea srod 8) ...now code it and submit it to save freak some time :twisted: :P

Posted: Wed Jun 25, 2008 2:01 pm
by srod
Sparkie wrote:Nice idea srod 8) ...now code it and submit it to save freak some time :twisted: :P
:lol:

A nice idea in turn, but my amateurish bug-ridden spaghettified code has no place in such a grand product as PB! :wink:

Seriously, such a facility (PB internals aside) could be added in but a few lines of code. What about, instead of a fontID parameter, just a style parameter? We could use one of the existing font styles : #PB_Font_Bold etc. This way we wouldn't be interfering with the menu item heights (at least not enough to have to alter #WM_MEASUREITEM etc.) and all Fred/Freak would need to do would be to create a logical font based upon the one currently selected into the menu dc etc.