API/ Pointers/ Peek Question

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

I'm tinkering with Franco's code snippet to capture the desktop. After many trials I cannot get the right syntax for reading data from the bitmap structure returned by "GetCurrentObject_". I have tried many different variations but trying to Peek() raises an illegal op error. Help! Please.


Procedure CaptureDesktop()
DC.l = GetDC_(0)
MDC.l = CreateCompatibleDC_(DC)
Image.l = CreateCompatibleBitmap_(DC,GetSystemMetrics_(#SM_CXSCREEN),GetSystemMetrics_(#SM_CYSCREEN))
SelectObject_(MDC,Image)
BitBlt_(MDC, 0, 0, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN),DC, 0, 0, $0CC0020)
Bitmap = GetCurrentObject_(MDC, 7)

MessageRequester("Width",Str(PeekL(Bitmap+4)),#MB_OK)

; OpenClipboard_(0)
; EmptyClipboard_()
; SetClipboardData_(2,Image)
; CloseClipboard_()
DeleteObject_(Image)
DeleteDC_(MDC)
ReleaseDC_(0,DC)
EndProcedure

CaptureDesktop()
End
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

Never mind, I think I am going about it the wrong way. My WinAPI knowledge is a bit rusty. Basically I'm trying to capture the desktop as a bitmap so I can use it as a texture in opengl. If anyone has any hints I'd appreciate it. In the mean time I'll trawl the forums again.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

I think Bitmap is a handle, not a pointer, so you can't Peek it (well, you can, but the code will probably crash). I don't have further info now, but it's not difficult to get that BMP structure, I think there may be even some examples if you search in the forum (try BITMAPINFO, for instance).

Bye,

El_Choni
Post Reply