M
Me Mine
i,
I have trying to code a small console app that will
allow a user to select a window and then create a
screen capture of the window. I haven't been able to
figure out how to do the screen capture part. The
code is as follows, the commented out lines at the end
are things I have tried, but don't work. Whenever I
try to create a compatibe Bitmap or DC it comes back
with an error as
win32ui: CreateCompatibleDC failed
or
AttributeError: CreateCompatibleDC
Any help would be greatly appreciated.
import win32gui
import win32ui
numWindows = 0
windows = []
winDict = {}
windowsText=[]
inc = 0
def _MyCallback( hwnd, extra ):
extra.append(hwnd)
win32gui.EnumWindows(_MyCallback, windows)
for i in windows:
if win32gui.IsWindowVisible(i):
if win32gui.IsWindowVisible:
windowsText.append(i)
winDict[numWindows] = i
numWindows +=1
print "Please select a window to capture"
for window in windowsText:
windowText = win32gui.GetWindowText(window)
print inc, windowText
inc += 1
selection = input()
print win32gui.GetWindowText(winDict[selection])
myDC = win32ui.CreateDCFromHandle(winDict[selection])
win32gui.SetForegroundWindow(winDict[selection])
win_sz = win32gui.GetClientRect(winDict[selection])
myBitMap = win32ui.CreateBitmap()
#myMemDC = win32ui.CreateCompatibleDC(myDC)
#myBitMap.BitBlt((0,0),(win_sz[2],win_sz[3],myDC,(0,0),0))
#myBitMap.CreateCompatibleBitMap(myDC,win_sz[2], win_sz[3])
#myBitMap.CreateCompatibleDC(myDC)
Thanks,
Rob
I have trying to code a small console app that will
allow a user to select a window and then create a
screen capture of the window. I haven't been able to
figure out how to do the screen capture part. The
code is as follows, the commented out lines at the end
are things I have tried, but don't work. Whenever I
try to create a compatibe Bitmap or DC it comes back
with an error as
win32ui: CreateCompatibleDC failed
or
AttributeError: CreateCompatibleDC
Any help would be greatly appreciated.
import win32gui
import win32ui
numWindows = 0
windows = []
winDict = {}
windowsText=[]
inc = 0
def _MyCallback( hwnd, extra ):
extra.append(hwnd)
win32gui.EnumWindows(_MyCallback, windows)
for i in windows:
if win32gui.IsWindowVisible(i):
if win32gui.IsWindowVisible:
windowsText.append(i)
winDict[numWindows] = i
numWindows +=1
print "Please select a window to capture"
for window in windowsText:
windowText = win32gui.GetWindowText(window)
print inc, windowText
inc += 1
selection = input()
print win32gui.GetWindowText(winDict[selection])
myDC = win32ui.CreateDCFromHandle(winDict[selection])
win32gui.SetForegroundWindow(winDict[selection])
win_sz = win32gui.GetClientRect(winDict[selection])
myBitMap = win32ui.CreateBitmap()
#myMemDC = win32ui.CreateCompatibleDC(myDC)
#myBitMap.BitBlt((0,0),(win_sz[2],win_sz[3],myDC,(0,0),0))
#myBitMap.CreateCompatibleBitMap(myDC,win_sz[2], win_sz[3])
#myBitMap.CreateCompatibleDC(myDC)
Thanks,
Rob