[N/A] Combobox Colour
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
[N/A] Combobox Colour
PB 5.21 LTS supports SetGadgetColor() (#PB_Gadget_BackColor and #PB_Gadget_FrontColor) but PB5.30 does not?
Last edited by IdeasVacuum on Sun Oct 26, 2014 1:54 pm, edited 1 time in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: [PB5.30]Combobox Colour
Using PB 5.31 Beta 4. I looked and the Combobox doesn't support it.
Then I went and looked with PB 5.21 LTS, the help file mentions no support for it. Running code doesn't show it to be support either.
Then I went and looked with PB 5.21 LTS, the help file mentions no support for it. Running code doesn't show it to be support either.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: [PB5.30]Combobox Colour
Yeah, my mistake - my code has:
...but before that:
Gnozal's lib 
Code: Select all
SetGadgetColor(#ComboSize, #PB_Gadget_BackColor, igListBackColour)Code: Select all
PureCOLOR_SetGadgetColor(#ComboSize, igTextColour, igListBackColour)IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: [PB5.30]Combobox Colour
Why don't you try with this, it is a very solid example and you can adapt it easily -> http://www.purebasic.fr/english/viewtopic.php?t=14334IdeasVacuum wrote:Yeah, my mistake - my code has:...but before that:Code: Select all
SetGadgetColor(#ComboSize, #PB_Gadget_BackColor, igListBackColour)Gnozal's libCode: Select all
PureCOLOR_SetGadgetColor(#ComboSize, igTextColour, igListBackColour)
Code compatible with PB5.3
Code: Select all
Global OriginProc.l, OriginProc1.l,lb,icontouse,hbrushDefault.l,hbrushSelected.l,hbrushSelectedFocus .l
hbrushDefault = CreateSolidBrush_(#White)
hbrushSelected = CreateSolidBrush_(RGB(200, 255, 200))
hbrushSelectedFocus = CreateSolidBrush_(RGB(0, 0, 80))
#DI_NORMAL = $0003
#ODS_SELECTED=1
#ODS_GRAYED=2
#ODS_DISABLED=4
#ODS_CHECKED=8
#ODS_FOCUS=16
#ODS_DEFAULT= 32
#ODS_COMBOBOXEDIT= 4096
#ODT_STATIC = 5
#SS_OWNERDRAW=13
Procedure comboproc(hwnd,msg,wParam,lParam)
Select msg
Case #WM_DRAWITEM
textbuffer.s=Space(255)
listb=GetWindow_(hwnd,#GW_CHILD)
*lpdis.DRAWITEMSTRUCT=lParam
*lptris.DRAWITEMSTRUCT=*lpdis.DRAWITEMSTRUCT
Select *lpdis\CtlType
Case #ODT_COMBOBOX
Select *lpdis\itemState
Case #ODS_SELECTED
dtFlags = #DT_LEFT | #DT_VCENTER
currentBrush = CreateSolidBrush_(RGB(0, 0, 80))
currentTextColor = #White
Case #ODS_SELECTED | #ODS_FOCUS
dtFlags = #DT_LEFT | #DT_VCENTER
currentBrush = hbrushSelectedFocus
currentTextColor = #White
Case 0
dtFlags = #DT_LEFT | #DT_VCENTER
currentBrush = #White
currentTextColor = RGB(127, 0, 127)
EndSelect
SendMessage_(*lpdis\hwndItem,#CB_GETLBTEXT,*lpdis\itemID,@textbuffer)
cbText$=PeekS(@textbuffer)
FillRect_(*lpdis\hdc, *lpdis\rcItem, currentBrush)
SetBkMode_(*lpdis\hdc, #TRANSPARENT)
SetTextColor_(*lpdis\hdc, currentTextColor)
*lpdis\rcItem\left+32
DrawText_(*lpdis\hdc, cbText$, Len(cbText$), *lptris\rcItem, dtFlags)
hbmpPicture = SendMessage_(*lpdis\hwndItem,#CB_GETITEMDATA, *lpdis\itemID,0)
hdcMem = CreateCompatibleDC_(*lpdis\hdc)
hbmpOld = SelectObject_(hdcMem, hbmpPicture)
BitBlt_(*lpdis\hdc, *lpdis\rcItem\left-32, *lpdis\rcItem\top, *lpdis\rcItem\right - *lpdis\rcItem\left,*lpdis\rcItem\bottom - *lpdis\rcItem\top, hdcMem, 0, 0, #SRCCOPY)
SelectObject_(hdcMem, hbmpOld);
DeleteDC_(hdcMem)
ProcedureReturn 0
EndSelect
EndSelect
ProcedureReturn CallWindowProc_(OriginProc1,hwnd,msg,wParam,lParam)
EndProcedure
Procedure ListboxProc( hwnd, msg,wParam,lParam)
Select msg
Case #WM_DRAWITEM
textbuffer.s=Space(255)
listb=GetWindow_(hwnd,#GW_CHILD)
*lpdis.DRAWITEMSTRUCT=lParam
*lptris.DRAWITEMSTRUCT=*lpdis.DRAWITEMSTRUCT
Select *lpdis\CtlType
Case #ODT_LISTBOX
Select *lpdis\itemState
Case #ODS_SELECTED
dtFlags = #DT_LEFT | #DT_VCENTER
currentBrush = CreateSolidBrush_(RGB(0, 0, 80))
currentTextColor = #White
Case #ODS_SELECTED | #ODS_FOCUS
dtFlags = #DT_LEFT | #DT_VCENTER
currentBrush = hbrushSelectedFocus
currentTextColor = #White
Case 0
dtFlags = #DT_LEFT | #DT_VCENTER
currentBrush = #White
currentTextColor = RGB(127, 0, 127)
EndSelect
SendMessage_(*lpdis\hwndItem,#LB_GETTEXT,*lpdis\itemID,@textbuffer)
lbText$=PeekS(@textbuffer)
FillRect_(*lpdis\hdc, *lpdis\rcItem, currentBrush)
SetBkMode_(*lpdis\hdc, #TRANSPARENT)
SetTextColor_(*lpdis\hdc, currentTextColor)
*lpdis\rcItem\left+32
DrawText_(*lpdis\hdc, lbText$, Len(lbText$), *lptris\rcItem, dtFlags)
hbmpPicture = SendMessage_(*lpdis\hwndItem,#LB_GETITEMDATA, *lpdis\itemID,0)
hdcMem = CreateCompatibleDC_(*lpdis\hdc)
hbmpOld = SelectObject_(hdcMem, hbmpPicture)
BitBlt_(*lpdis\hdc, *lpdis\rcItem\left-32, *lpdis\rcItem\top, *lpdis\rcItem\right - *lpdis\rcItem\left,*lpdis\rcItem\bottom - *lpdis\rcItem\top, hdcMem, 0, 0, #SRCCOPY)
SelectObject_(hdcMem, hbmpOld);
DeleteDC_(hdcMem)
ProcedureReturn 0
EndSelect
EndSelect
ProcedureReturn CallWindowProc_(OriginProc,hwnd,msg,wParam,lParam)
EndProcedure
ProcedureDLL Listbox(number,x,y,width,height,parent)
window=OpenWindow(#PB_Any,x,y,width,height,"",#PB_Window_BorderLess|#PB_Window_Invisible)
SetWindowLong_(WindowID(window),#GWL_STYLE, #WS_CHILD|#WS_DLGFRAME|#WS_EX_CLIENTEDGE|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
SetParent_(WindowID(window),parent)
ShowWindow_(WindowID(window),#SW_SHOW)
CreateGadgetList(WindowID(window))
lb=ListViewGadget(#PB_Any,0,0,width,height,#LBS_OWNERDRAWFIXED|#LBS_HASSTRINGS)
OriginProc= SetWindowLong_(WindowID(window), #GWL_WNDPROC, @ListboxProc())
SendMessage_(GadgetID(lb), #LB_SETITEMDATA, 0, icontouse)
SendMessage_(GadgetID(lb),#LB_SETITEMHEIGHT,0,32)
ProcedureReturn lb
EndProcedure
ProcedureDLL ComboBoxEx(number,x,y,width,height,parent)
combowindow=OpenWindow(#PB_Any,x,y,width,height,"",#PB_Window_BorderLess|#PB_Window_Invisible)
SetWindowLong_(WindowID(combowindow),#GWL_STYLE, #WS_CHILD|#WS_DLGFRAME|#WS_EX_CLIENTEDGE|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
SetParent_(WindowID(combowindow),parent)
ShowWindow_(WindowID(combowindow),#SW_SHOW)
CreateGadgetList(WindowID(combowindow))
combo=ComboBoxGadget(#PB_Any, 0,0,width,height,#CBS_OWNERDRAWFIXED|#CBS_HASSTRINGS)
SendMessage_(GadgetID(combo),#CB_SETITEMHEIGHT,-1,32)
SendMessage_(GadgetID(combo),#CB_SETITEMHEIGHT,0,32)
OriginProc1= SetWindowLong_(WindowID(combowindow), #GWL_WNDPROC, @comboproc())
ProcedureReturn combo
EndProcedure
ProcedureDLL ColorComboBox(number,x,y,width,height,parent)
combowindow=OpenWindow(#PB_Any,x,y,width,height,"",#PB_Window_BorderLess|#PB_Window_Invisible)
SetWindowLong_(WindowID(combowindow),#GWL_STYLE, #WS_CHILD|#WS_DLGFRAME|#WS_EX_CLIENTEDGE|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
SetParent_(WindowID(combowindow),parent)
ShowWindow_(WindowID(combowindow),#SW_SHOW)
CreateGadgetList(WindowID(combowindow))
combo=ComboBoxGadget(#PB_Any, 0,0,width,height,#CBS_OWNERDRAWFIXED|#CBS_HASSTRINGS)
SendMessage_(GadgetID(combo),#CB_SETITEMHEIGHT,-1,20)
SendMessage_(GadgetID(combo),#CB_SETITEMHEIGHT,0,20)
OriginProc1= SetWindowLong_(WindowID(combowindow), #GWL_WNDPROC, @comboproc())
ProcedureReturn combo
EndProcedure
ProcedureDLL AddListboxItem(listbox.l,Position.l,text.s,imageid.l)
If Position =-1
itemreturn=SendMessage_(GadgetID(listbox),#LB_ADDSTRING,0,text)
SendMessage_(GadgetID(listbox),#LB_SETITEMDATA,itemreturn,imageid)
ProcedureReturn itemreturn
Else
itemreturn=SendMessage_(GadgetID(listbox),#LB_INSERTSTRING,Position,text)
SendMessage_(GadgetID(listbox),#LB_SETITEMDATA,itemreturn,imageid)
ProcedureReturn itemreturn
EndIf
EndProcedure
ProcedureDLL AddCBItem(combobox.l,Position.l,text.s,imageid.l)
If Position =-1
itemreturn=SendMessage_(GadgetID(combobox),#CB_ADDSTRING,0,text)
SendMessage_(GadgetID(combobox),#CB_SETITEMDATA,itemreturn,imageid)
ProcedureReturn itemreturn
Else
itemreturn=SendMessage_(GadgetID(combobox),#CB_INSERTSTRING,Position,text)
SendMessage_(GadgetID(combobox),#CB_SETITEMDATA,itemreturn,imageid)
ProcedureReturn itemreturn
EndIf
EndProcedure
ProcedureDLL AddColorCBItem(combobox.l,Position.l,text.s,ColorID.l)
ic = CreateImage(#PB_Any,16,16)
icon=ImageID(ic)
StartDrawing(ImageOutput(ic))
DrawImage(icon,0,0)
Box(0,0,16,16,ColorID)
StopDrawing()
If Position =-1
itemreturn=SendMessage_(GadgetID(combobox),#CB_ADDSTRING,0,text)
SendMessage_(GadgetID(combobox),#CB_SETITEMDATA,itemreturn,icon)
ProcedureReturn itemreturn
Else
itemreturn=SendMessage_(GadgetID(combobox),#CB_INSERTSTRING,Position,text)
SendMessage_(GadgetID(combobox),#CB_SETITEMDATA,itemreturn,icon)
ProcedureReturn itemreturn
EndIf
EndProcedure
UseJPEGImageDecoder()
icontouse=CreateImage(10,32,32)
StartDrawing(ImageOutput(10))
DrawImage(icontouse,0,0)
Box(0,0,32,32,#White)
Box(0,0,20,20,#Red)
StopDrawing()
If OpenWindow(0,0,0,322,375,"StringGadget Flags",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
CreateGadgetList(WindowID(0))
List=Listbox(0,8,10,200,200,WindowID(0))
com=ComboBoxEx(8,8,215,300,300,WindowID(0))
colcb=ColorComboBox(10,8,270,200,200,WindowID(0))
nextcolcb=ColorComboBox(11,8,300,200,200,WindowID(0))
For i = 1 To 11
AddColorCBItem(colcb,-1,"Item " + Str(i) + " of the Combo",RGB(i*30,i*20,i*30))
Next
For i = 1 To 11
AddCBItem(com,-1,"Item " + Str(i) + " of the Combo",icontouse)
Next
For i = 1 To 11
AddListboxItem(List,-1,"Item " + Str(i) + " of the Listview",icontouse)
Next
AddColorCBItem(nextcolcb,-1,"Red",#Red)
AddColorCBItem(nextcolcb,-1,"Blue",#Blue)
AddColorCBItem(nextcolcb,-1,"Green",#Green)
AddColorCBItem(nextcolcb,-1,"Yellow",#Yellow)
AddColorCBItem(nextcolcb,-1,"Aqua",$FFF034)
Repeat
EventID.l=WaitWindowEvent()
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
Case List
Debug "rock on"
Case com
Debug " on"
EndSelect
Case #WM_CLOSE
Quit=1
DeleteObject_(hbrushDefault)
DeleteObject_(hbrushSelected)
DeleteObject_(hbrushSelectedFocus)
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf -
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: [N/A] Combobox Colour
Thanks, but it only takes a tiny bit of code to fake a ComboBox with a ListView + Button
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: [N/A] Combobox Colour
Code: Select all
Global OldProc
Structure ComboColors
Background.i
TextColor.i
Transparent.l
EndStructure
Structure ComboBox
State.l
Parameters.ComboColors
EndStructure
Global Dim ComboBoxConf.ComboBox(5)
Procedure ComboCallBack( hWnd.l, Message.l, wParam.l, lParam.l )
If (Message = #WM_CTLCOLOREDIT) Or (Message = #WM_CTLCOLORLISTBOX)
whaGadget = GetDlgCtrlID_(hWnd)
If IsGadget(whaGadget)
SetBkMode_(wParam, ComboBoxConf(whaGadget)\Parameters\Transparent)
SetTextColor_(wParam, ComboBoxConf(whaGadget)\Parameters\TextColor)
SetBkColor_(wParam, ComboBoxConf(whaGadget)\Parameters\Background)
Result = ComboBoxConf(whaGadget)\Parameters\Background
EndIf
Else
Result = CallWindowProc_(OldProc, hWnd, Message, wParam, lParam )
EndIf
ProcedureReturn Result
EndProcedure
Procedure.b SetComboBoxColors(Gadget, BackColor = #White, TextColor = #Black, Transparency.l = #TRANSPARENT)
OldProc = SetWindowLongPtr_(GadgetID(Gadget), #GWL_WNDPROC, @ComboCallBack())
If OldProc
ComboBoxConf(Gadget)\State = 1
ComboBoxConf(Gadget)\Parameters\Background = CreateSolidBrush_(BackColor)
ComboBoxConf(Gadget)\Parameters\TextColor = TextColor
ComboBoxConf(Gadget)\Parameters\Transparent = Transparency
ProcedureReturn 1
EndIf
EndProcedure
Procedure.b RemComboBoxColors(Gadget)
If ComboBoxConf(Gadget)\State
ComboBoxConf(Gadget)\State = 0
If SetWindowLongPtr_(GadgetID(Gadget), #GWL_WNDPROC, 0) : ProcedureReturn 1 : EndIf
EndIf
EndProcedure
If OpenWindow( 0, 200,400,200,100, "", #PB_Window_SystemMenu)
ComboBoxGadget( 1, 10, 10, 180, 24);, #PB_ComboBox_Editable )
AddGadgetItem(1, -1, "123" )
AddGadgetItem(1, -1, "456" )
AddGadgetItem(1, -1, "789" )
SetGadgetState(1,0)
SetComboBoxColors(1, $84E27C, $00D7FF)
ComboBoxGadget( 2, 10, 40, 180, 24, #PB_ComboBox_Editable )
AddGadgetItem(2, -1, "123" )
AddGadgetItem(2, -1, "456" )
AddGadgetItem(2, -1, "789" )
SetGadgetState(2,0)
SetComboBoxColors(2, $DCF8FF, $2222B2)
; RemComboBoxColors(1)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIfʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: [N/A] Combobox Colour
Tweaked it up a little and have included control to remove color from combobox gadgets.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: [N/A] Combobox Colour
Code: Select all
; Original bei Thunder93
; Updated for #PB_Any GadgetIDs
Global OldProc
Structure ComboColors
Background.i
TextColor.i
Transparent.l
EndStructure
Structure ComboBox
State.l
Parameters.ComboColors
EndStructure
Global NewMap ComboBoxConf.ComboBox()
Procedure ComboCallBack( hwnd.l, message.l, wParam.l, lParam.l )
If (message = #WM_CTLCOLOREDIT) Or (message = #WM_CTLCOLORLISTBOX)
whaGadget = GetDlgCtrlID_(hwnd)
If IsGadget(whaGadget)
If FindMapElement(ComboBoxConf(), Str(whaGadget))
SetBkMode_(wParam, ComboBoxConf()\Parameters\Transparent)
SetTextColor_(wParam, ComboBoxConf()\Parameters\TextColor)
SetBkColor_(wParam, ComboBoxConf()\Parameters\Background)
Result = ComboBoxConf()\Parameters\Background
EndIf
EndIf
Else
Result = CallWindowProc_(OldProc, hwnd, message, wParam, lParam )
EndIf
ProcedureReturn Result
EndProcedure
Procedure.b SetComboBoxColors(gadget, BackColor = #White, TextColor = #Black, Transparency.l = #TRANSPARENT)
OldProc = SetWindowLongPtr_(GadgetID(gadget), #GWL_WNDPROC, @ComboCallBack())
If OldProc
AddMapElement(ComboBoxConf(), Str(gadget))
ComboBoxConf()\State = 1
ComboBoxConf()\Parameters\Background = CreateSolidBrush_(BackColor)
ComboBoxConf()\Parameters\TextColor = TextColor
ComboBoxConf()\Parameters\Transparent = Transparency
ProcedureReturn 1
EndIf
EndProcedure
Procedure.b RemComboBoxColors(gadget)
If FindMapElement(ComboBoxConf(), Str(gadget))
If ComboBoxConf()\State
ComboBoxConf()\State = 0
If SetWindowLongPtr_(GadgetID(gadget), #GWL_WNDPROC, 0) : ProcedureReturn 1 : EndIf
EndIf
EndIf
EndProcedure
CompilerIf #PB_Compiler_IsMainFile
If OpenWindow( 0, 200,400,200,100, "", #PB_Window_SystemMenu)
CB1 = ComboBoxGadget( #PB_Any, 10, 10, 180, 24);, #PB_ComboBox_Editable )
AddGadgetItem(CB1, -1, "123" )
AddGadgetItem(CB1, -1, "456" )
AddGadgetItem(CB1, -1, "789" )
SetGadgetState(CB1,0)
SetComboBoxColors(CB1, $84E27C, $00D7FF)
CB2 = ComboBoxGadget( #PB_Any, 10, 40, 180, 24, #PB_ComboBox_Editable )
AddGadgetItem(CB2, -1, "123" )
AddGadgetItem(CB2, -1, "456" )
AddGadgetItem(CB2, -1, "789" )
SetGadgetState(CB2,0)
SetComboBoxColors(CB2, $DCF8FF, $2222B2, 50)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
CompilerEndIf
"Daddy, I'll run faster, then it is not so far..."

