Page 1 of 1

FrameGadget backcolor problem ...

Posted: Wed Jan 04, 2023 9:48 am
by marc_256
Hello everyone,

I am still building small robots,
and for communicate with these things, I need to write some PC programs.

Some years ago, I left purebasic for QB64, it work very well,
but there is no QB64 forum anymore and there is no more follow up. ;-(

So I'm back to PB, 2023, new year, new start ... ;-)

I use PB 5.73 x64 LTS and now downloaded and installed PB 6.00 x64 on win 10 PRO x64 system.

And restarted a new communication program (rs232/rs485) from scratch ...
the reason i left PureBasic two years ago, was the big quantity of bugs in PB i had by developing my programs.
And yes, the frustration is here again, with my small restart program.

Code: Select all

;--------------------------------------------------------------------------------------------------
;- TEST PROGRAM FRAMEGADGET
;--------------------------------------------------------------------------------------------------
EnableExplicit

;--------------------------------------------------------------------------------------------------
Declare CreateWindow()

;--------------------------------------------------------------------------------------------------
	CreateWindow()

	Repeat
		Delay(10)
	Until WaitWindowEvent() = #PB_Event_CloseWindow

	End

;--------------------------------------------------------------------------------------------------
Procedure CreateWindow()
	If OpenWindow(0, 0, 0, 320, 250, "FrameGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
		SetWindowColor (0, $004000)

		FrameGadget(3, 10, 190, 300, 50, "", #PB_Frame_Flat)

	EndIf

EndProcedure

;--------------------------------------------------------------------------------------------------


Is there someone who want to test this and send me some results please.
What am I doing wrong ??
I use FrameGadget() to draw a empty frame on the window green backcolor,
and the frames backcolor is white and not green ??

Tested on PB 5.73 x64 LTS and PB6 x64 on win 10 pro x64

Greetings,
Marco

PS: For all of you, a nice creative programming year 2023.

Re: FrameGadget backcolor problem ...

Posted: Wed Jan 04, 2023 10:47 am
by jacdelad
The gadget itself is very limited and doesn't support the GadgetColor-commands, so I assume it only works with the set systemcolor.

Re: FrameGadget backcolor problem ...

Posted: Wed Jan 04, 2023 10:49 am
by infratec
I modified the code from Fluid Byte (windows only)

Code: Select all

; Title:    FrameGadget with custom text color / Theme Support / 64-Bit
;
; Author:   Fluid Byte
; Version:  PureBasic V4.XX
; Platform: Windows XP and higher
; E-Mail:   fluidbyte@web.de
; https://www.purebasic.fr/english/viewtopic.php?p=327619#p327619
; Modified: infratec

EnableExplicit

Structure FRAME_EX
  lpPrevFunc.i
  clrText.i
  bThemeXP.i
  window.i
  gadget.i
EndStructure


Procedure FrameExProc(hWnd, uMsg, wParam, lParam)
  
  Protected *frmex.FRAME_EX, hDC, ps.PAINTSTRUCT, Title.s, fts.SIZE, wrc.RECT, lpBuffer, hThemeButton
  
  
  *frmex = GetWindowLongPtr_(hwnd, #GWL_USERDATA)
  
  Select uMsg
    Case #WM_NCDESTROY
      FreeStructure(*frmex)
      ProcedureReturn #False
      
    Case #WM_PAINT
      hdc = BeginPaint_(hwnd, @ps)
      If hdc
        
        SelectObject_(hdc, SendMessage_(hwnd, #WM_GETFONT, 0, 0))
        
        Title = GetGadgetText(*frmex\gadget)
        GetTextExtentPoint32_(hdc, Title, Len(Title), fts)   
        GetClientRect_(hWnd, wrc)
        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(*frmex\window), lpBuffer)
            DrawThemeBackground_(hThemeButton, hdc, 4, 1, wrc, 0)
            CloseThemeData_(hThemeButton)
            
            FreeMemory(lpBuffer)
          EndIf
        Else
          DrawEdge_(hdc, wrc, #EDGE_ETCHED, #BF_RECT)
        EndIf
        
        If GetWindowColor(*frmex\window) > -1
          SetBkColor_(hdc, GetWindowColor(*frmex\window))
        Else
          SetBkColor_(hdc, GetSysColor_(#COLOR_3DFACE))
        EndIf
        
        SetTextColor_(hdc, *frmex\clrText)
        TextOut_(hdc, 9, 0, Title, Len(Title))   
        
        EndPaint_(hwnd, ps)
      EndIf
      
      ProcedureReturn #True
      
  EndSelect
  
  ProcedureReturn CallWindowProc_(*frmex\lpPrevFunc, hWnd, uMsg, wParam, lParam)
  
EndProcedure


Procedure FrameGadgetEx(Gadget, X, Y, Width, Height, Text.s, Color.i=0)
  
  Protected *frmex.FRAME_EX, HINSTANCE, hResData, Length, Result
  Protected dvi.DLLVERSIONINFO\cbsize = SizeOf(DLLVERSIONINFO)
  
  
  If Gadget = #PB_Any
    Gadget = FrameGadget(#PB_Any, X, Y, Width, Height, Text)
    If Gadget
      Result = #True
    EndIf
  Else
    Result = FrameGadget(Gadget, X, Y, Width, Height, Text)
  EndIf
  
  If Result
    *frmex = AllocateStructure(FRAME_EX)
    *frmex\lpPrevFunc = SetWindowLongPtr_(GadgetID(Gadget), #GWL_WNDPROC, @FrameExProc())
    *frmex\clrText = Color
    *frmex\window = GetActiveWindow()
    *frmex\gadget = Gadget
    
    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(Gadget), #GWL_USERDATA, *frmex)
    
    Result = Gadget
  EndIf
  
  ProcedureReturn Result
  
EndProcedure


OpenWindow(0, 0, 0, 400, 300,"Ownerdraw Frame Control", #PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
SetWindowColor(0, $004000)

FrameGadgetEx(0, 10, 5, 200, 90, " FrameGadgetEx #1 ", #Red)
FrameGadgetEx(#PB_Any, 10, 100, 200, 90, " FrameGadgetEx #2 ", RGB(40, 180, 70))
FrameGadgetEx(2, 10, 195, 200, 90, " FrameGadgetEx #3 ")

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
But please create a bug report, else this bug would never be corrected.

Re: FrameGadget backcolor problem ...

Posted: Wed Jan 04, 2023 12:45 pm
by BarryG
marc_256 wrote: Wed Jan 04, 2023 9:48 amthere is no QB64 forum anymore
It's here -> https://qb64.boards.net

Re: FrameGadget backcolor problem ...

Posted: Wed Jan 04, 2023 1:33 pm
by breeze4me
Tested on Windows 10 Home x64.

1. Create a window hidden and use the HideWindow function later.

Code: Select all

Declare CreateWindow()

CreateWindow()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

End

Procedure CreateWindow()
  If OpenWindow(0, 0, 0, 320, 250, "FrameGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)
    SetWindowColor (0, $004000)
    
    FrameGadget(3, 10, 190, 300, 50, "", #PB_Frame_Flat)
    
    HideWindow(0, 0)
  EndIf
EndProcedure
2. Add other gadgets first in a frame gadget.

Code: Select all

Declare CreateWindow()

CreateWindow()

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

End

Procedure CreateWindow()
  If OpenWindow(0, 0, 0, 320, 250, "FrameGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    SetWindowColor (0, $004000)
    
    ButtonGadget(4, 15, 200, 150, 25, "test")
    FrameGadget(3, 10, 190, 300, 50, "", #PB_Frame_Flat)
    
  EndIf
EndProcedure

Re: FrameGadget backcolor problem ...

Posted: Thu Jan 05, 2023 9:53 am
by marc_256
Hi jacdelad and infratec,

Thanks for helping me,
but for me this must just be a bug ...
What I understand from the FrameGadget() is that :
- It just must draw 4 lines (empty box) in a specific color on your window backcolor
so, no filling up the frame with a backcolor but just framecolor ...

@ infratec,
I do not need a other backcolor in my frame, i just need the frame itself.
This works well on PB5.72 and not on PB 5.73 and PB 6.00

@ BarryG
Thanks, that must be a very new forum ...

@Breeze4me
Thanks, it works ...
but I never used this before ??
I tested my program in PB5.73 x64 and it works very well.

Marco,

Re: FrameGadget backcolor problem ...

Posted: Thu Jan 05, 2023 10:15 am
by infratec
Up to now I see no bug report from you about this.
So you don't mean that it is a bug :?:

Fred will never fix this if there is no bug report.
So you will see this still when PB 7.0 is out :wink:

Re: FrameGadget backcolor problem ...

Posted: Thu Jan 05, 2023 1:18 pm
by jacdelad
It's not a bug because it's neither mentioned that SetGadgetColor works on this gadget, nor is it standard OS behaviour.

Re: FrameGadget backcolor problem ...

Posted: Thu Jan 05, 2023 5:25 pm
by chi
SetWindowColor does not set the background brush of the window and, in case of the FrameGadget, draws with the default window color instead.

Code: Select all

;--------------------------------------------------------------------------------------------------
;- TEST PROGRAM FRAMEGADGET
;--------------------------------------------------------------------------------------------------
EnableExplicit

;--------------------------------------------------------------------------------------------------
Declare CreateWindow()
Global brush = CreateSolidBrush_($4000)

;--------------------------------------------------------------------------------------------------
CreateWindow()

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend

DeleteObject_(brush)
End

;--------------------------------------------------------------------------------------------------
Procedure CreateWindow()
  If OpenWindow(0, 0, 0, 320, 250, "FrameGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ;SetWindowColor (0, $004000)	  
    SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, brush)
    
    FrameGadget(3, 10, 190, 300, 50, "", #PB_Frame_Flat)
  EndIf
EndProcedure

;--------------------------------------------------------------------------------------------------

Re: FrameGadget backcolor problem ...

Posted: Thu Jan 05, 2023 6:59 pm
by Paul
I would have to believe it IS a bug.

The sample code posted shows the gadget seems to block the background color...
Image

Yet if you drag the Window off the screen and then back, the Window is repainted and now the background color shows properly...
Image

Re: FrameGadget backcolor problem ...

Posted: Thu Jan 05, 2023 9:33 pm
by marc_256
Hi infratec,
Can you please look at my previous bug report
viewtopic.php?p=573633&hilit=marc_256#p573633

look at the date ...
Sat Aug 21, 2021 9:36am
that is more than a year now, and do you see a [DONE] on the bug title ?
So, what's the difference to post a bug rapport or not ?

This was the original post ...
viewtopic.php?f=13&t=77778

There also, my program works well with
PB 5.61 x64 -> OK
PB 5.71 x64 -> OK
PB 5.72 x64 -> OK
PB 5.73 LTS x64 -> NOT OK


Hello chi,
If I use your code, I'm only windows compatible !!
And my program works well in PB 5.72 x64 and not in PB 5.73 x64


Hi Paul,
Yes, Yes, I did the same test and yes, then it works...
Under PB5.72 x64 it works as your second picture
And from PB 5.73 and PB 6.00 there is that problem as in picture one.
Thanks Paul


Marco

Re: FrameGadget backcolor problem ...

Posted: Thu Jan 05, 2023 9:57 pm
by normeus
Use setwindowcolor after frameGadet()
It's still a workaround, but it should do the trick.

Code: Select all

 If OpenWindow(0, 0, 0, 320, 250, "FrameGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   FrameGadget(3, 10, 190, 300, 50, "", #PB_Frame_Flat)
   SetWindowColor (0, $004000)
    Repeat
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
Norm

Re: FrameGadget backcolor problem ...

Posted: Fri Jan 06, 2023 10:35 am
by marc_256
@Norm

Hi, that works well, thanks.
But it is a little bit strange, to put it there.
normally that backcolor is related to the window, not the FrameGadget.

Re: FrameGadget backcolor problem ...

Posted: Fri Jan 13, 2023 11:36 pm
by offsides
QB64 appears to be back:

https://qb64.com/