How to set a background image for a window?

Everything else that doesn't fall into one of the other PB categories.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Post by MyTrial »

Thats working well on my code. But only a imagegadget could not be placed on that disabled imagegadget background - it is not visible. Any ideas?
Sigi
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Code: Select all

RedrawWindow_(GadgetID(#YourImageGadget), 0, 0, #RDW_INVALIDATE)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Post by MyTrial »

Hi Sparkie

thanks that works on windows - not on linux. First my software goes out to windows and in a few months on linux. Maybe there is a chance to get it work on linux?

The ugly thing is: Without your grandios help the image (on the image) does not come up on start up but if i set a window from an other program over it and get it back to the foreground then it is displayed.

Thanks
Sigi
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Will this work....

Code: Select all

ResizeGadget(#YourImageGadget, #PB_Ignore, #PB_Ignore, 0, 0)
ResizeGadget(#YourImageGadget, #PB_Ignore, #PB_Ignore, ImageWidth(#YourImage), ImageHeight(#YourImage))
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Post by MyTrial »

Hi Sparkie

Thanks - that works.
But is a silly and non performant action :)

I tested only with setgadgetstate() but that didn't work. Your trick works only if both resizegadgets are used.

Thanks
Sigi
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Post by MyTrial »

Hi Sparkie

i have that problem with an other gadget too. It is a ListViewGadget() which i use for printing logging data on the screen. When i add items all goes fine until the scroll buttons should come up, then the border and the scroll buttons are hidden and sometimes the whole gadget goes hidden. If i set an other program window over the program then the gadget is visible until the next item is added.

With following code (like your help) after EVERY AddItem() it is shown all the times. Is that a bug or did i something wrong?

Code: Select all

  Width = GadgetWidth(#GUI_Logging)
  Height = GadgetHeight(#GUI_Logging)
  ResizeGadget(#GUI_Logging,#PB_Ignore,#PB_Ignore,0,0)
  ResizeGadget(#GUI_Logging,#PB_Ignore,#PB_Ignore,Width,Height)
Sigi
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Gadgets on top of Gadgets is not the best approach here. I know you're looking for cross platform solutions but I think you're asking a bit much of PureBasic. I highly doubt the troubles you are having are being caused by a PB bug. ;)

I'd need to see some code to see what is happening on your side.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Post by MyTrial »

Maybe i am working the wrong way. My program background is a image. The program has no border. My first way was to draw that picture to the window and then set the gadgets on the window. All works fine until a other program comes in foreground. After my program is back to foreground the background image is gone! So my second way was to use a imagegadget for the background. All times a other program is in foreground and my program comes back the image is always there. That is only why i have a gadget on a gadget.

I have searched in the list and found that other people had the same problems but i didn't found a solution. Maybe i searched wrong or had tomatoes on my eyes and you have a link or a tipp for me. ;)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

MyTrial wrote:...you have a link or a tipp for me. ;)
Sparkie wrote:I'd need to see some code to see what is happening on your side.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Why not place the other gadgets inside the image gadget?

Code: Select all

UseGadgetList(GadgetID(#ImageGadget))
I may look like a mule, but I'm not a complete ass.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Post by MyTrial »

Thanks for your info, srod. But is there somewhere a sample how to use that? I do not understand what this does and how to use it.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Post by MyTrial »

Sparkie my projekt is very big with many sub program files which blows up all here if i post it because i must post all that you can compile that.

So i build a small part of what is going up like the following.

Code: Select all

CreateImage(1,300,300)
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Default)
Box(0,0,300,300,RGB(111,111,222))
StopDrawing()
LoadImage(2,"test.bmp")
StartDrawing(ImageOutput(1))
DrawImage(ImageID(2),0,0,300,300)
StopDrawing()

Flag = #PB_Window_ScreenCentered|#PB_Window_BorderLess
WindowHandler = OpenWindow(#PB_Any,0,0,300,300,"ImageGadgetTest",Flag)
If WindowHandler <> 0
  If CreateGadgetList(WindowID(WindowHandler))
    ImageGadget(3,0,0,300,300,ImageID(1))
    DisableGadget(3,1)
    ButtonGadget(4,10,10,280,20,"new item") 
    Flag = #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection
    ListViewGadget(5,10,40,280,210,Flag) 
    ButtonGadget(6,10,270,280,20,"quit")
  EndIf
EndIf

number = 1

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow : Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 4 : AddGadgetItem(5,-1," a new item - "+Str(number)) : number + 1
        Case 6 : Break
      EndSelect
  EndSelect
ForEver
You can use any image you have for "test.bmp".

But don't cosh me - i don't get it "work" to disable the loaded background image in this sample!? Maybe it is because in the original there are a lot of gadgets? I don't know.
User avatar
Demivec
Addict
Addict
Posts: 4283
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

@MyTrial: Your test code works fine for me. I activated other windows, covered up the program window, then re-exposed it. None of those actions stopped it from working. It always showed the background picture I loaded and displayed the gadgets correctly.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

MyTrial, here's the code you posted adapted so that the 2 buttons and the listview are made child windows of the ImageGadget. This means that the gadgets are physically inside the image gadget.

The subclassed-procedure is required to pass command messages from the image gadget to the main window so that the event loop can trap the button clicks etc.

Code: Select all

Global GoldImageProc, WindowHandler

Procedure ImageGadgetCallback(hWnd, uMsg, wParam, lParam)
  Protected result
  Select uMsg
    Case #WM_COMMAND
      SendMessage_(WindowID(WindowHandler), uMsg, wParam, lParam)
    Default
      result = CallWindowProc_(GoldImageProc, hWnd, uMsg, wParam, lParam)
  EndSelect
EndProcedure


CreateImage(1,300,300) 
StartDrawing(ImageOutput(1)) 
DrawingMode(#PB_2DDrawing_Default) 
Box(0,0,300,300,RGB(111,111,222)) 
StopDrawing() 
LoadImage(2,"test.bmp") 
StartDrawing(ImageOutput(1)) 
DrawImage(ImageID(2),0,0,300,300) 
StopDrawing() 



Flag = #PB_Window_ScreenCentered|#PB_Window_BorderLess 
WindowHandler = OpenWindow(#PB_Any,0,0,300,300,"ImageGadgetTest",Flag) 
If WindowHandler <> 0 
  If CreateGadgetList(WindowID(WindowHandler)) 
    ImageGadget(3,0,0,300,300,ImageID(1)) 
    UseGadgetList(GadgetID(3))
    ButtonGadget(4,10,10,280,20,"new item") 
    Flag = #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection 
    ListViewGadget(5,10,40,280,210,Flag) 
    ButtonGadget(6,10,270,280,20,"quit") 
    GoldImageProc = SetWindowLong_(GadgetID(3), #GWL_WNDPROC, @ImageGadgetCallback())
  EndIf 

EndIf 

number = 1 

Repeat 
  Event = WaitWindowEvent() 
  Select Event 
    Case #PB_Event_CloseWindow : Break 
    Case #PB_Event_Gadget 
      Select EventGadget() 
        Case 4 : AddGadgetItem(5,-1," a new item - "+Str(number)) : number + 1 
        Case 6 : Break 
      EndSelect 
  EndSelect 
ForEver
I may look like a mule, but I'm not a complete ass.
MyTrial
Enthusiast
Enthusiast
Posts: 165
Joined: Thu Nov 30, 2006 11:47 am

Post by MyTrial »

Thanks srod for your help. I really not understand what there is working how (maybe i have a problem in my head ;)). But i see that it uses microsoft specific parts which i should not use because my program should run on windows and linux. By the way - thanks.
Post Reply