It is currently Wed Feb 26, 2020 11:48 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: CheckBoxGadget BackColor
PostPosted: Wed Nov 29, 2006 8:24 am 
Offline
User
User

Joined: Sat Jan 08, 2005 7:46 pm
Posts: 46
Hi and good morning!

I am not sure if I am wrong or not. But I Think it is not possible to change
the Gadget_BackColor of a ChrckBoxGadget by using
SetGadgetColor(#Gadget, FarbTyp, Farbe).

Is there any possibility for changeing the "BackColor" by API.

Martin


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 29, 2006 8:39 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8027
Location: Fort Nelson, BC, Canada
Do you mean the actual box or the text that appears beside it?

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 29, 2006 8:47 am 
Offline
User
User

Joined: Sat Jan 08, 2005 7:46 pm
Posts: 46
I mean the Box! not the text. But if it is possible to do both it is much more better.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 29, 2006 9:00 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8027
Location: Fort Nelson, BC, Canada
The checkbox gadget is actually a button control that has the BS_CHECKBOX style, so SetGadgetColor isn't going to work on it.

For the text it can be done by reacting To the WM_CTLCOLORSTATIC message For the control by SetBkMode_(wParam,#TRANSPARENT), SetTextColor_(wParam,<desired text color>), And returning a SolidBrush your desired background color. For the box I've never tried to do that, so I'm not sure but it can probably be managed somehow. I'll study on it for a bit and let you know if something occurs.
Code:
Global GadgetFrg=#Black, GadgetBkg = CreateSolidBrush_(#Green)

Procedure WindowProc(hWnd, Msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  If Msg=#WM_CTLCOLORSTATIC
    If GetDlgCtrlID_(lparam) = 1
      SetBkMode_(wParam,#TRANSPARENT)
      SetTextColor_(wParam,GadgetFrg)
      result = GadgetBkg
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,260,160,"test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowCallback(@WindowProc())
CreateGadgetList(WindowID(0))
CheckBoxGadget(1,10,20,245,20,"Checkbox gadget with a green background")

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

DeleteObject_(GadgetBkg)

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 29, 2006 9:45 am 
Offline
User
User

Joined: Sat Jan 08, 2005 7:46 pm
Posts: 46
Thanks a lot for helping!!!!!!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 29, 2006 10:26 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8027
Location: Fort Nelson, BC, Canada
OK, got something. Here's an example of coloring all elements of the checkbox including background, text, box background and checkmark:
Code:
;====================================================
; Program:       CheckBox Colors Demo
; Author:        netmaestro
; Date:          November 29, 2006
;====================================================

Global GadgetBkg  = CreateSolidBrush_(#Green)
Global BoxBkg     = CreateSolidBrush_(#Yellow)
Global Checkcolor = #Blue
Global Textcolor  = #Red
Global NullPen    = CreatePen_(#PS_NULL, 0, 0)

Procedure GadgetProc(hwnd, msg, wparam, lparam)
  Shared oldproc
  result = CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
  Select msg
    Case  #WM_PAINT, #WM_LBUTTONUP, #WM_LBUTTONDOWN
      dc = GetDC_(hwnd)
      SelectObject_(dc, BoxBkg)
      SelectObject_(dc, NullPen)
      Rectangle_(dc,2,5,12,15)
      If GetGadgetState(GetDlgCtrlID_(hwnd))
        Restore check
         For i = 1 To 21
           Read x
           Read y
           SetPixel_(dc,x+2,y+5, CheckColor)
         Next   
      EndIf
      ReleaseDC_(hwnd, dc);
  EndSelect
  ProcedureReturn result
EndProcedure

Procedure WindowProc(hWnd, Msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  If Msg=#WM_CTLCOLORSTATIC
    If GetDlgCtrlID_(lparam) = 1
      SetBkMode_(wParam,#TRANSPARENT)
      SetTextColor_(wParam, Textcolor)
      result = GadgetBkg
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,260,160,"test",#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowCallback(@WindowProc())
CreateGadgetList(WindowID(0))
CheckBoxGadget(1,10,20,245,20,"Checkbox gadget with a green background")
oldproc = SetWindowLong_(GadgetID(1),#GWL_WNDPROC,@GadgetProc())

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

DeleteObject_(GadgetBkg)
DeleteObject_(BoxBkg)
DeleteObject_(NullPen)

DataSection
  check:
  Data.l 7,1,6,2,7,2,1,3,5,3,6,3,7,3,1,4,2,4,4,4,5,4,6,4,1,5,2,5,3,5,4,5,5,5,2,6,3,6,4,6,3,7
EndDataSection

_________________
Veni, vidi, vici.


Last edited by netmaestro on Wed Nov 29, 2006 10:48 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 29, 2006 10:43 am 
Offline
User
User

Joined: Sat Jan 08, 2005 7:46 pm
Posts: 46
Oh that is great: exactly what I am looking for.

Thank you very much


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Nov 29, 2006 10:56 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8027
Location: Fort Nelson, BC, Canada
One caveat, if you compile with xp skin support enabled, the foreground text color will be always black, but the background, box background and checkmark colors will all work as selected. If it's a problem I can probably think up a solution.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: CheckBoxGadget BackColor
PostPosted: Wed Jan 20, 2010 11:55 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 6:51 pm
Posts: 778
Location: NC, USA
Neat idea.

But has anyone figured how to change the background color of the check box only when it has the focus (or is the active gadget)?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Evil1 and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye