Re: GetClipboardData(CF_BITMAP) unimplemented

From: Roger Upole (rupole_at_hotmail.com)
Date: 05/21/04


Date: Thu, 20 May 2004 20:38:47 -0400

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')

"Kyle Harrigan" <kwharrigan@yahoo.com> wrote in message
news:90924643.0405200902.610baf23@posting.google.com...
> 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()