Page 1 of 1

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

Posted: Fri Jul 19, 2024 3:26 am
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)
.................

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

Posted: Fri Jul 19, 2024 10:27 am
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

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

Posted: Fri Jul 19, 2024 11:54 am
by RASHAD
Hi

Code: Select all

          InvalidateRect_(WindowID(?),0,1)
          SetGadgetText(?, "???????")

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

Posted: Fri Jul 19, 2024 2:18 pm
by hdt888
I tried again as you suggested. As a result the whole window started flashing.
Specifically, GadGets is flashing.

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

Posted: Fri Jul 19, 2024 2:46 pm
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).

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

Posted: Fri Jul 19, 2024 3:31 pm
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.

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

Posted: Fri Jul 19, 2024 4:03 pm
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(?)

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

Posted: Fri Jul 19, 2024 4:12 pm
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.

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

Posted: Fri Jul 19, 2024 8:31 pm
by RASHAD
Try to Invalidate the gadget region only

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

Posted: Sat Jul 20, 2024 10:20 am
by hdt888
InvalidateRect_(GadgetID(????),0,1) not work

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

Posted: Sat Jul 20, 2024 10:46 am
by RASHAD

Code: Select all

          GetWindowRect_(GadgetID(?),r.RECT)
          MapWindowPoints_(0,WindowID(?),r,2)
          InvalidateRect_(WindowID(?),r,1)
          SetGadgetText(?, "?????")

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

Posted: Sat Jul 20, 2024 11:07 am
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 ?

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

Posted: Sat Jul 20, 2024 11:12 am
by RASHAD
I can't tell without knowing what you are doing with the Thread and why
Maybe you can use Windows Timer instead

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

Posted: Sat Jul 20, 2024 11:30 am
by hdt888
Okay RASHAD.
Because I was messing around and caused this flickering. I fixed it.

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

Posted: Sat Jul 20, 2024 11:32 am
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)