old example to set window background not working

Just starting out? Need help? Post your questions and find answers here.
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

old example to set window background not working

Post by morosh »

Hello:

I tried a code posted here by TI-994A, several years ago, to set window background, it's not wotking. i modified it slightly:

Code: Select all

Procedure SetBackgroundImage(containerNo, imageNo)
  If IsWindow(containerNo)
    hWnd = WindowID(containerNo)
    imgWidth = WindowWidth(containerNo)
    imgHeight = WindowHeight(containerNo)
    result = #True
  ElseIf IsGadget(containerNo)
    hWnd = GadgetID(containerNo)
    imgWidth = GadgetWidth(containerNo)
    imgHeight = GadgetHeight(containerNo)
    result = #True
  Else
    result = #False
  EndIf
  If result
    ResizeImage(imageNo, imgWidth, imgHeight)
    image = CreatePatternBrush_(ImageID(imageNo))
    If image
      SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, image)
      RedrawWindow_(hWnd, #Null, #Null, #RDW_INVALIDATE)
      result = #True
    Else
      result = #False
    EndIf 
  EndIf
  ProcedureReturn result
EndProcedure

LoadImage(0, "C:\Program Files (x86)\PureBasic\Examples\Sources\Data\purebasic.bmp")

OpenWindow(0, 100, 100, 300, 300, "SetBackgroundImage")
SetBackgroundImage(0, 0)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend 

PureBasic: Surprisingly simple, diabolically powerful
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: old example to set window background not working

Post by RASHAD »

Try

Code: Select all

OpenWindow(0, 100, 100, 300, 300, "SetBackgroundImage")
SetBackgroundImage(0, 0)
InvalidateRect_(WindowID(0),0,1)
Egypt my love
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: old example to set window background not working

Post by morosh »

Thanks Rashad
works fine!!!
the image is streched, is it possible to be tiled/duplicated instead?
PureBasic: Surprisingly simple, diabolically powerful
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: old example to set window background not working

Post by RASHAD »

Hi

Code: Select all

LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\purebasic.bmp")
hBrush = CreatePatternBrush_(ImageID(0))
OpenWindow(0,0,0,400,300,"Test",#PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_TitleBar|#PB_Window_SizeGadget) 
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(0),0,1)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect  
Until Quit = 1
Egypt my love
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: old example to set window background not working

Post by morosh »

thanks Rashad, works great!!

next step, I like to implement MDI gadgets, it seems conflicting

Code: Select all

Procedure SetBackgroundImage(containerNo, imageNo)
  If IsWindow(containerNo)
    hWnd = WindowID(containerNo)
    imgWidth = WindowWidth(containerNo)
    imgHeight = WindowHeight(containerNo)
    result = #True
  ElseIf IsGadget(containerNo)
    hWnd = GadgetID(containerNo)
    imgWidth = GadgetWidth(containerNo)
    imgHeight = GadgetHeight(containerNo)
    result = #True
  Else
    result = #False
  EndIf
  If result
;    ResizeImage(imageNo, imgWidth, imgHeight)
    hBrush = CreatePatternBrush_(ImageID(imageNo))
    If hBrush
      SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush)
      RedrawWindow_(hWnd, #Null, #Null, #RDW_INVALIDATE)
      result = #True
    Else
      result = #False
    EndIf 
  EndIf
  ProcedureReturn result
EndProcedure

LoadImage(0, "C:\Program Files (x86)\PureBasic\Examples\Sources\Data\purebasic.bmp")
OpenWindow(0, 100, 100, 600, 300, "SetBackgroundImage")
SetBackgroundImage(0, 0)
InvalidateRect_(WindowID(0),0,1)

mdi=MDIGadget(0, 0, 0, 0, 0, 4, 0, #PB_MDI_AutoSize)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend 

PureBasic: Surprisingly simple, diabolically powerful
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: old example to set window background not working

Post by RASHAD »

No need for the procedure

Code: Select all

LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\purebasic.bmp")
LoadImage(1, #PB_Compiler_Home + "Examples\Sources\Data\Background.bmp")
hBrush = CreatePatternBrush_(ImageID(0))
hBrush2 = CreatePatternBrush_(ImageID(1))

OpenWindow(0, 0, 0, 600, 400, "SetBackgroundImage",#PB_Window_SystemMenu |#PB_Window_ScreenCentered)
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)

mdi = MDIGadget(0, 10, 10, 300,300, 4, 0, #PB_MDI_NoScrollBars)
SetClassLongPtr_(mdi, #GCL_HBRBACKGROUND, hBrush2)

InvalidateRect_(WindowID(0),0,1)

While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend 
Egypt my love
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: old example to set window background not working

Post by morosh »

Thanks Rashad
works like a charm
PureBasic: Surprisingly simple, diabolically powerful
Post Reply