My Version(Mixed with Danilos version):
Windows/Linux:
Code: Select all
;Screenshots unter Windows und Linux erstellen
;Gemischt mit Danilos variante hier: http://www.purearea.net/pb/CodeArchiv/Windows_System/Screenshots/MakeWindowScreenshot.pb
; Autor: DarkDragon/Danilo ;) .
;
#SCREENSHOT_MOUSE = 2
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Procedure GetCurrentCursor(*pt.Point)
hWindow.l
dwThreadID.l
dwCurrentThreadID.l
Result = 0
If GetCursorPos_(*pt)
hWindow = WindowFromPoint_(*pt\x, *pt\y)
If IsWindow_(hWindow)
dwThreadID = GetWindowThreadProcessId_(hWindow, @nil)
dwCurrentThreadID = GetCurrentThreadId_()
If (dwCurrentThreadID <> dwThreadID)
If AttachThreadInput_(dwCurrentThreadID, dwThreadID, 1)
Result.l = GetCursor_()
AttachThreadInput_(dwCurrentThreadID, dwThreadID, 0)
EndIf
Else
Result.l = GetCursor_()
EndIf
EndIf
EndIf
ProcedureReturn Result
EndProcedure
CompilerEndIf
Procedure MakeDesktopScreenshot(ImageNr,x,y,Width,Height,Flags)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
RunProgram("import", "-window root -crop "+Str(Width)+"x"+Str(Height)+"+"+Str(x)+"+"+Str(y)+" /tmp/snapshot.bmp", "/", 1)
hImage = LoadImage(ImageNr, "/tmp/snapshot.bmp")
CompilerElse
hImage = CreateImage(ImageNr,Width,Height)
If hImage
hDC = StartDrawing(ImageOutput())
If hDC
DeskDC = GetDC_(GetDesktopWindow_())
If DeskDC
BitBlt_(hDC,0,0,Width,Height,DeskDC,x,y,#SRCCOPY)
EndIf
ReleaseDC_(GetDesktopWindow_(),DeskDC)
EndIf
If (Flags & #SCREENSHOT_MOUSE)
hCursor = GetCurrentCursor(@pt.Point)
DrawImage(hCursor, pt\x-capX, pt\y-capY)
EndIf
StopDrawing()
EndIf
CompilerEndIf
ProcedureReturn hImage
EndProcedure
Procedure ViewImage()
If OpenWindow(1000, 0, 0, ImageWidth(), ImageHeight(), #PB_Window_SystemMenu, "Image")
CreateGadgetList(WindowID())
ImageGadget(1000, 0, 0, ImageWidth(), ImageHeight(), ImageID())
Repeat
Event = WaitWindowEvent()
Delay(10)
Until Event = #PB_Event_CloseWindow
CloseWindow(1000)
EndIf
EndProcedure
Delay(1000)
hImg = MakeDesktopScreenshot(0,100,300,512,256,#SCREENSHOT_MOUSE)
If hImg
ViewImage()
FreeImage(0)
EndIf
With Mouse-Area-Control:
Code: Select all
#SCREENSHOT_MOUSE = 2
ExamineDesktops()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Procedure GetCurrentCursor(*pt.Point)
hWindow.l
dwThreadID.l
dwCurrentThreadID.l
Result = 0
If GetCursorPos_(*pt)
hWindow = WindowFromPoint_(*pt\x, *pt\y)
If IsWindow_(hWindow)
dwThreadID = GetWindowThreadProcessId_(hWindow, @nil)
dwCurrentThreadID = GetCurrentThreadId_()
If (dwCurrentThreadID <> dwThreadID)
If AttachThreadInput_(dwCurrentThreadID, dwThreadID, 1)
Result.l = GetCursor_()
AttachThreadInput_(dwCurrentThreadID, dwThreadID, 0)
EndIf
Else
Result.l = GetCursor_()
EndIf
EndIf
EndIf
ProcedureReturn Result
EndProcedure
CompilerEndIf
Procedure MakeDesktopScreenshot(ImageNr,x,y,Width,Height,Flags)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
RunProgram("import", "-window root -crop "+Str(Width)+"x"+Str(Height)+"+"+Str(x)+"+"+Str(y)+" /tmp/snapshot.bmp", "/", 1)
hImage = LoadImage(ImageNr, "/tmp/snapshot.bmp")
CompilerElse
hImage = CreateImage(ImageNr,Width,Height)
If hImage
hDC = StartDrawing(ImageOutput())
If hDC
DeskDC = GetDC_(GetDesktopWindow_())
If DeskDC
BitBlt_(hDC,0,0,Width,Height,DeskDC,x,y,#SRCCOPY)
EndIf
ReleaseDC_(GetDesktopWindow_(),DeskDC)
EndIf
If (Flags & #SCREENSHOT_MOUSE)
hCursor = GetCurrentCursor(@pt.Point)
DrawImage(hCursor, pt\x-capX, pt\y-capY)
EndIf
StopDrawing()
EndIf
CompilerEndIf
ProcedureReturn hImage
EndProcedure
Procedure ViewImage()
If OpenWindow(1000, 0, 0, ImageWidth(), ImageHeight(), #PB_Window_SystemMenu, "Image")
CreateGadgetList(WindowID())
ImageGadget(1000, 0, 0, ImageWidth(), ImageHeight(), ImageID())
Repeat
Event = WaitWindowEvent()
Delay(10)
Until Event = #PB_Event_CloseWindow
CloseWindow(1000)
EndIf
EndProcedure
InitSprite()
InitMouse()
Structure Area
X.l
Y.l
Width.l
Height.l
EndStructure
Procedure MouseControlScreenshot(Img, Flags)
Area.Area
MakeDesktopScreenshot(Img,0,0,DesktopWidth(0),DesktopHeight(0), Flags)
OpenScreen(DesktopWidth(0), DesktopHeight(0), 32, "Capture")
Repeat
If IsScreenActive()
ExamineMouse()
MouseX = MouseX()
MouseY = MouseY()
If MouseButton(1)
If capMouse = 0
oMouseX = MouseX
oMouseY = MouseY
capMouse = 1
EndIf
Else
If capMouse = 1
If MouseX < oMouseX : v = oMouseX : oMouseX = MouseX : MouseX = v : EndIf
If MouseY < oMouseY : v = oMouseY : oMouseY = MouseY : MouseY = v : EndIf
Area\X = oMouseX
Area\Y = oMouseY
Area\Width = MouseX-oMouseX
Area\Height = MouseY-oMouseY
Q = 1
EndIf
EndIf
ClearScreen(0, 0, 0)
StartDrawing(ScreenOutput())
DrawImage(ImageID(), 0, 0)
DrawingMode(4|2)
If capMouse <> 0
Box(oMouseX, oMouseY, MouseX-oMouseX, MouseY-oMouseY)
EndIf
DrawingMode(2)
Box(MouseX-1 , MouseY-10, 2 , 20)
Box(MouseX-10, MouseY-1 , 20, 2 )
StopDrawing()
FlipBuffers()
EndIf
Delay(10)
Until Q = 1
CloseScreen()
ImgNew = GrabImage(Img, #PB_Any, Area\X, Area\Y, Area\Width, Area\Height)
FreeImage(Img)
CopyImage(ImgNew, Img)
FreeImage(ImgNew)
ProcedureReturn ImageID()
EndProcedure
Delay(1000)
;hImg = MakeDesktopScreenshot(0,100,300,512,256,#SCREENSHOT_MOUSE)
hImg = MouseControlScreenshot(0,#SCREENSHOT_MOUSE)
If hImg
ViewImage()
FreeImage(0)
EndIf
And on windows it can also show the mousecursor. You need ImageMagick on Linux.