Page 1 of 1

Is there a trick for change bgColor of Menubar & Statusb

Posted: Fri Sep 05, 2008 8:41 am
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


Posted: Fri Sep 05, 2008 12:26 pm
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

Posted: Fri Sep 05, 2008 1:16 pm
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

Posted: Fri Sep 05, 2008 2:58 pm
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.

Posted: Fri Sep 05, 2008 3:09 pm
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.

Posted: Fri Sep 05, 2008 4:09 pm
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

Posted: Mon Sep 08, 2008 3:30 pm
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

Posted: Tue Sep 09, 2008 12:49 am
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. ;)

Posted: Tue Sep 09, 2008 8:19 am
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:

Posted: Tue Sep 09, 2008 11:35 pm
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 :)