capturing windows with WM_PRINT

BlitzMax Forums/BlitzMax Beginners Area/capturing windows with WM_PRINT

Bremer(Posted 2007) [#1]
I have been trying to make some code to capture all the open windows on the desktop into pixmaps, but failed to find a way to do so.

I found a page explaining that in order to capture the windows that are partially hidden or completely hidden, you should be able to use sendmessage with WM_Print.

The page I found is located here: http://www.fengyuan.com/article/wmprint.html

But I have not been able to get any code working in bmax that uses this sendmessage command and capturing windows into pixmaps.

So what I am asking is if someone with more knowledge of the winapi could take a look at that page, and tell me if its possible at all, and perhaps how to go about it.


grable(Posted 2007) [#2]
I tried using the WM_PRINT method, but couldnt get it to work :(

You could try this instead, it needs the window to be visible on screen though so it may not be what you want...



Bremer(Posted 2007) [#3]
Yes I need to capture windows that are possibly behind other windows as well. And that page mentions that its possible, I just could not get any of it to work.


grable(Posted 2007) [#4]
You could remember the state of each window, show it on screen and capture it, then restore its state.


Bremer(Posted 2007) [#5]
Instead of using the BitBlt function in your code above I found PrintWindow which seems to work.

http://msdn2.microsoft.com/en-us/library/ms535695.aspx

This is how I set it up in bmax:

Function PrintWindow( hwnd:Int, hdcBlt:Int, nFlags:Int)


And I call it like this:

PrintWindow(hwnd,memdc,0)


Now I have to find out, how I get the handles of all windows on the desktop. But I am not having much luck with EnumWindows(), which seems to give me handles for all running processes, and not just windows on the desktop.


grable(Posted 2007) [#6]
Cool! it works on some windows but not all though :/
Many come out black, but that could be an incompatability between the DC/BITMAP or something.

EnumWindows isnt supposed to do that (there are other APIs for enumerating processes), it only enums toplevel windows.


Bremer(Posted 2007) [#7]
I believe that I have found a way to get windows. The following code seems to do the trick.



I just managed to make an alternative way of getting the handles without using enumwindows.



I hope the above code is useful to others as well. It hasn't been easy finding out how to code it, so at least it will be easier for others looking to do the same.

[EDIT]
It also grabs tool windows, like those loose window in drawing packages, so its not 100% yet, but I will keep looking to see if I can't fix that.