How to have a background image in your window
Posted: Sun Oct 12, 2003 9:39 am
Hi,
I did some code to have an image as background using some Windows API calls.
If you replace the WM_PAINT event code with PB standard commands, any gadget won't be shown. I don't know, maybe there is a trick for this too.
I did some code to have an image as background using some Windows API calls.
Code: Select all
Global BitMap
Global Form1
Procedure WindowCallback(WindowID,Message,wParam,lParam)
res=#PB_ProcessPureBasicEvents
Select Message
Case #WM_COMMAND
If lParam=GadgetID(0)
Debug "Gadget pressed."
EndIf
Case #WM_PAINT
ps.PAINTSTRUCT
hdc=BeginPaint_(Form1,ps)
hdcMem=CreateCompatibleDC_(hdc)
SelectObject_(hdcMem,BitMap)
BitBlt_(hdc,1,1,299,299,hdcMem,0,0,#SRCCOPY)
;change dimensions according to your BitMap
DeleteDC_(hdcMem)
DeleteObject_(hdcMem)
EndPaint_(Form1,ps)
;if you use the PureBasic commands, the rendering will be slower and
;above all any eventual gadget will be hidden (!). Try this and see:
;StartDrawing(WindowOutput())
;DrawImage(BitMap,1,1)
;StopDrawing()
ProcedureReturn #TRUE
EndSelect
ProcedureReturn res
EndProcedure
Procedure Open_Window()
Form1=OpenWindow(0,0,0,300,300,0,"")
If Form1
If CreateGadgetList(Form1)
ButtonGadget(0,93,39,227,58,"Sample Button")
EndIf
SetWindowCallback(@WindowCallback())
EndIf
EndProcedure
BitMap=CatchImage(0,?BitM)
Open_Window()
Repeat
Event=WaitWindowEvent()
Until Event=#PB_EventCloseWindow
End
DataSection
BitM: IncludeBinary "yourimage.bmp"
EndDataSection