
Code: Select all
ProcedureDLL MakeDesktopScreenshot(x,y,Width,Height) ;Returns ImageID
Protected hImage,Image
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
If IsImage(Image) :FreeImage(Image) :EndIf
Image = CreateImage(#PB_Any,Width,Height)
hImage = ImageID(Image)
Protected hDC = StartDrawing(ImageOutput(Image))
Protected DeskDC = GetDC_(GetDesktopWindow_())
BitBlt_(hDC,0,0,Width,Height,DeskDC,x,y,#SRCCOPY)
ReleaseDC_(GetDesktopWindow_(),DeskDC)
StopDrawing()
CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
Protected *src.GdkDrawable = gdk_window_lookup_(gdk_x11_get_default_root_xwindow_())
hImage = gdk_pixbuf_get_from_drawable_(#Null, *src, #Null, x, y, #Null, #Null,Width,Height)
CompilerEndIf
ProcedureReturn hImage
EndProcedure
ProcedureDLL SetWindowBackGroundImage(ImageID, Window)
Protected WindowID=WindowID(Window)
If WindowID
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected *Background, FixedBox.I, *Style.GtkStyle
gdk_pixbuf_render_pixmap_and_mask_(ImageID, @*Background, 0, 0)
*Style = gtk_style_new_()
*Style\bg_pixmap[0] = *Background
FixedBox = g_list_nth_data_(gtk_container_get_children_(gtk_bin_get_child_(WindowID)), 0)
gtk_widget_set_style_(FixedBox, *Style)
CompilerCase #PB_OS_Windows
Protected BrushImageID = CreatePatternBrush_(ImageID)
SetClassLongPtr_(WindowID, #GCL_HBRBACKGROUND, BrushImageID)
;InvalidateRect_(WindowID, 0, #True)
RedrawWindow_(WindowID, #Null, #Null, #RDW_INVALIDATE)
CompilerEndSelect
EndIf
EndProcedure
ProcedureDLL SetGadgetBackGroundImage(ImageID, Gadget)
Protected GadgetID = GadgetID(Gadget)
If GadgetID
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected *Background, FixedBox.I, *Style.GtkStyle
gdk_pixbuf_render_pixmap_and_mask_(ImageID, @*Background, 0, 0)
*Style = gtk_style_new_()
*Style\bg_pixmap[0] = *Background
gtk_widget_set_style_(GadgetID, *Style)
CompilerCase #PB_OS_Windows
Protected BrushImageID = CreatePatternBrush_(ImageID)
SetClassLongPtr_(GadgetID, #GCL_HBRBACKGROUND, BrushImageID)
;InvalidateRect_(WindowID, 0, #True)
RedrawWindow_(GadgetID, #Null, #Null, #RDW_INVALIDATE)
CompilerEndSelect
EndIf
EndProcedure
Enumeration
#window1
#window2
#container
EndEnumeration
Define ImageID = MakeDesktopScreenshot(0,0,300,300)
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#window1, #PB_Any, #PB_Any, 300, 300, "background image on window", wFlags)
ResizeWindow(#window1, WindowX(#window1) - 160, #PB_Ignore, #PB_Ignore, #PB_Ignore)
SetWindowBackGroundImage( ImageID,#window1)
OpenWindow(#window2, #PB_Any, #PB_Any, 300, 300, "background image on container", wFlags)
ResizeWindow(#window2, WindowX(#window2) + 160, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ContainerGadget(#container, 0, 0, 300, 300)
SetGadgetBackGroundImage(ImageID,#container )
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend