FrameContainer Font Text!

Post bugreports for the Windows version here
User avatar
ChrisR
Addict
Addict
Posts: 1526
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

FrameContainer Font Text!

Post by ChrisR »

The FrameContainer Font Text is not drawn properly if the FrameContainer is inside a Framecontainer!
No worries if it's in another type of container.
Tested with PB 6.21 x64 on Windows 11

Code: Select all

If OpenWindow(0, 0, 0, 500, 220, "FrameContainer Font Text", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ;LoadFont(0, "Segoe UI", 12, #PB_Font_Italic)
  ;SetGadgetFont(#PB_Default, FontID(0))
  FrameGadget(0, 20, 60, 200, 120, "FrameContainer_0", #PB_Frame_Container)
  CloseGadgetList()
  FrameGadget(1, 240, 20, 240, 180, "FrameContainer_1", #PB_Frame_Container)
    FrameGadget(2, 20, 40, 200, 120, "FrameContainer_2", #PB_Frame_Container)
      TextGadget(3, 10, 30, 180, 80, "The FrameContainer Font Text is not displayed properly if the FrameContainer is inside a Framecontainer !")
      SetGadgetColor(3, #PB_Gadget_FrontColor, RGB(255, 0, 0))
    CloseGadgetList()
  CloseGadgetList()
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Fred
Administrator
Administrator
Posts: 18431
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: FrameContainer Font Text!

Post by Fred »

It looks like a Windows limitation. While it works to use it as container, it doesn't seems to support all feature..

https://stackoverflow.com/questions/214 ... box#296594
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5022
Joined: Sun Apr 12, 2009 6:27 am

Re: FrameContainer Font Text!

Post by RASHAD »

Hi ChrisR
I don't like it but if you insist :)

Code: Select all

 
If OpenWindow(0, 0, 0, 500, 220, "FrameContainer Font Text", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  LoadFont(0, "Segoe UI", 12, #PB_Font_Italic)
  SetGadgetFont(#PB_Default, FontID(0))
  FrameGadget(0, 20, 60, 200, 120, "FrameContainer_0", #PB_Frame_Container)
  CloseGadgetList()
  FrameGadget(1, 240, 20, 240, 180, "FrameContainer_1", #PB_Frame_Container)
  ContainerGadget(5,20, 40, 200, 120)
    FrameGadget(2, 0, 0, 200, 120, "FrameContainer_2", #PB_Frame_Container)
      TextGadget(3, 10, 30, 180, 80, "The FrameContainer Font Text is not displayed properly if the FrameContainer is inside a Framecontainer !")
      SetGadgetColor(3, #PB_Gadget_FrontColor, RGB(255, 0, 0))
    CloseGadgetList()
  CloseGadgetList()
  CloseGadgetList()
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Egypt my love
User avatar
ChrisR
Addict
Addict
Posts: 1526
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: FrameContainer Font Text!

Post by ChrisR »

Hi Radhad,
Thanks for the workaround with ContainerGadget, I thought you liked, it's always so useful to have the container close at hand :wink:
Well, I don't really need it here. I just saw it by chance, in the preview in my Designer, while testing the Frame Container, I'm currently coding.
User avatar
ChrisR
Addict
Addict
Posts: 1526
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: FrameContainer Font Text!

Post by ChrisR »

Fred wrote: Thu Jan 08, 2026 3:34 pm It looks like a Windows limitation. While it works to use it as container, it doesn't seems to support all feature..

https://stackoverflow.com/questions/214 ... box#296594
Oops, with Rashad's reply, I didn't see your reply, Fred. Thank you for looking at it, so quickly.
I'll let you decide whether to tag the topic title.
Good end of testing, debugging, coding for our next PB 6.31
breeze4me
Enthusiast
Enthusiast
Posts: 649
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: FrameContainer Font Text!

Post by breeze4me »

After some investigation, it appears that the font is not set on the hdc before the DrawThemeText function is executed.
While using the MS Detours library can resolve this, there doesn't seem to be any other solution suitable for an official bug fix.

Code: Select all

Import "Detours.lib"
  DetourTransactionBegin.l()
  DetourTransactionCommit.l()
  DetourUpdateThread.l(hThread)
  DetourAttach.l(*ppPointer, pDetour)
  DetourDetach.l(*ppPointer, pDetour)
EndImport

Import "uxtheme.lib"
  DrawThemeText.l(hTheme, hdc, iPartId.l, iStateId.l, *pszText, cchText.l, dwTextFlags.l, dwTextFlags2.l, *pRect.RECT)
EndImport

Prototype.l ptDrawThemeText(hTheme, hdc, iPartId.l, iStateId.l, *pszText, cchText.l, dwTextFlags.l, dwTextFlags2.l, *pRect.RECT)
Global DrawThemeText__.ptDrawThemeText = @DrawThemeText()

#BP_GROUPBOX = 4
#GBS_NORMAL = 1
#GBS_DISABLED = 2

Procedure.l My_DrawThemeText(hTheme, hdc, iPartId.l, iStateId.l, *pszText, cchText.l, dwTextFlags.l, dwTextFlags2.l, *pRect.RECT)
  Protected Result.l
  Protected hWnd, hFont, hOldFont
  
  If iPartId = #BP_GROUPBOX
    hWnd = WindowFromDC_(hdc)
    
    If hWnd
      hFont = SendMessage_(hWnd, #WM_GETFONT, 0, 0)
      If hFont
        hOldFont = SelectObject_(hdc, hFont)
      EndIf
      
      Result = DrawThemeText__(hTheme, hdc, iPartId, iStateId, *pszText, cchText, dwTextFlags, dwTextFlags2, *pRect)
      
      If hOldFont
        SelectObject_(hdc, hOldFont)
      EndIf
      
      ProcedureReturn Result
    EndIf
  EndIf
  
  ProcedureReturn DrawThemeText__(hTheme, hdc, iPartId, iStateId, *pszText, cchText, dwTextFlags, dwTextFlags2, *pRect)
EndProcedure


If DetourTransactionBegin() = #NO_ERROR
  If DetourUpdateThread(GetCurrentThread_()) = #NO_ERROR
    
    If DrawThemeText__
      If DetourAttach(@DrawThemeText__, @My_DrawThemeText()) <> #NO_ERROR
        Debug "DetourAttach Error: DrawThemeText"
      Else
        Debug "DetourAttach OK: DrawThemeText"
      EndIf
    EndIf
    
    DetourTransactionCommit()
  EndIf
EndIf

If OpenWindow(0, 0, 0, 500, 220, "FrameContainer Font Text", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  ;LoadFont(0, "Segoe UI", 12, #PB_Font_Italic)
  ;SetGadgetFont(#PB_Default, FontID(0))
  
  FrameGadget(0, 20, 60, 200, 120, "FrameContainer_0", #PB_Frame_Container)
  CloseGadgetList()
  FrameGadget(1, 240, 20, 240, 180, "FrameContainer_1", #PB_Frame_Container)
    FrameGadget(2, 20, 40, 200, 120, "FrameContainer_2", #PB_Frame_Container)
      TextGadget(3, 10, 30, 180, 80, "The FrameContainer Font Text is not displayed properly if the FrameContainer is inside a Framecontainer !")
      SetGadgetColor(3, #PB_Gadget_FrontColor, RGB(255, 0, 0))
    CloseGadgetList()
  CloseGadgetList()
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf


If DetourTransactionBegin() = #NO_ERROR
  If DetourUpdateThread(GetCurrentThread_()) = #NO_ERROR
    
    If DrawThemeText__
      If DetourDetach(@DrawThemeText__, @My_DrawThemeText()) <> #NO_ERROR
        Debug "DetourDetach Error: DrawThemeText"
      Else
        Debug "DetourDetach OK: DrawThemeText"
        
      EndIf
    EndIf
    
    DetourTransactionCommit()
  EndIf
EndIf
User avatar
ChrisR
Addict
Addict
Posts: 1526
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: FrameContainer Font Text!

Post by ChrisR »

Thanks breeze4me for your investigation and for confirming that this is indeed a native Windows bug and not a PB issue :)
Post Reply