Page 2 of 2

Re: Window form background

Posted: Thu Mar 04, 2010 9:26 pm
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

Re: Window form background

Posted: Thu Mar 04, 2010 9:26 pm
by srod
Change :

Code: Select all

hBrush = CreatePatternBrush_(ImageID(5))
to

Code: Select all

Global hBrush = CreatePatternBrush_(ImageID(5))

Re: Window form background

Posted: Thu Mar 04, 2010 9:28 pm
by gabriel
Perfect!!!!!!!!!!!

Thanks

Re: Window form background

Posted: Thu Mar 04, 2010 10:25 pm
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

Re: Window form background

Posted: Thu Mar 04, 2010 11:28 pm
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.

Re: Window form background

Posted: Sun Mar 07, 2010 5:20 pm
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)