It is currently Mon Sep 28, 2020 9:04 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: FrameGadget text color
PostPosted: Fri Oct 06, 2017 1:44 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
Windows XP shows FrameGadgets with blue text, but Windows 7 has black. Does anyone know how to change the text color manually? I assume a callback or ownerdraw situation? Thanks.

Bonus: If the border color of a FrameGadget could be changed too, that would be great. :)


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget text color
PostPosted: Fri Oct 06, 2017 2:23 pm 
Offline
Moderator
Moderator

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1112
Location: Gernsbach (Germany)
http://www.rsbasic.de/winapi-library/ :arrow: http://www.rsbasic.de/aktualisierung/wi ... A4ndern.pb

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget text color
PostPosted: Sat Oct 07, 2017 3:19 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
Thanks, RSBasic! :)

However, that code has issues:

(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.

So, here is my optimized solution which fixes all the above:

[Edit] A better and shorter solution is here: viewtopic.php?f=12&t=69356

Code:
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


Last edited by Dude on Sun Oct 08, 2017 1:21 am, edited 7 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget text color
PostPosted: Sat Oct 07, 2017 4:46 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3670
Too much code for simple task :wink: :D
Code:
OpenWindow(0,200,200,420,150,"Window",#PB_Window_SystemMenu)
PanelGadget(0,10,10,210,130)
AddGadgetItem(0,-1,"Panel")
FrameGadget(1,10,10,180,85," Blue ")
txt = TextGadget(#PB_Any,10+8,10,30,20," Blue ")
SetGadgetColor(txt,#PB_Gadget_FrontColor,#Blue)
CloseGadgetList()
FrameGadget(2,230,23,180,118," Red ")
txt = TextGadget(#PB_Any,230+8,23,30,20," Red ")
SetGadgetColor(txt,#PB_Gadget_FrontColor,#Red)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget text color
PostPosted: Sat Oct 07, 2017 6:46 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 17, 2009 10:51 pm
Posts: 1387
Location: Nashville
RASHAD wrote:
Too much code for simple task :wink: :D



You obviously have never had a job where you get paid per line of code. :mrgreen:


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget text color
PostPosted: Sat Oct 07, 2017 6:57 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
RASHAD wrote:
Too much code for simple task :wink: :D

Hold it -- not so fast this time, Rashad! :twisted:

You need to test your code with all themes and window colors, etc.

Here's what your code produces on my test machine:

Image


Last edited by Dude on Sat Oct 07, 2017 1:12 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget text color
PostPosted: Sat Oct 07, 2017 8:58 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3670
Dude just increase the width of the TextGadget ex.from 30 to 50
And still there are many tech. to do the job
Try
- DrawEdge_(hDC,r,#EDGE_ETCHED,#BF_RECT)
- Rect_()
- RoundRect_()

Search the forum for examples made by NM,Danilo or srod

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget text color
PostPosted: Sat Oct 07, 2017 1:56 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
RASHAD wrote:
Dude just increase the width of the TextGadget ex.from 30 to 50

Thanks Rashad, I'll work on it. :)


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget text color
PostPosted: Sat Oct 07, 2017 2:45 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3670
Should do it for all circumstances
PB 5.61 x86 Windos 10 x64
Code:
OpenWindow(0,200,200,420,150,"Window", #PB_Window_SystemMenu)
If LoadFont(0,"Broadway",12)
  SetGadgetFont(#PB_Default, FontID(0))
EndIf
PanelGadget(0,10,10,210,130)
AddGadgetItem(0,-1,"Panel")
FrameGadget(1,10,10,180,85," Blue ")
dummy = TextGadget(#PB_Any,0,0,0,0," Blue ")
w = GadgetWidth(dummy,#PB_Gadget_RequiredSize)
h = GadgetHeight(dummy,#PB_Gadget_RequiredSize)
txt = TextGadget(#PB_Any,10+8,10,w,h," Blue ")
SetGadgetColor(txt,#PB_Gadget_FrontColor,$FF0000)
FreeGadget(dummy)
CloseGadgetList()
FrameGadget(2,230,23,180,118," Red ")
dummy = TextGadget(#PB_Any,0,0,0,0," Red ")
w = GadgetWidth(dummy,#PB_Gadget_RequiredSize)
h = GadgetHeight(dummy,#PB_Gadget_RequiredSize)
txt = TextGadget(#PB_Any,230+8,23,w,h," Red ")
SetGadgetColor(txt,#PB_Gadget_FrontColor,$0000FF)
FreeGadget(dummy)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadget text color
PostPosted: Sun Oct 08, 2017 1:18 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
Thanks, Rashad! I wrapped it up into a neat little procedure here:

viewtopic.php?f=12&t=69356

With credit given to you, of course. :)


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 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