(1) It uses a deprecated command.
(2) It's hard-coded to use a window ID of 0.
(3) Doesn't work with frames on a PanelGadget.
(4) Has no error-checking for lpBuffer and hThemeButton.
Code: Select all
Procedure FrameGadgetColorProc(hWnd,uMsg,wParam,lParam)
Structure FrameColor
lpPrevFunc.i
clrText.l
bThemeXP.b
EndStructure
*frmex.FrameColor=GetWindowLongPtr_(hWnd,#GWL_USERDATA)
Select uMsg
Case #WM_NCDESTROY
FreeMemory(*frmex)
ProcedureReturn 0
Case #WM_PAINT
activewin=GetActiveWindow()
If activewin<>-1
hdc=BeginPaint_(hWnd,ps.PAINTSTRUCT)
SelectObject_(hdc,SendMessage_(hWnd,#WM_GETFONT,0,0))
text$=GetGadgetText(GetDlgCtrlID_(hWnd))
GetTextExtentPoint32_(hdc,text$,Len(text$),fts.SIZE)
GetClientRect_(hWnd,wrc.RECT)
SetRect_(wrc,wrc\left,(wrc\top+fts\cy)/2,wrc\right,wrc\bottom)
If OSVersion()=>#PB_OS_Windows_XP And IsThemeActive_() And IsAppThemed_() And *frmex\bThemeXP
lpBuffer=AllocateMemory(14)
If lpBuffer
PokeS(lpBuffer,"Button",-1,#PB_Unicode)
hThemeButton=OpenThemeData_(WindowID(activewin),lpBuffer)
If hThemeButton
DrawThemeBackground_(hThemeButton,hdc,4,1,wrc,0)
CloseThemeData_(hThemeButton)
EndIf
FreeMemory(lpBuffer)
EndIf
Else
DrawEdge_(hdc,wrc,#EDGE_ETCHED,#BF_RECT)
EndIf
c=GetSysColor_(#COLOR_3DFACE)
parent=GetParent_(hWnd)
grandparent=GetParent_(parent)
If grandparent
gad=GetDlgCtrlID_(grandparent)
If GadgetType(gad)=#PB_GadgetType_Panel
If StartDrawing(WindowOutput(activewin))
c=Point(GadgetX(gad)+3,GadgetY(gad)+3)
StopDrawing()
EndIf
EndIf
EndIf
SetBkColor_(hdc,c)
SetTextColor_(hdc,*frmex\clrText)
TextOut_(hdc,9,0,text$,Len(text$))
EndPaint_(hWnd,ps)
EndIf
ProcedureReturn 0
EndSelect
ProcedureReturn CallWindowProc_(*frmex\lpPrevFunc,hWnd,uMsg,wParam,lParam)
EndProcedure
Procedure FrameGadgetColor(gad,x,y,w,h,text$,col)
dvi.DLLVERSIONINFO\cbsize=SizeOf(DLLVERSIONINFO)
FrameGadget(gad,x,y,w,h,text$)
*frmex.FrameColor=AllocateMemory(SizeOf(FrameColor))
*frmex\lpPrevFunc=SetWindowLongPtr_(GadgetID(gad),#GWL_WNDPROC,@FrameGadgetColorProc())
*frmex\clrText=col
hInstance=OpenLibrary(#PB_Any,"comctl32.dll")
If hInstance
CallFunction(hInstance,"DllGetVersion",@dvi)
If dvi\dwMajorVersion=6 : *frmex\bThemeXP=#True : EndIf
CloseLibrary(hInstance)
EndIf
SetWindowLongPtr_(GadgetID(gad),#GWL_USERDATA,*frmex)
ProcedureReturn GadgetID(gad)
EndProcedure
OpenWindow(0,200,200,420,150,"Window",#PB_Window_SystemMenu)
PanelGadget(0,10,10,210,130)
AddGadgetItem(0,-1,"Panel")
FrameGadgetColor(1,10,10,180,85,"Blue",#Blue)
CloseGadgetList()
FrameGadgetColor(2,230,23,180,118,"Red",RGB(220,0,0))
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow