GetClipboardData(CF_BITMAP) unimplemented

K

Kyle Harrigan

Win32all folks:

I am attempting to use win32all to perform screen captures and save
the bitmap to a file. The call to GetClipboardData fails saying
GetClipboardData(CF_BITMAP) is unimplemented. Any ideas?

My code looks something like this:

win32api.keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0)
win32clipboard.OpenClipboard()
format = win32clipboard.EnumClipboardFormats()
data = win32clipboard.GetClipboardData(format)
win32clipboard.CloseClipboard()
writeFile = open('outfile.bmp','w')
writeFile.write(data)
writeFile.close()
 
M

Michel Claveau/Hamster

Hi !


And the same for .SetClipboardData(
Please... Please ?

Thanks by advance.
 
R

Roger Upole

It's just that nobody has written code yet to do anything with the returned
bitmap handle. However, you can still do screen captures without it.
The below code should also work with just about any window handle,
not just the desktop
Roger

import win32gui, win32ui, win32con
hwnd=win32gui.GetDesktopWindow()
l,t,r,b=win32gui.GetWindowRect(hwnd)
h=b-t
w=r-l
hDC = win32gui.GetWindowDC(hwnd)
myDC=win32ui.CreateDCFromHandle(hDC)
newDC=myDC.CreateCompatibleDC()

myBitMap = win32ui.CreateBitmap()
myBitMap.CreateCompatibleBitmap(myDC, w, h)

newDC.SelectObject(myBitMap)
newDC.BitBlt((0,0),(w, h) , myDC, (0,0), win32con.SRCCOPY)
myBitMap.Paint(newDC)
myBitMap.SaveBitmapFile(newDC,'c:\\tmp.bmp')
 
M

Michel Claveau/Hamster

Hi !

For screen-capture, with PIL, you can do too :

import Image, ImageGrab
ImageGrab.grab().save(filename)



But the question talk of CLIPBOARD and bitmap.



@+
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top