window background image with DrawImage()

Windows specific forum
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

window background image with DrawImage()

Post 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 ?
- Registered PB user -

Using PB 4.00
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post 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.
- Registered PB user -

Using PB 4.00
User avatar
Mischa
Enthusiast
Enthusiast
Posts: 115
Joined: Fri Aug 15, 2003 7:43 pm

Post 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
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post 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 ;)
- Registered PB user -

Using PB 4.00
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> the ImageGadget() I create still does not redraw by itself

It should. Can you post some code that demonstrates the problem?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post 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.
- Registered PB user -

Using PB 4.00
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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") 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

Bingo !! 8O

I would have NEVER found this myself, thanks you ! :D
- Registered PB user -

Using PB 4.00
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

You're very welcome newbie. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Darth_Dan
New User
New User
Posts: 1
Joined: Mon Jun 23, 2014 9:02 am

Re: window background image with DrawImage()

Post 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.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: window background image with DrawImage()

Post 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?
Little John
Addict
Addict
Posts: 4807
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: window background image with DrawImage()

Post 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
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: window background image with DrawImage()

Post by Danilo »

Could be a next-generation intelligent bot. :wink:
Post Reply