lbw0514 (11-13-2013)
Well, as you can see from the title i am having major problems with GetPixel(). It's the worst method to use if you want to scan the whole screen. I have made a pixel aimbot lately but it just won't scan the screen fast enough. I researched the topic and found out about multi threading. So i multithreaded, oh i multi threaded the crap out of my program, here is the full source code of the program so that you don't think i am just bluffing. [Nevermind it won't let me post it cuz too many words, i will upload it to MPGH].
I am pretty sure i went overboard with multi threading, but even with that it's not scanning fast enough. I even made it skip every other pixel and still not fast enough. If anyone has a better way please tell me. Thanks.
lbw0514 (11-13-2013)
I don't know what code you have there but..
Try multi-threading just small amounts of the screen in each thread.
Don't scan every pixel, jump a few... And if you find a certain pixel, dont RE-scan the whole screen again, but just the area around that pixel.
Light travels faster than sound. That's why most people seem bright until you hear them speak.
DirectX is always faster. Per-pixel scanning is impossibly slow. Your much better off temporarily storing the entire image in memory, and reading it there rather then making thousands of API calls per frame, which impossibly slow.
API calls are notoriously slow in general, but screen GUI function are even slower, since Hardware components such as the screen buffer, must go through the kernel level due to the HAL (Hardware Abstraction Layer). DirectX is the only way I know to directly access the screen buffer.
So best solution would be either to access the entire screen in one call rather then calling a thousand times for each pixel, and using DirectX to check the screen buffer rather then the Windows GUI.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
258456 (11-09-2010)
i don't really have experience in directx so i don't know what function to use. If you could just tell me the function i guess that would be enough and i can just figure it out from there. Thanks for your reply
Save a frame as a bmp and look through the pixels using a loop.
258456 (11-09-2010)
258456 (11-09-2010),Hell_Demon (11-08-2010),Jason (11-07-2010),why06 (11-08-2010)
derp
/tooshort
Languages: C, C++, x86 ASM, PHP, Lua
It depends on the game really, for exactly what you want to do. I don't want to tell you a DirectX method for a OpenGL game, or Use OpenGL when its a Browser game using Windows GUI, etc.
EDIT: Okay I did a bit of googling and found exactly what your looking for:
THis is where the magic happens GetDIBits
https://msdn.microsof*****m/en-us/libr...=VS.85%29.aspx This Code Should save the current screen image or just the selected window, regardless of rather your using DirectX or OpenGL, though I would reccommend doing you own searching and using DirectX if your able to, because it should be faster.Code:int CaptureAnImage(HWND hWnd) { HDC hdcScreen; HDC hdcWindow; HDC hdcMemDC = NULL; HBITMAP hbmScreen = NULL; BITMAP bmpScreen; // Retrieve the handle to a display device context for the client // area of the window. hdcScreen = GetDC(NULL); hdcWindow = GetDC(hWnd); // Create a compatible DC which is used in a BitBlt from the window DC hdcMemDC = CreateCompatibleDC(hdcWindow); if(!hdcMemDC) { MessageBox(hWnd, L"CreateCompatibleDC has failed",L"Failed", MB_OK); goto done; } // Get the client area for size calculation RECT rcClient; GetClientRect(hWnd, &rcClient); //This is the best stretch mode SetStretchBltMode(hdcWindow,HALFTONE); //The source DC is the entire screen and the destination DC is the current window (HWND) if(!StretchBlt(hdcWindow, 0,0, rcClient.right, rcClient.bottom, hdcScreen, 0,0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), SRCCOPY)) { MessageBox(hWnd, L"StretchBlt has failed",L"Failed", MB_OK); goto done; } // Create a compatible bitmap from the Window DC hbmScreen = CreateCompatibleBitmap(hdcWindow, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top); if(!hbmScreen) { MessageBox(hWnd, L"CreateCompatibleBitmap Failed",L"Failed", MB_OK); goto done; } // Select the compatible bitmap into the compatible memory DC. SelectObject(hdcMemDC,hbmScreen); // Bit block transfer into our compatible memory DC. if(!BitBlt(hdcMemDC, 0,0, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top, hdcWindow, 0,0, SRCCOPY)) { MessageBox(hWnd, L"BitBlt has failed", L"Failed", MB_OK); goto done; } // Get the BITMAP from the HBITMAP GetObject(hbmScreen,sizeof(BITMAP),&bmpScreen); BITMAPFILEHEADER bmfHeader; BITMAPINFOHEADER bi; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bmpScreen.bmWidth; bi.biHeight = bmpScreen.bmHeight; bi.biPlanes = 1; bi.biBitCount = 32; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight; // Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that // call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc // have greater overhead than HeapAlloc. HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize); char *lpbitmap = (char *)GlobalLock(hDIB); // Gets the "bits" from the bitmap and copies them into a buffer // which is pointed to by lpbitmap. GetDIBits(hdcWindow, hbmScreen, 0, (UINT)bmpScreen.bmHeight, lpbitmap, (BITMAPINFO *)&bi, DIB_RGB_COLORS); // A file is created, this is where we will save the screen capture. HANDLE hFile = CreateFile(L"captureqwsx.bmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); // Add the size of the headers to the size of the bitmap to get the total file size DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); //Offset to where the actual bitmap bits start. bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER); //Size of the file bmfHeader.bfSize = dwSizeofDIB; //bfType must always be BM for Bitmaps bmfHeader.bfType = 0x4D42; //BM DWORD dwBytesWritten = 0; WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &dwBytesWritten, NULL); //Unlock and Free the DIB from the heap GlobalUnlock(hDIB); GlobalFree(hDIB); //Close the handle for the file that was created CloseHandle(hFile); //Clean up done: DeleteObject(hbmScreen); DeleteObject(hdcMemDC); ReleaseDC(NULL,hdcScreen); ReleaseDC(hWnd,hdcWindow); return 0; }
Last edited by why06; 11-08-2010 at 05:41 AM.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
258456 (11-09-2010)