Is there a trick for change bgColor of Menubar & Statusb

Just starting out? Need help? Post your questions and find answers here.
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Is there a trick for change bgColor of Menubar & Statusb

Post by Tomi »

Is there a trick for change bgColor of Menubar and Statusbar :?:

Until non-change in window color: it is not any problem
but if do change window color then bgColor of Menubar and Statusbar Perhaps be Discordant with colored window.
Please if there is a trick for it.



Code: Select all

 If OpenWindow(0, 200, 200, 400, 350, "MenuBar Example", #PB_Window_SystemMenu)
    ;-
    SetWindowColor(0, #Blue)
    CreateStatusBar(0,WindowID(0)) 
    ;-
    If CreateMenu(0, WindowID(0))
      MenuTitle("Project")
        MenuItem(1, "Open")
        MenuBar()               
        MenuItem(4, "Close")
    EndIf
    Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
  EndIf

Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Windows only:

For Menu coloring, do a search for MF_OWNERDRAW.

For StatusBar coloring...

Code: Select all

#SB_SETBKCOLOR = #CCM_SETBKCOLOR 

If OpenWindow(0, 0, 0, 355, 180, "Statusbar Color", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  SetWindowColor(0, RGB(100, 100, 255)) 
  hStatus = CreateStatusBar(0, WindowID(0)) 
  SendMessage_(hStatus, #SB_SETBKCOLOR, 0, GetWindowColor(0)) 
  ;...Any XP theme will need to removed from StatusBar 
  If OSVersion() >= #PB_OS_Windows_XP
    If GetWindowTheme_(hStatus) 
      SetWindowTheme_(hStatus, @null.w, @null.w) 
    EndIf
  EndIf 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 
*** Edit to fix bug
Last edited by Sparkie on Tue Sep 09, 2008 12:45 am, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post by Tomi »

I was found 2 method about Statusbar in:
http://www.purebasic.fr/german/archive/ ... highlight=
but if XP style is use there no work. :oops:
--------
Hello
Thankful Sparkie
Your code nice work with and Without XP style . :)
I will check it on Vista too and reply next.
Ok, i will make search by keyword: "MF_OWNERDRAW" and reply next.
ty
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post by Tomi »

Thankful Sparkie again :)
Your code nice work on vista .

About menubar:
"srod" have a cool code for it in:
http://www.purebasic.fr/english/viewtop ... 94&start=0
However srod's code can't add color to bar of menu bar. :cry:
and it is only there is.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Coloring a menubar requires that you hook into Windows itself - nasty business! :wink: There is definitely code in the forums to do it, try searching for something like xp menus etc.
I may look like a mule, but I'm not a complete ass.
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post by Tomi »

hey srod welcome here :)
ok, i make search with "xp menu". :idea:





Edit:
srod it was a good keyword. ty :)
there is a good code with nice work.
http://www.purebasic.fr/english/viewtop ... light=menu
User avatar
Shardik
Addict
Addict
Posts: 2067
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

Sparkie,

thank you for your nice StatusBar coloring example. But I have to point out that it isn't sufficient to test for a windows version to be greater or equal to WindowsXP because nevertheless an error is reported if running on WinNT and Win9x. The compiler doesn't really care for that if-statement and nevertheless tries to find the UXTheme.DLL for GetWindowTheme_() and SetWindowTheme_(). It reports this error in a lengthy error message box listing all the directory paths in which it has searched for that DLL. In order to circumvent this problem you have to use OpenLibrary() and use SetWindowTheme with CallFunction():

Code: Select all

#SB_SETBKCOLOR = #CCM_SETBKCOLOR

Procedure.L DisableXPSkin(Handle.L)
  Protected LibHandle.L
  Protected Result.L

  LibHandle = OpenLibrary(#PB_Any, "UXTheme.DLL")

  If LibHandle = 0
    ProcedureReturn #False
  Else
    Result = CallFunction(LibHandle, "SetWindowTheme", Handle, @" ", @" ")
    CloseLibrary(LibHandle)

    If Result <> #S_OK
      ProcedureReturn #False
    EndIf
  EndIf

  ProcedureReturn #True
EndProcedure

If OpenWindow(0, 0, 0, 355, 180, "Statusbar Color", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowColor(0, RGB(100, 100, 255))
  hStatus = CreateStatusBar(0, WindowID(0))
  SendMessage_(hStatus, #SB_SETBKCOLOR, 0, GetWindowColor(0))
  ;...Any XP theme will need to be removed from StatusBar
  If OSVersion() >= #PB_OS_Windows_XP
    DisableXPSkin(hStatus)
  EndIf
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks Shardik :)

I usually code for Win2k and later so the NT/98 users will sometimes be out of luck with my code. I did edit the code to change the conditional If's. Not sure how NT/98 will react so let me know. ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Shardik
Addict
Addict
Posts: 2067
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

Sparkie,

your last change doesn't work either because UXTheme.DLL is searched for even if the statements after the If are not executed. But you were the first one who taught us how to disable the WinXP style of a single gadget in a Win9x/NT compatible way: :lol:
http://www.purebasic.fr/english/viewtop ... 16&start=2

I tried to integrate that code snippet into your above example:

Code: Select all

#SB_SETBKCOLOR = #CCM_SETBKCOLOR

If OpenWindow(0, 0, 0, 355, 180, "Statusbar Color", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowColor(0, RGB(100, 100, 255))
  hStatus = CreateStatusBar(0, WindowID(0))
  SendMessage_(hStatus, #SB_SETBKCOLOR, 0, GetWindowColor(0))
  ;...Any XP theme will need to be removed from StatusBar
  If OSVersion() >= #PB_OS_Windows_XP
    ; --- Win9x/WinNT compatible way
    ;     (doesn't break with error message if UXTheme.DLL is missing)
    LibHandle = OpenLibrary(#PB_Any, "UXTheme.DLL")
    If LibHandle
      If CallFunction(LibHandle, "GetWindowTheme", hStatus) <> 0
        CallFunction(LibHandle, "SetWindowTheme", hStatus, @null.w, @null.w)
      EndIf
      CloseLibrary(LibHandle)
    EndIf
  EndIf
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Thank you very much for your very useful and helpful contributions in this forum. I have lots of code snippets from you (and of course from others like srod, netmaestro, Trond, ...). I can never thank you enough for that. I have archived the most useful code snippets since 2003 (some sort of private code archive much like purearea.net) and they have already saved me enourmous amounts of time in my daily programming life... :wink:
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

THUNK!!! (as the palm of my hand hits my thick forehead). NOW I understand what you are saying Shardik. Man, sometimes I just plain scare myself :lol:

Thanks for your patience and for the kind words :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply