Window form background

Just starting out? Need help? Post your questions and find answers here.
gabriel
Enthusiast
Enthusiast
Posts: 137
Joined: Sat Aug 01, 2009 4:49 pm
Location: Beirut, Lebanon

Re: Window form background

Post by gabriel »

russellbdavis wrote:Perhaps, move the OpenWindow() procedure past the 'End' statement, to the bottom of your code.
I tried, but sorry still not working, curious no?


Code: Select all

UseJPEGImageDecoder()
UseJPEGImageEncoder()

LoadImage (5, "pic1.jpg")
hBrush = CreatePatternBrush_(ImageID(5))

Declare open_window()
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

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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Window form background

Post by srod »

Change :

Code: Select all

hBrush = CreatePatternBrush_(ImageID(5))
to

Code: Select all

Global hBrush = CreatePatternBrush_(ImageID(5))
I may look like a mule, but I'm not a complete ass.
gabriel
Enthusiast
Enthusiast
Posts: 137
Joined: Sat Aug 01, 2009 4:49 pm
Location: Beirut, Lebanon

Re: Window form background

Post by gabriel »

Perfect!!!!!!!!!!!

Thanks
russellbdavis
User
User
Posts: 31
Joined: Wed Dec 02, 2009 4:50 pm
Location: Oklahoma City, OK
Contact:

Re: Window form background

Post by russellbdavis »

If you don't use Global, do this;

Code: Select all

Procedure open_window()
  If OpenWindow(0, 218, 0, 1031, 405, "MOROSH SERIAL PORT MONITOR",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    LoadImage (5, "pic1.jpg")
    hBrush = CreatePatternBrush_(ImageID(5))
    SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
    InvalidateRect_(WindowID(0), 0, 1)
  EndIf
endprocedure
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Window form background

Post by srod »

Better off using some kind of global because, ideally, at program's end (or when you are done with the brush), you would use DeleteObject_() to destroy the brush. You can't do this if the brush handle was stored only within a procedure's local variable etc.
I may look like a mule, but I'm not a complete ass.
User avatar
charvista
Addict
Addict
Posts: 969
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Window form background

Post by charvista »

The variable hBrush is not known in your openwindow() procedure.

Add Global to hBrush:

Code: Select all

Global hBrush = CreatePatternBrush_(ImageID(5))
OR

Add hBrush as parameter to openwindow():

Code: Select all

Procedure open_window(hBrush)
~~~~
open_window(hBrush)
- Windows 11 Home 64-bit
- PureBasic 6.30 (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 8K monitor with DPI @ 300%
Post Reply