Page 1 of 1

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 :)