How to set a background image for a window?
-
berryoxide
- Enthusiast

- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger
How to set a background image for a window?
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!
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!
Try this
I think there are some issues with panelgadgets() or containers or something but it's a start. 
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
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
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.
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.
oh... and have a nice day.
-
berryoxide
- Enthusiast

- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger
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.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 same code but with a gadget reporter, seems to work ok.
@berryoxide, does it work on your setup?
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
- Enthusiast

- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger
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. 
Last edited by Derek on Sat Aug 30, 2008 9:33 pm, edited 1 time in total.
@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
-
berryoxide
- Enthusiast

- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger
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!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
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
http://www.purebasic.fr/german/viewtopi ... 497#210497
http://www.purebasic.fr/english/viewtopic.php?t=32162
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)
Endinteresting, wonder why I didn't read about it yet... where you got this from?Derek wrote:Yeah, but if you disable the imagegadget then it works.
oh... and have a nice day.
Read this, scroll down to netmaestro's comment.Kaeru Gaman wrote:interesting, wonder why I didn't read about it yet... where you got this from?
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.
-
berryoxide
- Enthusiast

- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger
- netmaestro
- PureBasic Bullfrog

- Posts: 8453
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
berryoxide
- Enthusiast

- Posts: 136
- Joined: Fri Aug 15, 2008 6:04 pm
- Location: Debugger