image background for string gadget possible??

Just starting out? Need help? Post your questions and find answers here.
gabriel
Enthusiast
Enthusiast
Posts: 137
Joined: Sat Aug 01, 2009 4:49 pm
Location: Beirut, Lebanon

image background for string gadget possible??

Post by gabriel »

Hello:
just for curiosity reasons, is it possible to have an image background for a string gadget??

thanks
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: image background for string gadget possible??

Post 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
Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: image background for string gadget possible??

Post 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
BERESHEIT
gabriel
Enthusiast
Enthusiast
Posts: 137
Joined: Sat Aug 01, 2009 4:49 pm
Location: Beirut, Lebanon

Re: image background for string gadget possible??

Post by gabriel »

Wonderful!!

Thank you, both!!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: image background for string gadget possible??

Post 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
Egypt my love
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: image background for string gadget possible??

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: image background for string gadget possible??

Post 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
Egypt my love
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: image background for string gadget possible??

Post by c4s »

@RASHAD
Yes, good luck my friend!
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: image background for string gadget possible??

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: image background for string gadget possible??

Post 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:
Egypt my love
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 641
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: image background for string gadget possible??

Post 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.
Post Reply