屏幕复制-(这个窗口是最小化的)
需要截屏的程序是别人的,用于监测数据,一定条件下会显示不同的图片和文字.
我定时(每分钟两次)需要截到这个窗口的屏幕,识别图像,如果发现显示了红灯,就把文字发给另一部机(我工作用的电脑).全部都做好了.
现在的问题是,截屏的这个函数,我必须把这个窗口调到最前面,可是我这部机并不专门跑这个程序,如果按这个函数,每30秒把这个窗口放到前面来,会干扰一些其它的操作.
有没有办法在这个窗口最小化时,也复制它的样子出来.
谢谢!
------------------------------------------------------
HWND hWndPrev= ::FindWindow(NULL,"系统数据监测");
if (hWndPrev){
//把它调到最前
::ShowWindow(hWndPrev,SW_SHOW);
::SetForegroundWindow(hWndPrev);
Sleep(1000);
if (IsWindow(hWndPrev)){
RECT lc;
::GetWindowRect(hWndPrev, &lc);
if (lc.top>=0 || lc.bottom>=0 && lc.left>=0 || lc.right>=0){
char * lc_body;
CDC *pDC;//屏幕DC
pDC = CDC::FromHandle(::GetDC(hWndPrev));//获取当前整个屏幕DC
int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);//获得颜色模式
tagBITMAPINFO ls_info;
tagBITMAPFILEHEADER ls_header;
HDC lul_whdc = ::GetDC(::GetDesktopWindow());
if (lul_whdc==NULL){
return;
}
HDC hbuffer = ::CreateCompatibleDC(lul_whdc);
if (hbuffer == NULL){
::ReleaseDC(0,lul_whdc);
return;
}
HBITMAP hbmp = ::CreateCompatibleBitmap(lul_whdc, lc.right - lc.left , lc.bottom - lc.top ) ;
if (hbmp == NULL){
::ReleaseDC(0,lul_whdc);
::DeleteDC(hbuffer);
return;
}
if (::SelectObject(hbuffer,hbmp) == NULL){
::ReleaseDC(0,lul_whdc);
::DeleteDC(hbuffer);
::DeleteObject(hbmp);
return;
}
if (::BitBlt(hbuffer,0, 0, lc.right, lc.bottom, lul_whdc,lc.left,lc.top , SRCCOPY) == NULL){
::ReleaseDC(0,lul_whdc);
::DeleteDC(hbuffer);
::DeleteObject(hbmp);
return;
}
::ReleaseDC(0,lul_whdc);
ls_info.bmiHeader.biSize = 40;
ls_info.bmiHeader.biWidth = lc.right - lc.left;
ls_info.bmiHeader.biHeight = lc.bottom - lc.top;
ls_info.bmiHeader.biPlanes = 1;
ls_info.bmiHeader.biBitCount = BitPerPixel;
ls_info.bmiHeader.biCompression = 0;
ls_info.bmiHeader.biSizeImage = 0;
ls_info.bmiHeader.biXPelsPerMeter = 0;
ls_info.bmiHeader.biYPelsPerMeter = 0;
ls_info.bmiHeader.biClrUsed = 0;
ls_info.bmiHeader.biClrImportant = 0;
ls_header.bfSize = 14;
ls_header.bfOffBits = 14 + 40;
ls_header.bfType = 19778;
ls_header.bfReserved1 = 0;
ls_header.bfReserved2 = 0;
long ll_len = sizeof(ls_info.bmiHeader)+
sizeof(ls_header)+
(lc.right - lc.left + 1) * (lc.bottom - lc.top + 1) * (BitPerPixel) / 8 ;
lc_body = new char[ll_len];
::RtlMoveMemory(lc_body,&ls_header,sizeof(ls_header));
::RtlMoveMemory(lc_body + sizeof(ls_header),&ls_info.bmiHeader,sizeof(ls_info.bmiHeader));
::GetDIBits(hbuffer,hbmp,0,lc.bottom - lc.top,lc_body + sizeof(ls_header) + sizeof(ls_info.bmiHeader),&ls_info, 0);
::DeleteDC(hbuffer);
::DeleteObject(hbmp);
::DeleteDC(hbuffer);
//输出
CString ls_file_name;
ls_file_name = "f:\\desktop\\系统数据监测\\B"+shuf::DatetimeToString(shuf::Now(),"YYYYMMDDHHMMSS")+".bmp";
shuf::write_file(ls_file_name,lc_body,ll_len);
delete []lc_body;
return;
}
}
}