Page 1 of 1

image background for string gadget possible??

Posted: Tue Jul 19, 2011 6:38 pm
by gabriel
Hello:
just for curiosity reasons, is it possible to have an image background for a string gadget??

thanks

Re: image background for string gadget possible??

Posted: Tue Jul 19, 2011 7:59 pm
by RASHAD
Yes you can

Code: Select all

CreateImage(0,280,24)
  StartDrawing(ImageOutput(0))
      DrawingMode(#PB_2DDrawing_Gradient)     
      LinearGradient(0, 0, 280, 0)
      GradientColor(0.00, $03FEFC)
      GradientColor(0.25, $83FD7C)
      GradientColor(0.50, $FA8C05)
      GradientColor(0.75, $0593FA)
      GradientColor(1.00, $0803F7)
      Box(0,0,280,24)
  StopDrawing()

Procedure WndProc(hwnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_CTLCOLOREDIT
      hDC = wParam
      SetTextColor_(hDC, #Black)
      SetBkMode_(hDC, #TRANSPARENT)
      result = CreatePatternBrush_(ImageID(0))
     
    Case #WM_MOVE     
      InvalidateRect_(GadgetID(0),0,1)   
     
  EndSelect
  ProcedureReturn result
EndProcedure

;LoadImage(0, "f:\error_out.bmp")

OpenWindow(0,0,0,300,200,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

StringGadget(0,10,10,280,24,"")
SetGadgetText(0, "BackGround Test")
SetWindowCallback(@WndProc())

Repeat
  Select WaitWindowEvent()
     
       Case #PB_Event_CloseWindow
          Q = 1         
         
  EndSelect

Until Q = 1

Re: image background for string gadget possible??

Posted: Tue Jul 19, 2011 8:37 pm
by netmaestro
result = CreatePatternBrush_(ImageID(0))
Gigantic memory leak. If you create the brush when you create the image and assign it to a global variable, you can return that variable and there is no leak. The way you're doing it, a new brush gets created at every repaint.

Here's a couple of debugging lines you can add to avoid GDI leaks when coding stuff like this. Run this code and move the window around:

Code: Select all

Global ProcessHandle = OpenProcess_(#PROCESS_ALL_ACCESS,#False,GetCurrentProcessId_());

CreateImage(0,280,24)
  StartDrawing(ImageOutput(0))
      DrawingMode(#PB_2DDrawing_Gradient)     
      LinearGradient(0, 0, 280, 0)
      GradientColor(0.00, $03FEFC)
      GradientColor(0.25, $83FD7C)
      GradientColor(0.50, $FA8C05)
      GradientColor(0.75, $0593FA)
      GradientColor(1.00, $0803F7)
      Box(0,0,280,24)
  StopDrawing()

Procedure WndProc(hwnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_CTLCOLOREDIT
      hDC = wParam
      SetTextColor_(hDC, #Black)
      SetBkMode_(hDC, #TRANSPARENT)
      result = CreatePatternBrush_(ImageID(0))
      gdicount = GetGuiResources_(ProcessHandle, 0)
      Debug "Total GDI handles: "+Str(gdicount)
     
    Case #WM_MOVE     
      InvalidateRect_(GadgetID(0),0,1)   
     
  EndSelect
  ProcedureReturn result
EndProcedure

;LoadImage(0, "f:\error_out.bmp")

OpenWindow(0,0,0,300,200,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

StringGadget(0,10,10,280,24,"")
SetGadgetText(0, "BackGround Test")
SetWindowCallback(@WndProc())

Repeat
  Select WaitWindowEvent()
     
       Case #PB_Event_CloseWindow
          Q = 1         
         
  EndSelect

Until Q = 1

Re: image background for string gadget possible??

Posted: Tue Jul 19, 2011 8:54 pm
by gabriel
Wonderful!!

Thank you, both!!

Re: image background for string gadget possible??

Posted: Tue Jul 19, 2011 9:22 pm
by RASHAD
Thanks NM
I am not doing good these days
I am changing my accommodation after 14 years

Code: Select all

Global BKG

CreateImage(0,280,24)
  StartDrawing(ImageOutput(0))
      DrawingMode(#PB_2DDrawing_Gradient)     
      LinearGradient(0, 0, 280, 0)
      GradientColor(0.00, $03FEFC)
      GradientColor(0.25, $83FD7C)
      GradientColor(0.50, $FA8C05)
      GradientColor(0.75, $0593FA)
      GradientColor(1.00, $0803F7)
      Box(0,0,280,24)
  StopDrawing()

Procedure WndProc(hwnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_CTLCOLOREDIT
      hDC = wParam
      SetTextColor_(hDC, #Black)
      SetBkMode_(hDC, #TRANSPARENT)
      result = BKG
     
    Case #WM_MOVE     
      InvalidateRect_(GadgetID(0),0,1)   
     
  EndSelect
  ProcedureReturn result
EndProcedure

;LoadImage(0, "f:\error_out.bmp")

OpenWindow(0,0,0,300,200,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

StringGadget(0,10,10,280,24,"")
BKG = CreatePatternBrush_(ImageID(0))
SetGadgetText(0, "BackGround Test")
SetWindowCallback(@WndProc())

Repeat
  Select WaitWindowEvent()
     
       Case #PB_Event_CloseWindow
          Q = 1         
         
  EndSelect

Until Q = 1

Re: image background for string gadget possible??

Posted: Tue Jul 19, 2011 9:28 pm
by rsts
RASHAD wrote:Thanks NM
I am not doing good these days
I am changing my accommodation after 14 years
Sorry to hear that, Mr Rashad. I hope all goes well. Let us know if you need support.

cheers

Re: image background for string gadget possible??

Posted: Tue Jul 19, 2011 9:36 pm
by RASHAD
:) Thanks rsts
To move to some place else that mean you have to sacrifice
You can not imagine how many books went to garbage
Full library I can say(Should I be sad or not?)
Thanks mate

Re: image background for string gadget possible??

Posted: Tue Jul 19, 2011 11:24 pm
by c4s
@RASHAD
Yes, good luck my friend!

Re: image background for string gadget possible??

Posted: Wed Jul 20, 2011 2:54 am
by IdeasVacuum
Ah, most of my books are out-dated and should be discarded but I can't get out of that 'it might be useful one day' mode. Probably a good reason to use an e-reader, otherwise I'll be moving house to find space for more books :mrgreen: Good luck with the move Rashad, new surroundings can be good for the brain.

Re: image background for string gadget possible??

Posted: Wed Jul 20, 2011 4:59 am
by RASHAD
Thanks guys
Problems .... problems
One of my problems is while I discarded a lot of my favorites, one of my daughters
has the same bad habits of mine (that means she want to keep every thing of her own) :evil:

Re: image background for string gadget possible??

Posted: Wed Jul 20, 2011 9:26 am
by captain_skank
RASHAD wrote:Thanks guys
Problems .... problems
One of my problems is while I discarded a lot of my favorites, one of my daughters
has the same bad habits of mine (that means she want to keep every thing of her own) :evil:

I actualy misread that and thought you'd discarded one of your daughters. :shock:

Anyhoo hope your move goes well.

Nice tip there netmaestro.