image background for string gadget possible??
image background for string gadget possible??
Hello:
just for curiosity reasons, is it possible to have an image background for a string gadget??
thanks
just for curiosity reasons, is it possible to have an image background for a string gadget??
thanks
Re: image background for string gadget possible??
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
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: image background for string gadget possible??
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.result = CreatePatternBrush_(ImageID(0))
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
Re: image background for string gadget possible??
Wonderful!!
Thank you, both!!
Thank you, both!!
Re: image background for string gadget possible??
Thanks NM
I am not doing good these days
I am changing my accommodation after 14 years
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
Re: image background for string gadget possible??
Sorry to hear that, Mr Rashad. I hope all goes well. Let us know if you need support.RASHAD wrote:Thanks NM
I am not doing good these days
I am changing my accommodation after 14 years
cheers
Re: image background for string gadget possible??

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
Re: image background for string gadget possible??
@RASHAD
Yes, good luck my friend!
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!
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: image background for string gadget possible??
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
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.
If it sounds simple, you have not grasped the complexity.
Re: image background for string gadget possible??
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)
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)

Egypt my love
- captain_skank
- Enthusiast
- Posts: 641
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Re: image background for string gadget possible??
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)
I actualy misread that and thought you'd discarded one of your daughters.

Anyhoo hope your move goes well.
Nice tip there netmaestro.