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
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
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.
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
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