The problem of making TextGadget's text background transparent and using it in Thread

Just starting out? Need help? Post your questions and find answers here.
hdt888
User
User
Posts: 57
Joined: Sun Jul 07, 2024 8:42 am

The problem of making TextGadget's text background transparent and using it in Thread

Post by hdt888 »

I tried with the following code but it didn't work as expected.

My TextGadget IDs: #WORKING_wind_Text_Title and #WORKING_wind_Text_subTitle

The text characters overlap each other every time the Thread has an event.

I update this text by using SetGadgetText() in the Thread.

How to fix this ?

Code: Select all

Procedure WinProc(hWnd, Msg, wParam, lParam)
    Select Msg
      Case #WM_CTLCOLORSTATIC
        Select lParam
          Case GadgetID(#WORKING_wind_Text_Title)
            SetBkMode_(wParam, #TRANSPARENT)
            SetTextColor_(wParam, #Blue)
            ProcedureReturn GetStockObject_(#HOLLOW_BRUSH)
          Case GadgetID(#WORKING_wind_Text_subTitle)
            SetBkMode_(wParam, #TRANSPARENT)
            SetTextColor_(wParam, #Red)
            ProcedureReturn GetStockObject_(#HOLLOW_BRUSH)
        EndSelect
    EndSelect
    ProcedureReturn #PB_ProcessPureBasicEvents
  EndProcedure
...............
SetWindowCallback(@WinProc(), #my_window, #PB_Window_NoChildEvents)
.................
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by Axolotl »

The problem you described is outside the posted code.
Please post a compilable (even minimalistic) code with the problem included.
My guess: You create the Gadgets with coordinates which overlap eachother.
Suggestion: Search for examples acc. #WM_CTLCOLORSTATIC and / or Thread
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by RASHAD »

Hi

Code: Select all

          InvalidateRect_(WindowID(?),0,1)
          SetGadgetText(?, "???????")
Egypt my love
hdt888
User
User
Posts: 57
Joined: Sun Jul 07, 2024 8:42 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by hdt888 »

I tried again as you suggested. As a result the whole window started flashing.
Specifically, GadGets is flashing.
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by mk-soft »

How often is the gadget updated in the thread?

Is it better to use PostEvent to update the gadget from the thread? Under macOS and Linux you cannot update gadgets from a thread (Crashed).
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
hdt888
User
User
Posts: 57
Joined: Sun Jul 07, 2024 8:42 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by hdt888 »

thank mk-soft.

I tried again as you suggested. result is still the same. window is flickering.

It seems that command:

Code: Select all

InvalidateRect_(WindowID(?),0,1)
makes the whole window transparent and not just the textgadget.
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by Axolotl »

Of course, the solution depends on what your problem is.
In some of my apps I reduce flickering with this, if the thread is doing something in loops, I use a counter (count) to update (PostEvent) the UI not every loop iteration:

Code: Select all

; reduce flickering .... (snippet out of my code, need the right place i.e. in a loop in a thread to run) 
If count % 100 = 0  ; every 100 step send an update 
  PostEvent(#EVENT_ThreadUpdate, 0, 2, 0, index) ; ... Object = 2, index in bytes) 
EndIf 
count + 1   
To understand what the API functions are doing "Learn MS" is a great place to look at. i.e. invalidaterect
You can try

Code: Select all

GadgetID(?)
instead of

Code: Select all

WindowID(?)
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
hdt888
User
User
Posts: 57
Joined: Sun Jul 07, 2024 8:42 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by hdt888 »

You can try

Code: Select all

GadgetID(?)
instead of

Code: Select all

WindowID(?)
thank @axoloti

I tried again as you suggested. GadgetID(?) not work for me.
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by RASHAD »

Try to Invalidate the gadget region only
Egypt my love
hdt888
User
User
Posts: 57
Joined: Sun Jul 07, 2024 8:42 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by hdt888 »

InvalidateRect_(GadgetID(????),0,1) not work
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by RASHAD »

Code: Select all

          GetWindowRect_(GadgetID(?),r.RECT)
          MapWindowPoints_(0,WindowID(?),r,2)
          InvalidateRect_(WindowID(?),r,1)
          SetGadgetText(?, "?????")
Egypt my love
hdt888
User
User
Posts: 57
Joined: Sun Jul 07, 2024 8:42 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by hdt888 »

Okay @RASHAD. Thank you.

Everything works smoothly and beautifully. The textGadgets can now have their background color transparent.

But there is one problem: when I update the text for these textGadgets via a CreateThread(), I see the window and the textGadgets flickering.

How to fix this ?
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by RASHAD »

I can't tell without knowing what you are doing with the Thread and why
Maybe you can use Windows Timer instead
Egypt my love
hdt888
User
User
Posts: 57
Joined: Sun Jul 07, 2024 8:42 am

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by hdt888 »

Okay RASHAD.
Because I was messing around and caused this flickering. I fixed it.
PB 5.x + 6.x + Win10. Feel the ...Pure... Power.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: The problem of making TextGadget's text background transparent and using it in Thread

Post by mk-soft »

Maybe it helps to switch on the double buffering of the gadget.
And also not to update too often.

Call once after creating the gadget

Code: Select all

SetWindowLong_(GadgetID(???), #GWL_EXSTYLE, GetWindowLong_(GadgetID(???), #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply