FrameGadget backcolor problem ...

Just starting out? Need help? Post your questions and find answers here.
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

FrameGadget backcolor problem ...

Post 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.
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: FrameGadget backcolor problem ...

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FrameGadget backcolor problem ...

Post 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.
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: FrameGadget backcolor problem ...

Post by BarryG »

marc_256 wrote: Wed Jan 04, 2023 9:48 amthere is no QB64 forum anymore
It's here -> https://qb64.boards.net
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: FrameGadget backcolor problem ...

Post 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
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: FrameGadget backcolor problem ...

Post 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,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FrameGadget backcolor problem ...

Post 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:
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: FrameGadget backcolor problem ...

Post by jacdelad »

It's not a bug because it's neither mentioned that SetGadgetColor works on this gadget, nor is it standard OS behaviour.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: FrameGadget backcolor problem ...

Post 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

;--------------------------------------------------------------------------------------------------
Et cetera is my worst enemy
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: FrameGadget backcolor problem ...

Post 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
Image Image
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: FrameGadget backcolor problem ...

Post 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
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
normeus
Enthusiast
Enthusiast
Posts: 470
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: FrameGadget backcolor problem ...

Post 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
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: FrameGadget backcolor problem ...

Post 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.
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: FrameGadget backcolor problem ...

Post by offsides »

QB64 appears to be back:

https://qb64.com/
PB 5.72 (32-bit) on Win 10.
Post Reply