Hi all,
it's possible capture portion of screen outside the program of glbasic (capture desktop,explorer,firefox etc)?
I would like write a magnifier program in windows system.
Thank you
Edo
Not with internal GLBasic commands. You'll need to contain C++ instructions by using the INLINE command.
I 'wrote' (a.k.a. copied from examples in other languages) this in Blitz:
Function Screenshot2DBuffer(DestinationBuffer,BufferWidth,BufferHeight)
If DestinationBuffer = 0 Or BufferWidth = 0 Or BufferHeight = 0 Then Return False
OriginalBufferWidth = BufferWidth
BufferWidth = BufferWidth / 16
If BufferWidth * 16 <> OriginalBufferWidth Then BufferWidth = (BufferWidth + 1) * 16 Else BufferWidth = OriginalBufferWidth
hDC = GetDC(0)
hMemDC= CreateCompatibleDC(hdc)
hMemBmp= CreateCompatibleBitmap(hdc,BufferWidth,BufferHeight)
bmi = CreateBank(48)
PokeByte bmi,0,44
PokeInt bmi,4,BufferWidth
PokeInt bmi,8,-BufferHeight
PokeByte bmi,12,1
PokeByte bmi,14,32
SelectObject hMemDC, hMemBmp
BitBlt hMemDC, 0, 0, BufferWidth, BufferHeight, hDC, 0, 0, $00CC0020
If BufferWidth = OriginalBufferWidth Then
LockBuffer DestinationBuffer
LocBnk = CreateBank(76)
MoveMemoryObjInt(LocBnk,DestinationBuffer,76)
Loc = PeekInt(LocBnk,72)
FreeBank LocBnk
GetDIBitsInt hDC,hMemBmp,0,BufferHeight,Loc,bmi,0
UnlockBuffer DestinationBuffer
Else
TemporaryImage = CreateImage(BufferWidth,BufferHeight)
TemporaryBuffer = ImageBuffer(TemporaryImage)
LocBnk = CreateBank(76)
LockBuffer TemporaryBuffer
MoveMemoryObjInt(LocBnk,TemporaryBuffer,76)
Loc = PeekInt(LocBnk,72)
FreeBank LocBnk
GetDIBitsInt hDC,hMemBmp,0,BufferHeight,Loc,bmi,0
UnlockBuffer TemporaryBuffer
CopyRect 0,0,OriginalBufferWidth,BufferHeight,0,0,TemporaryBuffer,DestinationBuffer
EndIf
ReleaseDC 0, hDC
DeleteDC hMemDC
DeleteObject hMemBmp
FreeBank bmi
Return True
End Function
This takes a screenshot of the entire screen ('0' as a window handle represents the desktop, which is the parent window of every other window, and so the screenshot is of all windows - i.e. the entire screen).
I can't expect you to understand everything that's going on there (I almost don't myself because I converted it from a PowerBASIC example...), but essentially "BitBlt" copies the image data to a windows image in memory. "GetDIBits" (which I called GetDIBitsInt) will return that info in something like BGRA format.
A lot of the stuff involving 'Banks' is just because there is no MEM2SPRITE command, so you're forced to find the data at an offset from an internal struct, then copy the info from a memory bank... which you won't have to do in GLBasic.
You should also be able to specify a specific rectangle to capture (such as area around the mouse) rather than the whole screen, but unfortunately I don't have the time at the moment to try and convert some of that code into C++ in GLBasic...
In my quick googling efforts, I can't find any screen capture example in C++ that I can understand, but this looks like a good example in PowerBASIC, which is understandable although unusable until converted... http://www.jose.it-berater.org/smfforum/index.php?topic=2775.0 (http://www.jose.it-berater.org/smfforum/index.php?topic=2775.0)