Menu coloring using SetMenuInfo_ () not working with 64 Bit?

Everything else that doesn't fall into one of the other PB categories.
es_91
Enthusiast
Enthusiast
Posts: 242
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Menu coloring using SetMenuInfo_ () not working with 64 Bit?

Post by es_91 »

What the heck is this? Yeah, I know it's a formal way to start a thread but I'm a bit p****d with the things right now.

This is a nice code showing how to color your menu bar. I used snippets from it several times, but I never noticed that it refuses delivery when compiling in 64 Bit.

It's the same with this code.

The system is Windows Vista SP2 64 Bit. The PureBasic version is 5.31.

As I said, it runs a yellow menu in 32 Bit, it runs a standard grey menu (and a #Null return from SetMenuInfo_ ()) in 64 Bit.

(Turning the structure members into Integer won't do the trick.)

Have I ignored an important information? Or, what else could it be? What do you think about this? Does the linked code work for you?
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Menu coloring using SetMenuInfo_ () not working with 64

Post by bbanelli »

es_91 wrote:What the heck is this? Yeah, I know it's a formal way to start a thread but I'm a bit p****d with the things right now.

This is a nice code showing how to color your menu bar. I used snippets from it several times, but I never noticed that it refuses delivery when compiling in 64 Bit.

It's the same with this code.

The system is Windows Vista SP2 64 Bit. The PureBasic version is 5.31.

As I said, it runs a yellow menu in 32 Bit, it runs a standard grey menu (and a #Null return from SetMenuInfo_ ()) in 64 Bit.

(Turning the structure members into Integer won't do the trick.)

Have I ignored an important information? Or, what else could it be? What do you think about this? Does the linked code work for you?

Code: Select all

Structure myMENUINFO
  cbSize.l
  fMask.l
  dwStyle.l
  cyMax.l
  hbrBack.l
  dwContextHelpId.l
  dwMenuData.l
   CompilerIf #PB_Compiler_Processor  = #PB_Processor_x64
    PB_Alignment2.b[12]
   CompilerEndIf  
EndStructure
http://www.forums.purebasic.com/english ... e0#p437628

Alternatively, just change this

Code: Select all

\cbSize = SizeOf(MENUINFO)
into

Code: Select all

\cbSize = SizeOf(MENUINFO)+12
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Menu coloring using SetMenuInfo_ () not working with 64

Post by luis »

The menu bar or the menu items ?

The first code does nothing here, using PB 5.31 x86 on Win7 x64.

On the other hand adding #MIM_APPLYTOSUBMENUS

Code: Select all

  \fMask = #MIM_BACKGROUND | #MIM_APPLYTOSUBMENUS
changes the background color of the menu items to yellow.

Still doesn't work on x64 though.

I don't think it's a terrific idea to change the bg color of a menu, not knowing what the foreground color is.

Well, I don't think it's a nice idea to change any color (OS themes are there for a good reason and you can piss off the user doing so), *unless* you owner draw all (maybe skinning your program entirely).


To make it work on x86 and x64 I've changed it as follow:

Code: Select all

#MIM_BACKGROUND = 2
#MIM_APPLYTOSUBMENUS =  $80000000 ; added

Structure myMENUINFO Align #PB_Structure_AlignC ; added
  cbSize.l
  fMask.l
  dwStyle.l
  cyMax.l 
  hbrBack.i ; changed to HBRUSH, handle size -> pointer size
  dwContextHelpId.l
  *dwMenuData ; changed to ULONG_PTR -> http://msdn.microsoft.com/en-us/library/windows/desktop/aa384255%28v=vs.85%29.aspx
EndStructure

Debug SizeOf(myMENUINFO)

hMenuBrushBG = CreateSolidBrush_(RGB(255,255,0))

With mi.myMENUINFO
  \cbSize = SizeOf(myMENUINFO)
  \fMask = #MIM_BACKGROUND | #MIM_APPLYTOSUBMENUS ; added
  \hbrBack = hMenuBrushBG
EndWith

If OpenWindow(0,0,0,500,250,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If CreateMenu(0, WindowID(0))
    MenuTitle("Menü 1")
      MenuItem(1,"Item 1")
    MenuTitle("Menü 2")
      MenuItem(2,"Item 2")
  EndIf
  
  Debug SetMenuInfo_(MenuID(0), mi)
  DrawMenuBar_(WindowID(0))
Repeat
EventID=WaitWindowEvent()
If EventID=#PB_Event_CloseWindow
  DeleteObject_(hMenuBrushBG)
  Quit=1
EndIf
Until Quit=1
EndIf
references:

MENUINFO
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Windows data types
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
"Have you tried turning it off and on again ?"
A little PureBasic review
es_91
Enthusiast
Enthusiast
Posts: 242
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: Menu coloring using SetMenuInfo_ () not working with 64

Post by es_91 »

Luis' code works absolutely fine. Thanks for doing some research, luis!

And bbanelli thank you for the try and for giving me a link to a fine RASHAD code!
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Re: Menu coloring using SetMenuInfo_ () not working with 64

Post by leodh »

Hi guys

How could this be done with popup menus ?

Leo
Regards
Leo
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Menu coloring using SetMenuInfo_ () not working with 64

Post by chi »

How could this be done with popup menus ?
same same but (a little bit) different ;)

Code: Select all

#MIM_BACKGROUND = 2
#MIM_APPLYTOSUBMENUS =  $80000000 ; added

Structure myMENUINFO Align #PB_Structure_AlignC ; added
  cbSize.l
  fMask.l
  dwStyle.l
  cyMax.l
  hbrBack.i ; changed to HBRUSH, handle size -> pointer size
  dwContextHelpId.l
  *dwMenuData ; changed to ULONG_PTR -> http://msdn.microsoft.com/en-us/library/windows/desktop/aa384255%28v=vs.85%29.aspx
EndStructure

Debug SizeOf(myMENUINFO)

hMenuBrushBG = CreateSolidBrush_(RGB(255,255,0))

With mi.myMENUINFO
  \cbSize = SizeOf(myMENUINFO)
  \fMask = #MIM_BACKGROUND | #MIM_APPLYTOSUBMENUS ; added
  \hbrBack = hMenuBrushBG
EndWith

If OpenWindow(0,0,0,500,250,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If CreatePopupMenu(0) ;changed
    MenuTitle("Menü 1")
    MenuItem(1,"Item 1")
    MenuTitle("Menü 2")
    MenuItem(2,"Item 2")
  EndIf
  
  Debug SetMenuInfo_(MenuID(0), mi)
  DrawMenuBar_(WindowID(0))
  Repeat
    EventID=WaitWindowEvent()
    
    If EventID = #PB_Event_RightClick ;changed
      DisplayPopupMenu(0, WindowID(0))
    EndIf
    
    If EventID=#PB_Event_CloseWindow
      DeleteObject_(hMenuBrushBG)
      Quit=1
    EndIf
  Until Quit=1
EndIf
Et cetera is my worst enemy
Post Reply