Page 1 of 3
How to set a background image for a window?
Posted: Sat Aug 30, 2008 8:17 pm
by berryoxide
Hi!
I've been looking endlessly through the forums but still can't find what I want... I'd like to have this working on both Windows and Linux and it is a simple "hello world" like application for which I want to have a custom background image. All gadgets and stuff then becomes placed "on top" of the background image.
Can anyone point me in the right direction? Still a noob in these things, but any help is appreciated! Thanks!
Posted: Sat Aug 30, 2008 8:25 pm
by Derek
Try this
Code: Select all
OpenWindow(0,0,0,200,200,"",$ca0001)
CreateImage(0,200,200,32)
StartDrawing(ImageOutput(0))
For y=0 To 200
Line(0,y,200,0,RGB(y+50,0,0))
Next
StopDrawing()
CreateGadgetList(WindowID(0))
ImageGadget(1,0,0,200,200,ImageID(0))
DisableGadget(1,1)
ButtonGadget(2,10,10,180,30,"Press me")
StringGadget(3,10,100,180,20,"Type in here")
Repeat
Until WaitWindowEvent()=16
I think there are some issues with panelgadgets() or containers or something but it's a start.

Posted: Sat Aug 30, 2008 8:46 pm
by Kaeru Gaman
dz dz dz!
Derek, how could you?
Gadgets don't have a z-order, there have been hundrets of discussions about it,
and it was ALWAYS! said that
thou shalt not put Gadgets over each other!
@berryoxide
you have to go the API way, there is no cross-platform solution for a background image.
Posted: Sat Aug 30, 2008 8:54 pm
by berryoxide
Kaeru Gaman wrote:dz dz dz!
Derek, how could you?
Gadgets don't have a z-order, there have been hundrets of discussions about it,
and it was ALWAYS! said that
thou shalt not put Gadgets over each other!
@berryoxide
you have to go the API way, there is no cross-platform solution for a background image.
The API way... Well ok, as long as it runs under Wine I guess it's good. But I still don't know how to do that the "API way" let alone understand that MessageBox_ is a function of the API.
Posted: Sat Aug 30, 2008 9:02 pm
by Derek
Kaeru Gaman wrote:dz dz dz!
Derek, how could you?
Gadgets don't have a z-order, there have been hundrets of discussions about it,
and it was ALWAYS! said that
thou shalt not put Gadgets over each other!
Yeah, but if you disable the imagegadget then it works.
That's good enough for me.

Posted: Sat Aug 30, 2008 9:06 pm
by Derek
The same code but with a gadget reporter, seems to work ok.
Code: Select all
OpenWindow(0,0,0,200,200,"",$ca0001)
CreateImage(0,200,200,32)
StartDrawing(ImageOutput(0))
For y=0 To 200
Line(0,y,200,0,RGB(y+50,0,0))
Next
StopDrawing()
CreateGadgetList(WindowID(0))
ImageGadget(1,0,0,200,200,ImageID(0))
DisableGadget(1,1)
ButtonGadget(2,10,10,180,30,"Press me")
StringGadget(3,10,100,180,20,"Type in here")
Repeat
e=WaitWindowEvent()
If e=#PB_Event_Gadget
gad=EventGadget()
Debug Gad
EndIf
Until e=16
@berryoxide, does it work on your setup?
Posted: Sat Aug 30, 2008 9:08 pm
by berryoxide
@Derek: It indeed does and fantastically! I wrapped the code in a procedure "SetWindowBackground(WindowID, ImageID)" so if there is a better approach I can swiftly change the code.
I'm getting the grip of this and I really like the logic behind PureBasic

Posted: Sat Aug 30, 2008 9:12 pm
by Derek
Glad I could help, I have no idea if it works on linux though and as Kaeru said, you might get into problems with the z-order of gadgets so bear it in mind.

Posted: Sat Aug 30, 2008 9:12 pm
by SFSxOI
@berryoxide
Code: Select all
MessageBox_(#Window_Num_or_Null, "This is something you want to say", "Information - this is the title (caption)", #MB_ICONEXCLAMATION)
MessageBox_(#Null, "This is something you want to say", "Information - this is the title (caption)", #MB_ICONEXCLAMATION)
http://msdn.microsoft.com/en-us/library/ms645505.aspx
Posted: Sat Aug 30, 2008 9:16 pm
by berryoxide
SFSxOI wrote:Code: Select all
MessageBox_(#Window_0, "This is something you want to say", "Information - this is the title (caption)", #MB_ICONEXCLAMATION)
http://msdn.microsoft.com/en-us/library/ms645505.aspx
No no you got me wrong... I know that already, it's just that I found Visual Basic code which I wanted to port to PureBasic for fun, and I by mistake added an underscore (finger slipped on the shift key) just before the parentheses began in front of the MessageBox procedure. That mistake was in there so long until I compiled and in my debugging phrase I saw that the underscore didn't make an error... Well, I tried to do it again and "o m g" it works!

Posted: Sat Aug 30, 2008 9:29 pm
by Kaeru Gaman
http://www.purebasic.fr/german/viewtopi ... 497#210497
Code: Select all
OpenWindow(0,0,0,520,400,"void",#WS_OVERLAPPEDWINDOW | #WS_VISIBLE | 1)
LoadImage(0,#PB_Compiler_Home + "Examples\Sources\Data\Background.bmp")
hbrBackground = CreatePatternBrush_(ImageID(0))
SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hbrBackground)
HideWindow(0,0)
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
DeleteObject_(hbrBackground)
Code: Select all
; German forum:
; Author: Unknown (updated for PB4.00 by blbltheworm), modified by hardfalcon
; OS: Windows
; Demo: No
hWnd = OpenWindow(0, 100, 200, 250, 260, "Image brush", #PB_Window_SystemMenu )
UsePNGImageDecoder()
UseJPEGImageDecoder()
hImage = LoadImage(#PB_Any,"Z:\usr\share\pixmaps\backgrounds\gnome\background-default.jpg")
Debug ImageDepth(hImage)
ExamineDesktops()
Debug DesktopDepth(0)
If ImageDepth(hImage) <> DesktopDepth(0) ;sonst gehts nicht, Farbtiefe des Bildes MUSS der Desktopfarbtiefe entsprechen!
hImage2 = CreateImage(#PB_Any,ImageWidth(hImage),ImageHeight(hImage),#PB_Image_DisplayFormat)
Debug ImageDepth(hImage2)
StartDrawing(ImageOutput(hImage2))
Debug DrawImage(ImageID(hImage),0,0)
StopDrawing()
FreeImage(hImage)
hImage = hImage2
EndIf
hBrush = CreatePatternBrush_(ImageID(hImage))
SetClassLong_(hWnd, #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(hWnd, #Null, #True)
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
DeleteObject_(hBrush) ; Brush löschen/freigeben!
FreeImage(hImage)
End
http://www.purebasic.fr/english/viewtopic.php?t=32162
Derek wrote:Yeah, but if you disable the imagegadget then it works.
interesting, wonder why I didn't read about it yet... where you got this from?
Posted: Sat Aug 30, 2008 9:37 pm
by Derek
Kaeru Gaman wrote:interesting, wonder why I didn't read about it yet... where you got this from?
Read this, scroll down to netmaestro's comment.
http://www.purebasic.fr/english/viewtop ... magegadget
If it's good enough for netmaestro then it's more than good enough for me.
But the code you posted above is good as it seems to be doing what Sparkie says in the same link above, but as Sparkie says it's not cross-platform whereas the disable gadget trick is.

Posted: Sat Aug 30, 2008 10:58 pm
by berryoxide
I'll stick with Derek's suggestion for now... Works in GNU/Linux as well by the way. Just QEMUed into OSx86 and it works there too

Posted: Sat Aug 30, 2008 11:23 pm
by netmaestro
Berikco wrote:The grid of the Visual Designer is just a disabled imagegadget
Thanks Derek, and if it's good enough for Berikco it's good enough for me

Posted: Sat Aug 30, 2008 11:40 pm
by berryoxide
If it's good enough for Berikco, it's good enough for netmaestro, and if it's good enough for netmaestro it's good enough for Derek, and if it's good enough for Derek it's good enough for me.
Sorry, didn't have something else to do
