Thread: Freeze the screen

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    43

    Freeze the screen

    I am using Getpixel() to capture pixels from the screen, but I need to lock the screen to stop it from changing before I have had time to scan all the pixels. How do I freeze the screen?

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Look for a copy bitmap function in the manual (say) and make a copy of the whole thing in one single call.
    That should keep changes to a minimum.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Look at Device contexts. They contain a bitmap, font, pen ect.

    Try..
    This will not stop the screen changing while your app runs.

    HDC hScreen = GetDC(NULL); // capture current screen

    //extract or copy the bitmap contained in hScreen

    //return hScreen to default items
    ReleaseDC(hScreen); //and free when finished

    I suggest you create a CompatibleBitmap() (in its own CompatibleDC() ) to copy the screen DC ( BitBlt() ).

    Then you can use GetDIBits() ect rather than the slow GetPixel() (all at once / individually ).
    "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

  4. #4
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    You should try using the search function. I answered a very similar question to this not to long ago. Anyway here is some code that locks the screen, then copies the entire contents to memory, finally releases the screen:

    Code:
    HDC hdcScr, hdcMem;
    HWND hwnd;
    HBITMAP hBitmap;
    
        
    If(LockWindowUpdate(hwnd = GetDesktopWindow())) {//locking the screen
    
                   hdcScr = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_LOCKWINDOWUPDATE);
                   hdcMem = CreateCompatibleDC(hdcScr);
                   hBitmap = CreateCompatibleBitmap(hdcScr, 60, 60);
                   SelectObject(hdcMem, hBitmap);
    
                   BitBlt(hdcMem, 0, 0, 60, 60, hdcScr, 0, 0, SRCCOPY);
    
                   //whatever else you want to do
    }
    DeleteDC(hdcMem);
    ReleaseDC(hwnd, hdcScr);
    DeleteObject(hBitmap);
    LockWindowUpdate(NULL); //unlock the screen
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  4. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM