941,512 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 389
  • C++ RSS
Jan 23rd, 2010
0

ScreenShot-10 times in one second and showing it in Image component

Expand Post »
Hey, I have a big problem. I want to do a program which will get a part of the screen of a program. After that It will show this small rectangle in Image component in BCB. But the problem is, it has to refresh it at least 10 times in one second. For now I succeeded in doing a code that gets a screen but it is too slow. For now it is refreshing in 2,5-3 seconds:/ Maybe better solution would be DirectX or something else?
C++ Syntax (Toggle Plain Text)
  1. Image1->Picture->LoadFromFile("black.bmp");
  2. Image1->Refresh();
  3. HWND Wnd=FindWindow(NULL,"Window");
  4. if(Wnd==0) {MessageBox(0,"Didnt find the window",0,0);}
  5. HDC ekran=GetDC(Wnd);
  6. for(int i=0; i<116; i++)
  7. {
  8. for(int j=0; j<114; j++)
  9. {
  10. screen[i][j]=GetPixel(ekran, 674+i,11+j); //colorref
  11. Image1->Picture->Bitmap->Canvas->Pixels[i][j]=screen[i][j];
  12. }
  13. }
Last edited by arva; Jan 23rd, 2010 at 5:25 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
arva is offline Offline
3 posts
since Jan 2010
Jan 23rd, 2010
0
Re: ScreenShot-10 times in one second and showing it in Image component
http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
How about something more efficient at copying rectangles, say bitblt ?
Team Colleague
Reputation Points: 5862
Solved Threads: 947
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jan 23rd, 2010
0
Re: ScreenShot-10 times in one second and showing it in Image component
Now I have something like this. It is within a loop. It should show the window but it shows only black screen. When I'm using analogical code but with loading a bitmap from file everthing works fine.
1.
C++ Syntax (Toggle Plain Text)
  1. HDC WinDC;
  2. HDC CopyDC;
  3. HBITMAP hBitmap;
  4. RECT rt;
  5. HWND Wnd=FindWindow(NULL,"WINDOW");
  6. if(Wnd==0) {MessageBox(0,"didnt found the window!",0,0);}
  7. GetWindowRect (Wnd, &rt);
  8. WinDC = GetDC (Wnd);
  9. CopyDC = CreateCompatibleDC (global_hdc);
  10. std::cout<<rt.right - rt.left<<std::endl;
  11. std::cout<<rt.bottom - rt.top<<std::endl;
  12. hBitmap = CreateCompatibleBitmap (WinDC,
  13. 800, //width
  14. 600);//height
  15. SelectObject (CopyDC, hBitmap);
  16. BitBlt (global_hdc, //destination
  17. 0,0,
  18. 800, //width
  19. 600, //height
  20. CopyDC, //source
  21. 0, 0,
  22. SRCCOPY);
  23.  
  24. DeleteObject((HBITMAP)hBitmap);
  25. DeleteDC(CopyDC);

2.Analogical code with loading from file:
C++ Syntax (Toggle Plain Text)
  1. HBITMAP image;
  2. BITMAP bm;
  3. HDC hdcMem;
  4. //load the bitmap image
  5. image = (HBITMAP)LoadImage(0,"asteroid.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
  6. //read the bitmap's properties
  7. GetObject(image, sizeof(BITMAP), &bm);
  8. //create a device context for the bitmap
  9. hdcMem = CreateCompatibleDC(global_hdc);
  10. SelectObject(hdcMem, image);
  11. //draw the bitmap to the window (bit block transfer)
  12. BitBlt(
  13. global_hdc, //destination device context
  14. 0, 0, //x,y location on destination
  15. bm.bmWidth, bm.bmHeight, //width,height of source bitmap
  16. hdcMem, //source bitmap device context
  17. 0, 0, //start x,y on source bitmap
  18. SRCCOPY); //blit method
  19. //delete the device context and bitmap
  20. DeleteDC(hdcMem);
  21. DeleteObject((HBITMAP)image);
Last edited by arva; Jan 23rd, 2010 at 6:35 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
arva is offline Offline
3 posts
since Jan 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ tests
Next Thread in C++ Forum Timeline: Nasty form of function hooking





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC