Page 1 of 1

window background image with DrawImage()

Posted: Sun Aug 08, 2004 11:34 pm
by newbie
Hi,

I wanted to set a background image, and started with this code :

Code: Select all

UseJPEGImageDecoder(

;- Image Globals
Global Image0

;- Catch Images
Image0 = CatchImage(0, ?Image0)

If (Image0 = 0)
    Debug "error images"
EndIf

;- Images
DataSection 
Image0 :
IncludeBinary "C:\myrep\myimage.jpg"

EndDataSection
then after at the start of the code :

Code: Select all

Open_Window_0()

StartDrawing(WindowOutput())
DrawImage(Image0, 0, 0, 667, 275) 
StopDrawing()
The image appears, it's ok, but as soon as I move a window over my window, the image is wiped at this area and does not redraw.
Same if i minimize the window and open it again, the image has disapeared completly.

Is there something I miss ?

Posted: Sun Aug 08, 2004 11:39 pm
by Pupil
Use an image gadget to hold you image to get the redrawing done automaticly, else you have to do this yourself everytime your window get covered by another window.

Posted: Mon Aug 09, 2004 12:04 am
by newbie
I didn't know that, thx ;)

But unfortunaly, even if I have others apps where I already used imagegadget and where the Image never disapear, this time on this app the image still goes away 8O
(the image displays first ok with borders, but after moving another window on it, just the empty "border" lines remain).

Must be something on my side so, I'll try to find out and report here If I find.

Posted: Wed Aug 11, 2004 1:42 pm
by Mischa
Try this:

Code: Select all

Image = CatchImage(0, ?Image0)
brush = CreatePatternBrush_(Image) 
SetClassLong_(WindowID(),#GCL_HBRBACKGROUND,brush)

Before your program terminates you have to call:

Code: Select all

DeleteObject_(brush)
Regards,
Mischa

Posted: Wed Aug 11, 2004 3:22 pm
by newbie
Thanks Mischa,

this works fine indeed, and does not disapear.
What is still weird thought, is that the ImageGadget() I create still does not redraw by itself :?

Anyway your tip is very good and working ;)

Posted: Wed Aug 11, 2004 8:44 pm
by PB
> the ImageGadget() I create still does not redraw by itself

It should. Can you post some code that demonstrates the problem?

Posted: Wed Aug 11, 2004 8:46 pm
by Shannara
Wow, this works for a normal window but not a mdi window, it does it properly, but once you start the mdi control, it'll only do this to a non-mdi section.. erk! and not the client area... weird.

Posted: Wed Aug 11, 2004 10:27 pm
by newbie
PB wrote:> the ImageGadget() I create still does not redraw by itself

It should. Can you post some code that demonstrates the problem?
This one does not redraw on my comp :

Code: Select all

;- Image Plugins
;UseEC_OLEImageDecoder()
UseJPEGImageDecoder()

;- Image Globals
Global Image0

;- Catch Images
Image0 = CatchImage(0, ?Image0)


;- Images
DataSection
Image0:
IncludeBinary "C:\myrep\binary3.jpg"
EndDataSection

;- Window Constants
;
Enumeration
    #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
    #Image_0
EndEnumeration

Procedure Open_Window_0()
    If OpenWindow(#Window_0, 114, 111, 645, 260,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_MinimizeGadget , "no redraw :")
        If CreateGadgetList(WindowID())
            
            ImageGadget(#Image_0, 5, 20, 30, 230, Image0, #PB_Image_Border)
        EndIf
    EndIf
EndProcedure

Open_Window_0()

hwnd = WindowID(#Window_0)
;SysTrayIcon = ExtractIcon_(hwnd,"client.exe",0)
SysTrayIcon = LoadImage(0, "E:\myrep\block2.ico")
AddSysTrayIcon(0, WindowID(0), SysTrayIcon) 
SysTrayIconToolTip(0, "toto")

;Interception des evenements
Repeat ;tant que fenetre non fermée
    Repeat ; tant qu'il y a des evnements
        ;evenements fenetre
        EventID.l = WindowEvent()
        
        If EventID = 0  ; We wait only when nothing is being done
            Sleep_(20)
        EndIf
        
        Select EventID 
            ;
            ;FENETRE
            ;
            Case #PB_EventCloseWindow ;fermeture fenetre
                Quit = 1
                
            Case #PB_Event_SysTray
                
                Select EventType() 
                    
                    Case #PB_EventType_LeftDoubleClick 
                        HideWindow(#Window_0, 0)
                        
                EndSelect
                ;
                ;OBJETS
                ;
            Case #PB_Event_Gadget     ;evenements des controles de la feuille
                Gadget = EventGadgetID()
                Select Gadget
                    
                    
                        
                EndSelect
                
            Default
                If IsIconic_(hwnd) <> 0 ;the window has been minimized 
                    If MainWindowState = 0
                        HideWindow(#Window_0, 1)
                        MainWindowState = 1
                    EndIf
                Else
                    MainWindowState = 0
                EndIf     
                
        EndSelect
    Until EventID <> 0
Until Quit = 1
I have the lastest final purebasic v3.91, and I'm using jaPBe 2.4.7.17.

Posted: Wed Aug 11, 2004 10:50 pm
by Sparkie
You are using the same Image# 0 for 2 different images. Loading the SysTrayIcon wipes out the CatchImage.

Code: Select all

Image0 = CatchImage(0, ?Image0) 

SysTrayIcon = LoadImage(0, "E:\myrep\block2.ico") 

Try changing the SysTrayIcon to image# 1

Code: Select all

SysTrayIcon = LoadImage(1, "E:\myrep\block2.ico") 

Posted: Wed Aug 11, 2004 11:00 pm
by newbie
Bingo !! 8O

I would have NEVER found this myself, thanks you ! :D

Posted: Wed Aug 11, 2004 11:06 pm
by Sparkie
You're very welcome newbie. :)

Re: window background image with DrawImage()

Posted: Mon Jun 23, 2014 9:04 am
by Darth_Dan
You could just look in the help:


Content drawn on a window will be erased whenever the window or a part of it is covered by another window, moved outside of the screen or when the window is hidden or minimized. So to keep the drawn content visible, it must be redrawn after every #PB_Event_Repaint event. A more convenient alternative is to draw the content to an image via ImageOutput() and display it as ImageGadget() in the application window and if necessary, update it with SetGadgetState(). This way all needed refreshing will be handled by the ImageGadget.

Re: window background image with DrawImage()

Posted: Tue Jun 24, 2014 6:45 am
by Danilo
Profile: newbie
- Last visited: 20 Feb 2009
- Using PB 4.00

Too late, Darth_Dan. :D

Did you just register to answer this 10 years old thread?

Re: window background image with DrawImage()

Posted: Tue Jun 24, 2014 7:05 am
by Little John
Danilo wrote:Did you just register to answer this 10 years old thread?
And the problem has already been solved 10 years ago ...
Danilo, don't be surprised, just be flabbergasted. :D

Re: window background image with DrawImage()

Posted: Tue Jun 24, 2014 7:16 am
by Danilo
Could be a next-generation intelligent bot. :wink: