I have created a MFC application with button click event which captures the screen shots of the window and save it in a file. I want to make a thread for looping in which the capturing of screen continues to go on. Please help me... Am using the following code which takes 10 screen shots in the interval of 10 seconds. How to make it as a service to run continuously after installing.. help me.. with this code...
void CscreensaveDlg::OnBnClickedOk()
{
HDC hScrDC = ::GetDC(NULL);
HDC hMemDC = NULL;
BYTE *lpBitmapBits = NULL;
int nWidth = GetSystemMetrics(SM_CXSCREEN);
int nHeight = GetSystemMetrics(SM_CYSCREEN);
hMemDC = ::CreateCompatibleDC(hScrDC);
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = nWidth;
bi.bmiHeader.biHeight = nHeight;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
HBITMAP bitmap = ::CreateDIBSection(hMemDC, &bi, DIB_RGB_COLORS, (LPVOID*)&lpBitmapBits, NULL, 0);
HGDIOBJ oldbmp = ::SelectObject(hMemDC, bitmap);
::BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY);
BITMAPFILEHEADER bh;
ZeroMemory(&bh, sizeof(BITMAPFILEHEADER));
bh.bfType = 0x4d42;
bh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bh.bfSize = bh.bfOffBits + ((nWidth*nHeight)*3);
CFile file;
char buffer[1000];
DWORD threadId;
int value = 10;
for(int c=0;c<10;c++)
{
sprintf_s(buffer,"D:\image%u.jpg",c);
CString sName(buffer);
LPCTSTR lpszName = sName;
if(file.Open(lpszName, CFile::modeCreate | CFile::modeWrite))
{
file.Write(&bh, sizeof(BITMAPFILEHEADER));
file.Write(&(bi.bmiHeader), sizeof(BITMAPINFOHEADER));
file.Write(lpBitmapBits, 3 * nWidth * nHeight);
file.Close();
Sleep(10000);
}
}
::SelectObject(hMemDC, oldbmp);
::DeleteObject(bitmap);
::DeleteObject(hMemDC);
::ReleaseDC(NULL, hScrDC);
}