Colorizing CheckBoxes in XP...

Windows specific forum
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Colorizing CheckBoxes in XP...

Post by HeX0R »

The following example works perfectly BUT:
As soon as you activate WinXP Style on your pc and activate the compiler option xp-skin the fontcolor will be black
(well i guess it depends on the used winxp style, but at least it won't be the wished white color).

Any ideas ?

This only happens to checkboxes btw...

Code: Select all

OpenWindow(0,100,150,120,40,#PB_Window_SystemMenu,"")

Brush = CreateSolidBrush_($808080)

Procedure myCallback(WindowID, Message, wParam, lParam)
  Shared Brush
  Result = #PB_ProcessPureBasicEvents
  Select Message
  Case #WM_CTLCOLORSTATIC
    SetBkMode_(wParam,#TRANSPARENT)
    SetTextColor_(wParam, $FFFFFF)
    Result = Brush
  EndSelect
  ProcedureReturn Result
EndProcedure

SetWindowCallback(@myCallback())
CreateGadgetList(WindowID())
CheckBoxGadget(4, 10, 10,100, 20, "Test")

Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post by HeX0R »

Anyone ?

Where is our Windoze-Guru Sparkie these days ? On Holiday i guess :D
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Hi HeX0R :)

Not sure what's causing the problem but here's a quick "hack" if you can live with it for now. I'll take a closer look when I get a chance. ;)

This disables the XP Theme for the OptionGadget and allows the color changes.

Code: Select all

OpenWindow(0,100,150,120,40,#PB_Window_SystemMenu,"") 

Brush = CreateSolidBrush_($808080) 

Procedure myCallback(WindowID, Message, wParam, lParam) 
  Shared Brush 
  Result = #PB_ProcessPureBasicEvents 
  Select Message 
    Case #WM_CTLCOLORSTATIC 
      Debug "HI"
      SetBkMode_(wParam,#TRANSPARENT) 
      SetTextColor_(wParam, $FFFFFF) 
      Result = Brush 
  EndSelect 
  ProcedureReturn Result 
EndProcedure 

SetWindowCallback(@myCallback()) 
CreateGadgetList(WindowID()) 
CheckBoxGadget(4, 10, 10,100, 20, "Test") 

;--> Disable XP Theme for the OptionGadget
If OSVersion() = #PB_OS_Windows_XP
  OpenLibrary(0, "uxtheme.dll")
  CallFunction(0, "SetWindowTheme", GadgetID(4), @" ", @" ")
  CloseLibrary(0)
EndIf

Repeat 
Until WaitWindowEvent() = #PB_EventCloseWindow 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

Code: Select all

CallFunction(0, "SetWindowTheme", GadgetID(4), @" ", @" ")
That can randomly fail because the last two parameters should be pointers to null-terminated 16-bit unicode strings. Credit for tracking that down goes to Fred who helped fix a similar bug in my program :) I think this is the simplest fix:

Code: Select all

CallFunction(0, "SetWindowTheme", GadgetID(4), @null.w, @null.w)
Mat
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Thanks for the info MrMat :)

I'd go with Fred's recommendation in this case as well. ;)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

No problem. I think Fred's suggestion was to label a Data.w 0 and reference that but @null.w should do the same thing (since it's a pointer to a 16-bit zero) and it saves typing a few characters... :D
Mat
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post by HeX0R »

Haa, i knew you're the man!

Thanks a lot both of you, i surely can live with this "Hack".
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

As soon as you activate WinXP Style on your pc and activate the compiler option xp-skin the fontcolor will be black
Will it still turn to black if I don't acvtivate the option xp-skin in the compiler, and the user activates WinXP Style on his PC? :?
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post by HeX0R »

Nope!
Only if both is activated
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

isnt a checkbox a BUTTON? hence the #wm_colorstatic message wont be processed? doesnt the checkbox then nees to be ownerdrawn, and the Bkcolor set to "coloref" whatever?

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Post Reply