SetMenuItemInfo_ seems not to work on ...ImageMenu

Just starting out? Need help? Post your questions and find answers here.
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

SetMenuItemInfo_ seems not to work on ...ImageMenu

Post 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
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

Thx Sparkie :)

- - so i have to create my own ownerdrawn menu to get bold items with icons :?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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.
Last edited by Sparkie on Wed Jun 25, 2008 1:42 pm, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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. :)
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Nice idea srod 8) ...now code it and submit it to save freak some time :twisted: :P
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Post Reply