Thread: Capturing desktop WITHOUT active window

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    5

    Capturing desktop WITHOUT active window

    Hello,

    for my application's needs, I am trying to capture the whole desktop (including children windows), except the active window. I have the capturing code working, but I cannot find reference on how to ignore the active window. Can someone assist me?

    This is on Win32, C++, No MFC.

    Thank you for your time

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    GetDesktopWindow()?
    GetDC()?

    Those should get you enough information to read from the DC.

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    5
    Yep this is what I am using, but it gets the entire window list. Is there a flag to ignore the active window? Or maybe another way?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Could something as simple as hide window, take snapshot, unhide window work? Depending upon how you have your cntls set up, I could see a hack solution working.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by Oldman47 View Post
    Could something as simple as hide window, take snapshot, unhide window work? Depending upon how you have your cntls set up, I could see a hack solution working.
    That is what I was thinking but wondered about the timing (how you would know the 'hide' msg had been processed and so it was time to take the snapshot and show it again).

    SendMessageTimeout() might help.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Dec 2009
    Posts
    5
    Hiding the window I'd not an option unfortunately. I have tried it and it looks a bit ugly.
    Is there a way to get all the active hwnds and create a new hierarchy to use that instead of getdesktopwindow

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Why do you need the other windows and not yours?

    there is possibly another way to do this, rather than a screen scrape.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Registered User
    Join Date
    Dec 2009
    Posts
    5
    I need every window but mine. It is for a game I am making, but I cannot say more

    What other way could there be without the screen capture?

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    That depends on what data/info you need but there are other ways.

    I can see no reason wht a game would need to see the windows under yours, that do not belong to your app.

    I can see why a RAT would need to, but I don't answer those type of questions.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    Registered User
    Join Date
    Dec 2009
    Posts
    5
    I can assure you it's for a game, but I cannot say anything more as it's for acommercial product. My engine does not allow me to run code before the main window creation, and considering I need a screenshot of the original desktop, I need to exclude the engine's window. If you have a solution for it and donor want to make it public, it wold be kind of you to pm me.

  11. #11
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    If this is for a commercial product then I would imagine someone on your development team could figure out how to get this done if you absolutely need it. If you are trying to create some type of screensaver or game that utilizes the desktop as it's background (as many cool screen savers and games have in previous times) there are many ways to do this. Just because your window is not created yet does not mean you cannot still call the API and utilize it's functions. Before you create your window just take a snapshot of the desktop. This will be on a DC from which you can then create a texture out of. In fact this is exactly what IDirect3DTexture<X> does in Direct3D 9/10 and it's how textures are created. Load the data into a DC and then blit the data to a surface from there.

    My engine does not allow me to run code before the main window creation,
    This makes no sense. If you are using the engine then I assume it is you who tells it how to initialize and set itself up. Prior to doing that you can execute the code to grab the desktop and put it into a DC. After the engine starts up you can then use the data to create a texture now that you will have a valid device, assuming you are using Direct3D. Every third party system I've used thus far must be initialized and some even force you to create the device and pass it in.

    If it is some sort of program that takes over the system and then calls your code then you need to minimize or hide it, correctly handle the lost device (which I'm sure the engine does), execute your screen capture code, handle the reset device condition (which I'm sure the engine does), and then blit the data to a texture and create a fullscreen quad that uses the texture. I know this would work for Direct3D so I'm sure it's possible regardless of which graphics API or engine you are using.
    Last edited by VirtualAce; 12-06-2009 at 01:36 PM.

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by alkisbkn View Post
    My engine does not allow me to run code before the main window creation,
    Then your engine creates the main window.

    You should be able to remove the visible style at creation and capture the desktop (without your window) in the response to the create msg (WM_INITDIALOG or WM_CREATE) and then show the window.

    This will not be 'ugly' as the window is yet to appear.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  2. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM