ok i will do that now
This is my code
RECT rc;
HDC hdcMem, hdcOld;
BYTE* m_pDrawingSurfaceBits=NULL;
BITMAPINFOHEADER bmpInfoHeader = {0};;
HBITMAP hbmDIBSection = NULL;
HWND hParent,hChild=NULL;
char* szAppName = "view.exe";
BOOL bRet = IsProcessRunning(szAppName);
if (!bRet)
{
::MessageBox(hWnd,"Application is not running",NULL,NULL);
}
hParent = FindWindow("WindowViewer", NULL);
if (!hParent)
{
::MessageBox(hWnd,"not able to find WindowViewer class",NULL,NULL);
}
if(hParent)
hChild = FindWindowEx(hParent,NULL,"ViewPU",NULL);
if (!hChild)
{
::MessageBox(hWnd,"not able to find ViewPU class",NULL,NULL);
}
::SendMessage(hChild, WM_SYSCOMMAND, SC_HOTKEY, (LPARAM) hChild);
::SendMessage(hChild, WM_SYSCOMMAND, SC_RESTORE, (LPARAM) hChild);
GetWindowRect(hChild, &rc);
hdcOld = ::GetDC(hParent);
if(hdcOld == NULL)
::MessageBox(hWnd,"hdcOld null",NULL,NULL);
hdcMem = CreateCompatibleDC(hdcOld);
if(hdcMem == NULL)
::MessageBox(hWnd,"hdcMem null",NULL,NULL);
long width = rc.right-rc.left;
long height = rc.bottom-rc.top;
if(hdcMem != NULL)
{
bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfoHeader.biBitCount = 24;
bmpInfoHeader.biPlanes = 1;
bmpInfoHeader.biCompression = BI_RGB;
bmpInfoHeader.biWidth =width;
bmpInfoHeader.biHeight = height;
bmpInfoHeader.biSizeImage = ((((bmpInfoHeader.biWidth * bmpInfoHeader.biBitCount) + 31) & ~31) >> 3) * bmpInfoHeader.biHeight;
hbmDIBSection = CreateDIBSection(hdcMem, (CONST BITMAPINFO*)&bmpInfoHeader, DIB_RGB_COLORS, (void**)&m_pDrawingSurfaceBits, NULL, 0);
}
HBITMAP hbmOld = (HBITMAP) SelectObject(hdcMem, hbmDIBSection);
bRet = BitBlt(hdcMem,0,0,width,height,hdcOld,0,0,SRCCOPY);
if (bRet ==0)
{
DWORD d=::GetLastError();
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL
);
::MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );}
BITMAPFILEHEADER bfh = {0};
bfh.bfType = 0X4D42;
bfh.bfOffBits = sizeof(BITMAPINFOHEADER)+sizeof(BITMAPFILEHEADER);
bfh.bfSize = bfh.bfOffBits+bmpInfoHeader.biSizeImage;
bRet = SetCurrentDirectory("c:\\testBitmap");
DWORD ret = GetLastError();
char filename[200];
char *dir= "c:\\testBitmap\\";
int j;
j = sprintf(filename,"%s",dir);
j+= sprintf(filename+j,"%s",temp);
j+= sprintf(filename+j,"%d",counter);
j+= sprintf(filename+j,"%s",".bmp");
HANDLE hFile = CreateFile(filename,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if (!hFile)
{
return ;
}
DWORD dwWritten = 0;
bRet = WriteFile(hFile,&bfh,sizeof(bfh),&dwWritten,NULL);
bRet = WriteFile(hFile,&bmpInfoHeader,sizeof(bmpInfoHeader),&dwWritten,NULL);
bRet = WriteFile(hFile,m_pDrawingSurfaceBits,bmpInfoHeader.biSizeImage,&dwWritten,NULL);
bRet = CloseHandle(hFile);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
|