#include once "window9.bi"

Dim Shared g_Cf As CHARFORMAT

Function win9SetGadgetColor(ByVal gadget As HWND, ByVal COLBND As integer, ByVal COLText As Integer, ByVal flag As byte) As byte Export
	Dim sClass As USTRING  = GetClassName_(gadget)
	Select Case sClass
		Case "RichEdit20A" , "RichEdit20W"
			Select Case flag
				Case 2
					g_Cf.cbSize=SizeOf(g_Cf)
					g_Cf.dwMask=1073741824
					g_Cf.crTextColor= COLText
					SendMessage(gadget , WM_USER + 68,4, Cast(LPARAM,@g_Cf))
				Case 1
					SendMessage(Gadget, WM_USER + 67, 0,COLBND)
				Case 3
					g_Cf.cbSize=SizeOf(g_Cf)
					g_Cf.dwMask=1073741824
					g_Cf.crTextColor= COLText
					SendMessage(gadget , WM_USER + 68,4, Cast(LPARAM,@g_Cf))
					SendMessage(Gadget, WM_USER + 67, 0,COLBND)
			End Select
			Return 1
		Case "tooltips_class32"
			Select Case flag
				Case 1
					SendMessage(gadget,WM_USER+19,COLBND,0)
				Case 2
					SendMessage(gadget,WM_USER+20,COLText,0)
				Case 3
					SendMessage(gadget,WM_USER+19,COLBND,0)
					SendMessage(gadget,WM_USER+20,COLText,0)
			End Select
			Return 1
		Case "ComboBox"
			win9SetCurrentColors(COLBND ,COLText)
			Return 3
		Case "SysTreeView32"
			Select Case flag
				Case 1
					SendMessage(gadget,4381,0,cast(LPARAM,COLBND))
				Case 2
					SendMessage(gadget,4382,0,cast(LPARAM,COLText))
				Case 3
					SendMessage(gadget,4381,0,cast(LPARAM,COLBND))
					SendMessage(gadget,4382,0,cast(LPARAM,COLText))
			End Select
			Return 1
		Case "SysListView32"
			Select Case flag
				Case 1
					SendMessage(gadget,LVM_SETBKCOLOR,0,COLBND)
					SendMessage(gadget,LVM_SETTEXTBKCOLOR,0,COLBND)
				Case 2
					SendMessage(gadget,LVM_SETTEXTCOLOR ,0,COLText)
				Case 3
					SendMessage(gadget,LVM_SETBKCOLOR ,0,COLBND)
					SendMessage(gadget,LVM_SETTEXTBKCOLOR,0,COLBND)
					SendMessage(gadget,LVM_SETTEXTCOLOR ,0,COLText)
			End Select
			Return 1
			'  result=FBIDLISTBOX
			'Case "SysTabControl32"
			'  result=FBIDTABBERBOX
			'Case "msctls_trackbar32"
			'  result=FBIDTRACKBAR
		Case "ScrollBar"
			win9SetCurrentColors(COLBND ,COLText)
			Return 2
			'  result=FBIDSCROLLBAR
		Case "msctls_progress32"
			Select Case flag
				Case 1
					SendMessage(gadget,8193,0,COLBND)
				Case 2
					SendMessage(gadget,1033 ,0,COLText)
				Case 3
					SendMessage(gadget,8193 ,0,COLBND)
					SendMessage(gadget,1033 ,0,COLText)
			End Select
		Case "msctls_statusbar32"
			SendMessage(gadget,&h2001,0,COLBND)
		Case "Static" , "Button"
			InvalidateRect(gadget,0,1)
		Case "ExplorerGadget"
			dim hwndEG as HWND = *cast(HWND ptr,GetProp(gadget,"addparam60000"))
			Select Case flag
				Case 1
					SendMessage(hwndEG,LVM_SETBKCOLOR,0,COLBND)
					SendMessage(hwndEG,LVM_SETTEXTBKCOLOR,0,COLBND)
				Case 2
					SendMessage(hwndEG,LVM_SETTEXTCOLOR ,0,COLText)
				Case 3
					SendMessage(hwndEG,LVM_SETBKCOLOR ,0,COLBND)
					SendMessage(hwndEG,LVM_SETTEXTBKCOLOR,0,COLBND)
					SendMessage(hwndEG,LVM_SETTEXTCOLOR ,0,COLText)
			End Select
			Return 4
	End Select
	If Mid(sClass,1,11)="CLASSCLASS_" Or Mid(sClass,1,9)="Container" Then
		WindowColor(gadget,COLBND)
	End If
	Return 0
End Function
