Window form background
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Window form background
Is there a way to set the background of a window to a jpg or bmp image, without using an Image Gadget? I was creating a child window, and then placing an image gadget on the window, and loading an image into the gadget. Can't I just set the window background to the image instead? If so, how?
- netmaestro
- PureBasic Bullfrog

- Posts: 8453
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Window form background
Are you on Windows? If so, you can do:
And your window will maintain the image as its background, redrawing it automatically as necessary.
If you're not on Windows: dunno.
Code: Select all
hBrush = CreatePatternBrush_(ImageID(x))
; open window 0
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(0), 0, 1)
If you're not on Windows: dunno.
BERESHEIT
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: Window form background
ah...cool! Dang, I'm going to owe something shortly for all your great help!
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Window form background
on the other hand - why don't you want to use an ImageGadget?
just deactivate the ImageGadget and you can put Buttons onto it as if it was a sole backdrop.
just deactivate the ImageGadget and you can put Buttons onto it as if it was a sole backdrop.
oh... and have a nice day.
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: Window form background
my original idea involved 3 rows of images. I had first thought to have a single image gadget that is a composite image of the 3 rows combined into one. And I was going to simply use the DrawImage function to paste an image over any of the 3 rows of the overall ImageGadget. But I would also need to paste the original image back at the same row later, using the original image to make the pasted image disappear, only at the given row. Then I thought about it and realized, if the window form background was the overall image, I could then use 3 ImageGadgets positioned over the 3 row locations. Then I could just make the ImageGadgets visible/invisible as needed without needing to use DrawImage and managing the code to do that. If any of the 3 ImageGadgets are invisible, then the backdrop of the window will appear as needed.
Here is background image;

Here is a single row element

Here would be the completed fill

Here is background image;

Here is a single row element

Here would be the completed fill

- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: Window form background
two things...
1. That is how I wrote the MAGIC SQUARE game on my website.. just using 2 different images for the tiles annd 1 for the background... there was some artifcats when user in vista moved window but this was a vista issue and his update fixed this!
2. NICE GRAPHICS!!! Is this for you ATC simulation?
1. That is how I wrote the MAGIC SQUARE game on my website.. just using 2 different images for the tiles annd 1 for the background... there was some artifcats when user in vista moved window but this was a vista issue and his update fixed this!
2. NICE GRAPHICS!!! Is this for you ATC simulation?
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: Window form background
Thanks! Yes, this is how the flight strips will appear on the screen for my tower simulator. There will be 2 bays, one for arrivals, one for departures. The little squares across the top will denote active pages of strips. Rather than use a scroll area, I'm keeping the strips fixed in position, 3 to a page. The grey square indicates no strips are present. Each square will turn green if/when it contains flight strips, going from left to right. When an aircraft communicates, the square associated with the page the flight strip is on, will turn yellow. If there is something urgent that needs to be done, it will turn red and blink. When the user clicks on the appropriate square, the 3 strips associated on that page will be displayed.
here is the current state of the project.

All of the onscreen elements are sprites, except the strip bays.
here is the current state of the project.

All of the onscreen elements are sprites, except the strip bays.
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Window form background
ermn... when it is a SCREEN, you would not put some Gadgets on it.
concerning your ImageGadgets...
you also could define a Headline, and a single Back for a single Row Element.
then make the whole table of Four ImageGadgets, one Headline and three Rows.
you can switch each Row between Empty Back and Element just by assigning the according Image.
but the naked Row Element does not look as if it already meets it's purpose,
I assume there is Text to be put on it?
so there would be even more to it, ot just ImageGadgets.
and again, your screenshot does not at all look as if it has ANYTHING to do with Gadgets,
it's rather a Screen full of grafic effects.
concerning your ImageGadgets...
you also could define a Headline, and a single Back for a single Row Element.
then make the whole table of Four ImageGadgets, one Headline and three Rows.
you can switch each Row between Empty Back and Element just by assigning the according Image.
but the naked Row Element does not look as if it already meets it's purpose,
I assume there is Text to be put on it?
so there would be even more to it, ot just ImageGadgets.
and again, your screenshot does not at all look as if it has ANYTHING to do with Gadgets,
it's rather a Screen full of grafic effects.
oh... and have a nice day.
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: Window form background
Yes, right now they are merely backdrops for what is to come. The top row of the strip bay with the squares, will have to have code to respond to which square was clicked. In VB I would have created a control array of the squares, each one with its own unique index property which would be passed to the function call when clicked.
The strips themselves will have text written on them in accordance with FAA standards dealing with flight strips. Each one will correspond to an aircraft on the ground or in the air. So, yes, the graphic right now is of a blank strip that has not had texted printed on it yet. In reality, there is a plastic strip holder that has the paper inserted into it. It is placed in the strip bay (that is slightly tilted upward), and it will slide to the bottom of the bay, or on top of the strip at the bottom. So all strips will start at the bottom and stack on top of each other. For example, if there are a total of say 5 strips, the first page will have 3 strips in it, with the next one only 2. Those two will stack from the bottom of strip bay, not the top.

Oh, hello there fellow Okie! Oklahoma City here!
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Window form background
so, it will not be done with the background, you'll need to put the text on it, too.
you could Draw the text on the empty stripe and assign the new image to an ImageGadget.
mind you, drawn text is dependant on the size in the system settings.
for the headline, you could put an Image with empty boxes in the back and use an ImageGadget for each box.
ImageGadgets can recieve clicks, too.
again, all this would be far easier using sprites and a spritefont.
you don't need Window-Controls to handle clicks properly.
you could Draw the text on the empty stripe and assign the new image to an ImageGadget.
mind you, drawn text is dependant on the size in the system settings.
for the headline, you could put an Image with empty boxes in the back and use an ImageGadget for each box.
ImageGadgets can recieve clicks, too.
again, all this would be far easier using sprites and a spritefont.
you don't need Window-Controls to handle clicks properly.
oh... and have a nice day.
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: Window form background
I am using the DBPro calls for the 3d window, and not using the PB Screen functions.
That means I am using the DB Sprite functions, not PBs.
So, I am trying to find the best combination to work for me.
I need to have the code respond to clicks on the strips, so I figured seperate Image Gadgets would be the easiest method.
Plus, the need to hide/show them on the fly. But hey, I am open to other ideas.
That means I am using the DB Sprite functions, not PBs.
So, I am trying to find the best combination to work for me.
I need to have the code respond to clicks on the strips, so I figured seperate Image Gadgets would be the easiest method.
Plus, the need to hide/show them on the fly. But hey, I am open to other ideas.
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Window form background
ok, I have no idea about DBPro...
but I would assume that handling of MouseClicks on the HUD are at least as easy as Mouse on 2D with PB.
plus, handling of sprites and bitmaptext is way easier than drawing several layers of images for an ImageGadget.
I see no way to get a bitmapfont on an Image except preparing 62+ char images with alphachannel.
maybe handling TTF would be easier then, but you'll need to check the size of the output.
change the DPI in your system settings and watch the effect.
... but maybe it's just me because I come from oldskool programming.
but I would assume that handling of MouseClicks on the HUD are at least as easy as Mouse on 2D with PB.
plus, handling of sprites and bitmaptext is way easier than drawing several layers of images for an ImageGadget.
I see no way to get a bitmapfont on an Image except preparing 62+ char images with alphachannel.
maybe handling TTF would be easier then, but you'll need to check the size of the output.
change the DPI in your system settings and watch the effect.
... but maybe it's just me because I come from oldskool programming.
oh... and have a nice day.
Re: Window form background
hello:
just a curious notice:
this program works perfectly:
but this one not:
Although they are equivalent,
why?
thanks
just a curious notice:
this program works perfectly:
Code: Select all
UseJPEGImageDecoder()
UseJPEGImageEncoder()
LoadImage (5, "pic1.jpg")
hBrush = CreatePatternBrush_(ImageID(5))
If OpenWindow(0, 218, 0, 1031, 405, "MOROSH SERIAL PORT MONITOR", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(0), 0, 1)
EndIf
Repeat ; Start of the event loop
Event = WaitWindowEvent() ; This line waits until an event is received from Windows
WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadget() ; Is it a gadget event?
EventType = EventType() ; The event type
Until Event = #PB_Event_CloseWindow ; End of the event loop
End
Code: Select all
UseJPEGImageDecoder()
UseJPEGImageEncoder()
LoadImage (5, "pic1.jpg")
hBrush = CreatePatternBrush_(ImageID(5))
Procedure open_window()
If OpenWindow(0, 218, 0, 1031, 405, "MOROSH SERIAL PORT MONITOR", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(0), 0, 1)
EndIf
EndProcedure
open_window()
Repeat ; Start of the event loop
Event = WaitWindowEvent() ; This line waits until an event is received from Windows
WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadget() ; Is it a gadget event?
EventType = EventType() ; The event type
Until Event = #PB_Event_CloseWindow ; End of the event loop
End
why?
thanks
-
russellbdavis
- User

- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: Window form background
Perhaps, move the OpenWindow() procedure past the 'End' statement, to the bottom of your code.

