screenshots before a window pops up?

This is a discussion on screenshots before a window pops up? within the Game Programming forums, part of the General Programming Boards category; does anyone know of a way to get a screenshot before the window for a program comes up? what i'm ...

  1. #1
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176

    Question screenshots before a window pops up?

    does anyone know of a way to get a screenshot before the window for a program comes up? what i'm wanting is to take a screenshot, save it as a .BMP, and use it as a background in a program using allegro. it's done in some screensavers (the funky lens effects that bounce on the screen.. that one with the dog, ripping things up). anyone have any ideas? i don't know if it's even possible.. thought i'd give it a shot though.

    windows XP home
    MSVC++ 6.0 with allegro.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    BitBlt()

  3. #3
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    yuuuuuuum....blt....*drools*

  4. #4
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    er.. alrite. i'll look into that. thanks!

    *hands ride -or- die a mop and bucket* you made a mess in my thread

  5. #5
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    are you wanting to save a bitmap when your allegro program is run? sorry, i didn't quite understand your question.

    if you are wanting to save a bitmap with your allegro program you should look into your bitmap routines in the allegro docs. there is a save function for it.

  6. #6
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    i'm wanting to save a picture of the desktop (or whatever windows there are open) before the window for my program pops up. it's kind of hard to explain.. i sort of want it so the print screen button is pressed, but before the window for my program pops up (and gets in the way). make any sense..? i'll look into that bitblt() thing.

  7. #7
    Perverted unanimous's Avatar
    Join Date
    Oct 2001
    Posts
    336
    Are you saying that you want your program to take a picture of the desktop but your problem is that your app comes upp and it takes a picture of your app instead of the desktop?

  8. #8
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    lol.. i had forgotten about this topic.. still interested though.

    yes, exactly. but by 'desktop', i don't mean just wallpaper.. i mean wallpaper, icons, taskbar, and any windows open (besides my app).
    If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrariwise, what it is, it wouldn't be, and what it wouldn't be, it would. You see?

  9. #9
    eats only heads
    Guest
    you could cause the program to minimize itself.

  10. #10
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    I don't think Allegro is capable of that, so you should try win32
    programming in combination with Allegro, with win32 you can do
    anything so this as well (i think)

  11. #11
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    Make a Win32 program that takes a screen and saves it as a bmp file. Make it open up your allegro game as it closes, and make the allegro game read in the bmp file.

  12. #12
    Registered User dead_cell's Avatar
    Join Date
    Jun 2002
    Posts
    44
    I don't think simulate_keypress() would work here, would it?

    The only other way i could see this being done would indeed be through a win32 API function call and drawing the image data to the BITMAP allegro buffer.
    Linux is great - It does infinite loops in five seconds!

    ~Linus Torvalds

  13. #13
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    Here's what my reference material has to say. If you want to take a screenshot just do it before you show your window for the first time or call ShowWindow(hWnd, SW_HIDE);
    Where hWnd is a handle to your program's window.

    @ dead_cell: I've never heard of simulate_keypress, would it be defined as:?
    Code:
    VOID simulate_keypress(BYTE bVk, BYTE bScan, DWORD dwFlags, DWORD dwExtraInfo )
    {
        keybd_event(bVk, bScan, dwFlags, dwExtraInfo);
    }
    // Quote:

    You can use a bitmap to capture an image, and you can store the captured image in memory, display it at a different location in your application's window, or display it in another window.

    In some cases, you may want your application to capture images and store them only temporarily. For example, when you scale or "zoom" a picture created in a drawing application, the application must temporarily save the normal view of the image and display the zoomed view. Later, when the user selects the normal view, the application must replace the zoomed image with a copy of the normal view that it temporarily saved.
    To store an image temporarily, your application must call CreateCompatibleDC to create a DC that is compatible with the current window DC. After you create a compatible DC, you create a bitmap with the appropriate dimensions by calling the CreateCompatibleBitmap function and then select it into this device context by calling the SelectObject function.

    After the compatible device context is created and the appropriate bitmap has been selected into it, you can capture the image. The Win32 API provides the BitBlt function to capture images. This function performs a bit block transfer that is, it copies data from a source bitmap into a destination bitmap. Because it copies data from bitmaps, you'd expect that two arguments to this function would be bitmap handles; however, this is not the case. Instead, BitBlt receives handles that identify two device contexts and copies the bitmap data from a bitmap selected into the source DC into a bitmap selected into the target DC. In this case, the target DC is the compatible DC, so when BitBlt completes the transfer, the image has been stored in memory. To redisplay the image, call BitBlt a second time, specifying the compatible DC as the source DC and a window (or printer) DC as the target DC.

    The following example code, from an application that captures an image of the entire desktop, creates a compatible device context and a bitmap with the appropriate dimensions, selects the bitmap into the compatible DC, and then copies the image using the BitBlt function.

    Code:
    /*  
     * Create a normal DC and a memory DC for the entire screen. The 
     * normal DC provides a "snapshot" of the screen contents. The 
     * memory DC keeps a copy of this "snapshot" in the associated 
     * bitmap. 
     */ 
     
    hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); 
    hdcCompatible = CreateCompatibleDC(hdcScreen); 
     
    /* Create a compatible bitmap for hdcScreen. */ 
     
    hbmScreen = CreateCompatibleBitmap(hdcScreen, 
                         GetDeviceCaps(hdcScreen, HORZRES), 
    
                         GetDeviceCaps(hdcScreen, VERTRES)); 
     
    if (hbmScreen == 0) 
        errhandler("hbmScreen", hwnd); 
     
    /* Select the bitmaps into the compatible DC. */ 
     
    if (!SelectObject(hdcCompatible, hbmScreen)) 
        errhandler("Compatible Bitmap Selection", hwnd); 
     
            /* Hide the application window. */ 
     
            ShowWindow(hwnd, SW_HIDE); 
     
            /* 
             * Copy color data for the entire display into a 
             * bitmap that is selected into a compatible DC. 
    
             */ 
     
            if (!BitBlt(hdcCompatible, 
                   0,0, 
                   bmp.bmWidth, bmp.bmHeight, 
                   hdcScreen, 
                   0,0, 
                   SRCCOPY)) 
     
            errhandler("Screen to Compat Blt Failed", hwnd); 
     
            /* Redraw the application window. */ 
     
            ShowWindow(hwnd, SW_SHOW);
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  14. #14
    Registered User dead_cell's Avatar
    Join Date
    Jun 2002
    Posts
    44

    simulate_keypress()

    simulate_keypress() is under Allegro's keyboard.h

    It's defined as:
    Code:
    AL_FUNC(void, simulate_keypress, (int keycode));
    The simulated keypress would look something like this:
    Code:
    simulate_keypress(92);
    But, since it only simulates the keypress, I'm not sure if it reads the simulation as an actual event.

    But, you could probably do it the other way, if you wanted

    [edit]
    I'm still new to allegro, so I'm not very much of a help when it comes to the actual logistics of the API
    [/edit]
    Last edited by dead_cell; 12-31-2002 at 11:19 AM.
    Linux is great - It does infinite loops in five seconds!

    ~Linus Torvalds

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21