I was looking at how to use the clipboard in blitz3d (using the win32 api) and found some PB code to capture the screen and send it to the clipboard.
edit: found some more code on the PB forum that extended this function, it used GetSystemMetrics (for the desktop size) which was better than GetDeviceCaps.
You need to have a file named "User32.decls" in your "userlibs" folder with these declared.
.lib "User32.dll"
; Window Functions
Api_GetClientRect%(hWnd,lpRect*):"GetClientRect"
Api_GetDesktopWindow%():"GetDesktopWindow"
Api_GetForegroundWindow%():"GetForegroundWindow"
Api_GetWindowRect%(hWnd,lpRect*):"GetWindowRect"
; Clipboard Functions
Api_CloseClipboard%():"CloseClipboard"
Api_EmptyClipboard%():"EmptyClipboard"
Api_GetClipboardData%(uFormat):"GetClipboardData"
Api_IsClipboardFormatAvailable%(format):"IsClipboardFormatAvailable"
Api_OpenClipboard%(hwnd):"OpenClipboard"
Api_SetClipboardData%(uFormat,hData):"SetClipboardData"
; Coordinate Space and Transformation Functions
Api_ClientToScreen%(hWnd,lpPoint*):"ClientToScreen"
; Device Context Functions
Api_GetDC%(hWnd):"GetDC"
Api_ReleaseDC%(hwnd,hdc):"ReleaseDC"
; Accessibility Functions
Api_GetSystemMetrics%(nIndex):"GetSystemMetrics"
And a file named "Gdi32.decls" in the "userlibs" folder with these declared.
.lib "Gdi32.dll"
; Bitmap Functions
Api_BitBlt%(hdcDest,nXDest,nYDest,nWidth,nHeight,hdcSrc,nXSrc,nYSrc,dwRop):"BitBlt"
Api_CreateCompatibleBitmap%(hdc,nWidth,nHeight):"CreateCompatibleBitmap"
Api_GetPixel%(hdc,nXPos,nYPos):"GetPixel"
Api_SetPixel%(hdc,X,Y,crColor):"SetPixel"
; Device Context Functions
Api_CreateCompatibleDC%(hdc):"CreateCompatibleDC"
Api_CreateDC%(lpszDriver$,lpszDevice$,lpszOutput$,lpInitData*):"CreateDCA"
Api_DeleteDC%(hdc):"DeleteDC"
Api_DeleteObject%(hObject):"DeleteObject"
Api_GetDeviceCaps%(hdc,nIndex):"GetDeviceCaps"
Api_GetObject%(hgdiobj,cbBuffer,lpvObject*):"GetObjectA"
Api_SelectObject%(hdc,hgdiobj):"SelectObject"
Or you can use the user32.dll decls and gdi32.dll decls.
The CaptureScreenArea function. |
;Capture Screen Area function, by markcw on 14 Jul 06
Graphics3D 320,240,0,2
SetBuffer BackBuffer()
initime=MilliSecs()
While Not KeyHit(1)
If done=0 And MilliSecs()>initime+50 ;wait for text info
done=1 : CaptureScreenArea(0,0,320,240) ;x,y,width,height
EndIf
Cls
Text 0,0,"OK, paste the current clipboard data"
Text 0,12,"to whatever program you use to see"
Text 0,24,"the results of the screen capture."
Text 0,36,"done="+done+" initime="+initime
Flip
Wend
Function CaptureScreenArea(sx,sy,swidth,sheight)
;Capture a given screen area to the clipboard
;From PureBasic CodeArchiv source, by wayne1 on 30/1/2002
Local hdcSrc,hdcDst,hbmp,hold
hdcSrc=Api_GetDC(0) ;hwnd
hdcDst=Api_CreateCompatibleDC(hdcSrc) ;hdc
hbmp=Api_CreateCompatibleBitmap(hdcSrc,swidth,sheight) ;hdc,width,height
hold=Api_SelectObject(hdcDst,hbmp) ;hdc,hobject[bitmap]
Api_BitBlt(hdcDst,0,0,swidth,sheight,hdcSrc,sx,sy,$00CC0020) ;SrcCopy
Api_SelectObject(hdcDst,hold) ;restore old to dc
If Api_OpenClipboard(0) ;hwnd
Api_EmptyClipboard() ;free last data
Api_SetClipboardData(2,hbmp) ;CF_Bitmap,hdata[bitmap]
Api_CloseClipboard()
EndIf
Api_ReleaseDC(0,hdcSrc) ;hwnd,hdc
Api_DeleteDC(hdcDst) ;hdc
End Function |