Capture screen - what's wrong? 
Author Message
 Capture screen - what's wrong?

Hi,

I'm trying to develop a small application that must capture a specific
part of the screen every X seconds and *save it to a bmp file*

Since I had no idea about how to capture a screen, I read the help about the
topic and found a rather old sample which I tested. It didn't worked.
Therefore, I adapted this code to use MFC:

--- code begins here ----

 CDC dcScreen, dcCompatible;
 CBitmap bmScreen;

 if (!dcScreen.CreateDC("DISPLAY",NULL,NULL,NULL))
 {
  MessageBox("Cannot capture the requested area");
  return;
 }

 if (!dcCompatible.CreateCompatibleDC(&dcScreen))
 {
  MessageBox("Cannot capture the requested area");
  return;
 }

 if
(!bmScreen.CreateCompatibleBitmap(&dcScreen,(m_x1-m_x0+1),(m_y1-m_y0+1)))

 {
  MessageBox("Cannot capture the requested area");
  return;
 }

 CSize bmDim;

 bmDim = bmScreen.GetBitmapDimension();

 CString tmp;

 tmp.Format("%d %d",bmDim.cx, bmDim.cy);

 MessageBox(tmp); // Reports 0,0

 if (!dcCompatible.SelectObject(&bmScreen))
 {
  MessageBox("Cannot capture the requested area");
  return;
 }

 AfxGetApp()->m_pMainWnd->ShowWindow(SW_HIDE);

 if (!dcCompatible.BitBlt(              0, 0   ,
(m_x1-m_x0+1),(m_y1-m_y0+1),
                       &dcScreen, m_x0, m_y0,
                 SRCCOPY))
 {
  AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
  MessageBox("Cannot capture the requested area");
  return;
 }

 AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);

 CFile f;
 if( !f.Open("d:\\tmp\\capture.bmp", CFile::modeCreate |
CFile::modeWrite ) )
 {
  MessageBox("Cannot create the capture file");
  return;
 }

 CArchive ar( &f, CArchive::store);

 bmScreen.Serialize(ar);

        ar.Close();

--- code ends here -------

When I execute the previous code, I get no warnings and a file named
"capture.bmp" is created in the requested directory. However, the bmp is
empty (0 bytes). As you can see in the code above, I have reported via
MessageBox the dimensions of the CBitmap object I'm using to capture the
screen. These dimensions are 0,0 (that is, no dimension).

Note that m_x0, m_x1, m_y0 and m_y1 are members of my class and keep the
limits of the screen area I intend to capture. I have checked their values
and are OK.

Can you tell me what's wrong?

Please, send your answers not only to the group but also to


since my news server works intermitently.

Thanks for your help!!!

Jose.



Tue, 04 Dec 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. how to capture the game's screen??

2. capturing a 'c' system() call's screen output into the calling processes screen buffer

3. capture 'enter key'

4. Best 'Keyboard Stroke' capture Function

5. DBWin32 V2.2 Captures OutputDebugString on '95/'98/NT

6. Capturing CTreeCtrl check 'events'.

7. DBWin32 V2.0 Captures OutputDebugString on '95/'98/NT

8. DBWin32 V2.0 Captures OutputDebugString on '95/'98/NT

9. How to capture the message of toolbar's button's pushdown event

10. Capturing 'X'

11. DBWin32 captures OutputDebugString on Win '95/'98/NT.

12. DBWin32 V2.0 Captures OutputDebugString on '95/'98/NT

 

 
Powered by phpBB® Forum Software