Window capture using WM_PRINT and Python

A

arN

Hi !

I'm a Java developper and I wish to make a capture of an offscreen
window (on WinXP). It's not possible in Java, so I use a python script
and WM_PRINT, but it doesn't seem to work.

Could someone have a look at my script and give me any advise ?

TIA

--
Arnaud
my python script : python snap.py GraphicalContext_handle image_handle
--------------------------------------------------------------------------------------------------
snap.py :
"
import win32api, win32con, sys

win32api.SendMessage(sys.argv[2], win32con.WM_PAINT, sys.argv[3], 0)
win32api.SendMessage(sys.argv[2], win32con.WM_PRINT, sys.argv[3],
win32con.PRF_CHILDREN | win32con.PRF_CLIENT | win32con.PRF_OWNED)
"

------------------------------------------------------------------------------------------------
snippet from Snapshot.java :
"
public static Image snapshot(Composite bean) {
GC gc = new GC(bean);
final Image image = new Image (null, bean.getBounds().width,
bean.getBounds().height);
String commmand = "python snap.py " + gc.handle + " " + image.handle;

Runtime rt = Runtime.getRuntime();
try {
Process p = rt.exec(command);
} catch (.....)

gc.dispose();
return image;
}
"
 
R

Roger Upole

Do you get any kind of traceback when you start a process that way?
There's not much info to go on.

Sys.argv parameters are passed as strings. You'll need to do an int() on
them
before you can use them as handles. Also, not all handles are portable
between processes. Your device context handle might not be valid
even if you make it an int.

hth
Roger


arN said:
Hi !

I'm a Java developper and I wish to make a capture of an offscreen window
(on WinXP). It's not possible in Java, so I use a python script and
WM_PRINT, but it doesn't seem to work.

Could someone have a look at my script and give me any advise ?

TIA

--
Arnaud
my python script : python snap.py GraphicalContext_handle image_handle
--------------------------------------------------------------------------------------------------
snap.py :
"
import win32api, win32con, sys

win32api.SendMessage(sys.argv[2], win32con.WM_PAINT, sys.argv[3], 0)
win32api.SendMessage(sys.argv[2], win32con.WM_PRINT, sys.argv[3],
win32con.PRF_CHILDREN | win32con.PRF_CLIENT | win32con.PRF_OWNED)
"

------------------------------------------------------------------------------------------------
snippet from Snapshot.java :
"
public static Image snapshot(Composite bean) {
GC gc = new GC(bean);
final Image image = new Image (null, bean.getBounds().width,
bean.getBounds().height);
String commmand = "python snap.py " + gc.handle + " " + image.handle;

Runtime rt = Runtime.getRuntime();
try {
Process p = rt.exec(command);
} catch (.....)

gc.dispose();
return image;
}
"
 

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

Similar Threads

[Newbie] Need help 1
[Newbie] need help 1
Python and Windows Services Question 1

Members online

Forum statistics

Threads
474,216
Messages
2,571,116
Members
47,720
Latest member
mohdkaif002

Latest Threads

Top