HBITMAP FAR CopyWindowToBitmap(HWND hWnd, WORD fPrintArea) { HBITMAP hBitmap = NULL; // handle to device-dependent bitmap /* check for a valid window handle */ if (!hWnd) return NULL; switch (fPrintArea) { case PW_WINDOW: // copy entire window { RECT rectWnd; /* get the window rectangle */ GetWindowRect(hWnd, &rectWnd); /* get the bitmap of that window by calling * CopyScreenToBitmap and passing it the window rect */ hBitmap = CopyScreenToBitmap(&rectWnd); } break; case PW_CLIENT: // copy client area { RECT rectClient; POINT pt1, pt2; /* get client dimensions */ GetClientRect(hWnd, &rectClient); /* convert client coords to screen coords */ pt1.x = rectClient.left; pt1.y = rectClient.top; pt2.x = rectClient.right; pt2.y = rectClient.bottom; ClientToScreen(hWnd, &pt1); ClientToScreen(hWnd, &pt2); rectClient.left = pt1.x; rectClient.top = pt1.y; rectClient.right = pt2.x; rectClient.bottom = pt2.y; /* get the bitmap of the client area by calling * CopyScreenToBitmap and passing it the client rect */ hBitmap = CopyScreenToBitmap(&rectClient); } break; default: // invalid print area return NULL; } /* return handle to the bitmap */ return hBitmap; }
CCatchScreenDlg::CCatchScreenDlg(CWnd* pParent /*=NULL*/) : CDialog(CCatchScreenDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCatchScreenDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 //******************************************************************************* //初始化像皮筋类 m_rectTracker.m_nStyle=CRectTracker::resizeInside|CRectTracker::solidLine; m_rectTracker.m_rect.SetRect(-1,-1,-1,-1); m_hCursor=AfxGetApp()->LoadCursor(IDC_CURSOR1); m_bDraw=FALSE; m_bFirstDraw=FALSE; m_bQuit=FALSE; m_bShowMsg=FALSE; m_startPt=0; //获取屏幕分辩率 m_xScreen = GetSystemMetrics(SM_CXSCREEN); m_yScreen = GetSystemMetrics(SM_CYSCREEN); //截取屏幕到位图中 CRect rect(0, 0,m_xScreen,m_yScreen); m_pBitmap=CBitmap::FromHandle(CopyScreenToBitmap(&rect)); //一定要初始化m_rgn, m_rgn.CreateRectRgn(0,0,50,50); //******************************************************************************* m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }
HDIB FAR CopyScreenToDIB(LPRECT lpRect) { HBITMAP hBitmap; // handle to device-dependent bitmap HPALETTE hPalette; // handle to palette HDIB hDIB = NULL; // handle to DIB /* get the device-dependent bitmap in lpRect by calling * CopyScreenToBitmap and passing it the rectangle to grab */ hBitmap = CopyScreenToBitmap(lpRect); /* check for a valid bitmap handle */ if (!hBitmap) return NULL; /* get the current palette */ hPalette = GetSystemPalette(); /* convert the bitmap to a DIB */ hDIB = BitmapToDIB(hBitmap, hPalette); /* clean up */ DeleteObject(hPalette); DeleteObject(hBitmap); /* return handle to the packed-DIB */ return hDIB; }
void CSplashScreen::OnPaint() { CPaintDC dc(this); // device context for painting CDC dcMem; GetWindowRect(&rect);//获得要抓图的区域 m_hbm = CopyScreenToBitmap(rect);//抓图 GetObject(m_hbm, sizeof(m_bitmap),&m_bitmap);//获得抓到的图的尺寸 if (dcMem.CreateCompatibleDC(&dc)) { SelectObject(dcMem, m_hbm); BitBlt(dc,0,0,m_bitmap.bmWidth, m_bitmap.bmHeight, dcMem,0 ,0, SRCCOPY); m_image->Draw(dc.m_hDC,m_bitmap.bmWidth/2 - 380/2,m_bitmap.bmHeight/2 - 350/2,380,350); CRect rc(0, m_bitmap.bmHeight/2 + 70, m_bitmap.bmWidth ,m_bitmap.bmHeight); LOGFONT lf = {0}; lf.lfHeight = 26; lf.lfWeight = FW_BOLD; lf.lfQuality = 0 ? NONANTIALIASED_QUALITY : ANTIALIASED_QUALITY; _tcscpy(lf.lfFaceName, _T("Arial")); CFont font; font.CreateFontIndirect(&lf); CFont* pOldFont = dc.SelectObject(&font); CString strAppVersion; strAppVersion.Format(_T("eMule %u.%u%c VeryCD"), CemuleApp::m_nVersionMjr, CemuleApp::m_nVersionMin, _T('a') + CemuleApp::m_nVersionUpd); rc.top += 30; rc.top += dc.DrawText(strAppVersion, &rc, DT_CENTER | DT_NOPREFIX); if (pOldFont) { dc.SelectObject(pOldFont); } font.DeleteObject(); rc.top += 8; lf.lfHeight = 14; lf.lfWeight = FW_NORMAL; lf.lfQuality = 0 ? NONANTIALIASED_QUALITY : ANTIALIASED_QUALITY; _tcscpy(lf.lfFaceName, _T("Arial")); font.CreateFontIndirect(&lf); pOldFont = dc.SelectObject(&font); dc.DrawText(_T("Copyright (C) 2002-2009 Merkur"), &rc, DT_CENTER | DT_NOPREFIX); if (pOldFont) { dc.SelectObject(pOldFont); } font.DeleteObject(); } }
//保存截图 void SaveScreen() { HBITMAP hbitmap=CopyScreenToBitmap(); TCHAR name[MAX_PATH]; SYSTEMTIME st; GetLocalTime(&st); // PengJiLin, 2010-6-7, GetCurrentDirectory()函数全部替代 //::GetCurrentDirectory(MAX_PATH,name); lstrcpy(name, CBcfFile::GetAppPath()); lstrcat(name,"\\截图"); ::CreateDirectory(name,NULL); wsprintf(name,TEXT("%s\\%d-%d-%d-%d-%d-%d.bmp"),name,st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond); SaveBitmapToFile(hbitmap,name); }
void CCatchScreenDlg::OnLButtonDblClk(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default int nHitTest; nHitTest=m_rectTracker.HitTest(point); //如果在是矩形内部双击 if(nHitTest==8) { //保存位图到粘贴板中,bSave 为TRUE, CopyScreenToBitmap(m_rectTracker.m_rect,TRUE); //PostQuitMessage(0); CDialog::OnLButtonDblClk(nFlags, point); OnOK(); return; } }
bool CGetScreenInfo::CopyScreenToData(LPRECT lpRect) { if(!m_bIsLock) { HBITMAP hBitmap; hBitmap = CopyScreenToBitmap(lpRect); if(hBitmap) { WORD dwBitCount = (WORD)GetBitCount(); _BitmapToData(hBitmap, dwBitCount); // DeleteObject(hBitmap); return true; } else return false; } return false; }
void CCatchScreenDlg::SnapWholeScreen() { //截取屏幕到位图中 CRect rect(0, 0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)); char szTempPath[MAX_PATH]={0} ; char filename[1024]={0} ; GetTempPath(sizeof(szTempPath), szTempPath) ; sprintf(filename, "%s/snapscreen.bmp" , szTempPath ) ; SaveBitmapToFile(CopyScreenToBitmap(rect,TRUE) , filename) ; if( atoi(__argv[1]) ) { char szCmd[1024]={0} ; sprintf(szCmd,"mspaint.exe %s" , filename) ; WinExec(szCmd,1) ; } PostQuitMessage(0); }
// This is where we insert the DIB bits into the video stream. // FillBuffer is called once for every sample in the stream. HRESULT CVCamPin::FillBuffer(IMediaSample *pSample) { BYTE *pData; long cbData; CheckPointer(pSample, E_POINTER); CAutoLock cAutoLockShared(&m_cSharedState); // Access the sample's data buffer pSample->GetPointer(&pData); cbData = pSample->GetSize(); // Check that we're still using video ASSERT(m_mt.formattype == FORMAT_VideoInfo); VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)m_mt.pbFormat; // Copy the DIB bits over into our filter's output buffer. // Since sample size may be larger than the image size, bound the copy size. int nSize = min(pVih->bmiHeader.biSizeImage, (DWORD) cbData); HDIB hDib = CopyScreenToBitmap(&m_rScreen, pData, (BITMAPINFO *)&(pVih->bmiHeader), m_hCursor); if (hDib) DeleteObject(hDib); // Set the timestamps that will govern playback frame rate. // If this file is getting written out as an AVI, // then you'll also need to configure the AVI Mux filter to // set the Average Time Per Frame for the AVI Header. // The current time is the sample's start. REFERENCE_TIME rtStart = m_iFrameNumber * m_rtFrameLength; REFERENCE_TIME rtStop = rtStart + m_rtFrameLength; pSample->SetTime(&rtStart, &rtStop); m_iFrameNumber++; // Set TRUE on every sample for uncompressed frames pSample->SetSyncPoint(TRUE); return S_OK; }
CCatchScreenDlg::CCatchScreenDlg(CWnd* pParent /*=NULL*/) : CDialog(CCatchScreenDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCatchScreenDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 //******************************************************************************* //初始化像皮筋类,新增的resizeMiddle 类型 m_rectTracker.m_nStyle=CMyTracker::resizeMiddle|CMyTracker::solidLine; m_rectTracker.m_rect.SetRect(-1,-2,-3,-4); //设置矩形颜色 m_rectTracker.SetRectColor(RGB(10,100,130)); //设置矩形调整时光标,默认的太小了,弄了个大点的 m_rectTracker.SetResizeCursor(IDC_CURSOR6,IDC_CURSOR5,IDC_CURSOR2,IDC_CURSOR3,IDC_CURSOR4); m_hCursor=AfxGetApp()->LoadCursor(IDC_CURSOR1); m_bDraw=FALSE; m_bFirstDraw=FALSE; m_bQuit=FALSE; m_bShowMsg=FALSE; m_startPt=0; //获取屏幕分辩率 m_xScreen = GetSystemMetrics(SM_CXSCREEN); m_yScreen = GetSystemMetrics(SM_CYSCREEN); //截取屏幕到位图中 CRect rect(0, 0,m_xScreen,m_yScreen); m_pBitmap=CBitmap::FromHandle(CopyScreenToBitmap(&rect)); //初始化刷新窗口区域 m_rgn m_rgn.CreateRectRgn(0,0,50,50); //******************************************************************************* m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }
void CCatchScreenDlg::OnLButtonDblClk(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default int nHitTest; nHitTest=m_rectTracker.HitTest(point); if(nHitTest==8) { char szTempPath[MAX_PATH]={0} ; char filename[1024]={0} ; GetTempPath(sizeof(szTempPath), szTempPath) ; sprintf(filename, "%s/snapscreen.bmp" , szTempPath ) ; SaveBitmapToFile(CopyScreenToBitmap(m_rectTracker.m_rect,TRUE) , filename) ; if( atoi(__argv[1]) ) { char szCmd[1024]={0} ; sprintf(szCmd,"mspaint.exe %s" , filename) ; WinExec(szCmd,1) ; } PostQuitMessage(0); } CDialog::OnLButtonDblClk(nFlags, point); }
void CCatchScreenDlg::CaptureIt() { m_bSleeping = false; //截取屏幕到位图中 CRect rect(0, 0, m_nCXScreen, m_nCYScreen); SetRedraw(FALSE); m_OrgBackgroundBitmap.Attach(CopyScreenToBitmap(&rect)); CClientDC dc(this); m_BackgroundBitmap.Attach(CreateTransparentColorBitmap(&dc, &m_OrgBackgroundBitmap, rect)); //把对化框设置成全屏顶层窗口 SetWindowPos(&wndTopMost, 0, 0, m_nCXScreen, m_nCYScreen, SWP_SHOWWINDOW); SetRedraw(); //移动操作提示窗口 m_wndTipEdit.GetWindowRect(&rect); m_wndTipEdit.MoveWindow(10, 10, rect.Width(), rect.Height()); m_bDrawTracker=FALSE; m_rectTracker.m_rect.SetRect(-1, -1, -1, -1); PaintWindow(); //显示操作提示窗口文字 DrawTip(dc); }
int _tmain(int argc, _TCHAR* argv[]) { /* CvCapture *capture=0; IplImage *frame=0; int right=GetSystemMetrics(SM_CXSCREEN); int left=0; int top=0; int bottom=GetSystemMetrics(SM_CYSCREEN); RECT rc={left,top,right,bottom}; frame=GetDIBitsFormScreen(&rc); cvNamedWindow("frame",CV_WINDOW_AUTOSIZE); cvShowImage("frame",frame); cvWaitKey(0); cvDestroyWindow("frame"); cvReleaseImage(&frame); //_CrtDumpMemoryLeaks(); return 0;*/ IplImage* screenRGB=0; IplImage* screen_resize=0; time_t begin,end; while(1) { begin=clock(); CopyScreenToBitmap(); //得到的图片为RGBA格式,即4通道。 if(!screen_resize) screen_resize=cvCreateImage(cvSize(1600,900),image_depth,image_nchannels); cvResize(screemImage,screen_resize,CV_INTER_LINEAR); if(!screenRGB) screenRGB=cvCreateImage(cvSize(1600,900),IPL_DEPTH_8U,3); cvCvtColor(screen_resize,screenRGB,CV_RGBA2RGB); //cvShowImage("s_laplace",screenRGB); CvPoint ptDest; CvPoint ptSrc; ptDest.x=0;ptDest.y=0; ptSrc.x=0;ptSrc.y=0; TemlateBit(screenRGB,"temimage.jpg",&ptDest,&ptSrc); end=clock(); printf("ptDest.x=%d ptDest.y=%d \n ptSrc.x=%d ptSrc.y=%d \n",ptDest.x,ptDest.y,ptSrc.x,ptSrc.y); printf("runtime:%1.3f \n",double(end-begin)/CLOCKS_PER_SEC); HWND h=GetDesktopWindow(); HDC hdc=GetWindowDC(h); //Rectangle(hdc,ptDest.x-1,ptDest.y-1,ptSrc.x+1,ptSrc.y+1); MoveToEx(hdc,ptDest.x-1,ptDest.y-1,NULL); LineTo(hdc,ptSrc.x+1,ptDest.y-1); LineTo(hdc,ptSrc.x+1,ptSrc.y+1); LineTo(hdc,ptDest.x-1,ptSrc.y+1); LineTo(hdc,ptDest.x-1,ptDest.y-1); ReleaseDC(h,hdc); cvWaitKey(10); } cvDestroyAllWindows(); return 0; }
// This is where we insert the DIB bits into the video stream. // FillBuffer is called once for every sample in the stream. HRESULT CPushPinDesktop::FillBuffer(IMediaSample *pSample) { __int64 startThisRound = StartCounter(); BYTE *pData; long cbData; CheckPointer(pSample, E_POINTER); // Access the sample's data buffer pSample->GetPointer(&pData); cbData = pSample->GetSize(); // Make sure that we're still using video format ASSERT(m_mt.formattype == FORMAT_VideoInfo); VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)m_mt.pbFormat; // Copy the DIB bits over into our filter's output buffer. // Since sample size may be larger than the image size, bound the copy size. int nSize = min(pVih->bmiHeader.biSizeImage, (DWORD) cbData); // cbData is the size of pData HDIB hDib = CopyScreenToBitmap(hScrDc, &m_rScreen, pData, (BITMAPINFO *) &(pVih->bmiHeader)); if (hDib) DeleteObject(hDib); // for some reason the timings are messed up initially, as there's no start time. // race condition? // so don't count them unless they seem valid... FILTER_STATE myState; CSourceStream::m_pFilter->GetState(INFINITE, &myState); bool fullyStarted = myState == State_Running; CRefTime now; CSourceStream::m_pFilter->StreamTime(now); // calculate how long it took before we add in our own arbitrary delay to enforce fps... long double millisThisRoundTook = GetCounterSinceStartMillis(startThisRound); // wait until we "should" send this frame out...TODO...more precise et al... if(m_iFrameNumber > 0 && (now > 0)) { // now > 0 to accomodate for if there is no clock at all... while(now < previousFrameEndTime) { // guarantees monotonicity too :P Sleep(1); CSourceStream::m_pFilter->StreamTime(now); } } REFERENCE_TIME endFrame = now + m_rtFrameLength; pSample->SetTime((REFERENCE_TIME *) &now, &endFrame); if(fullyStarted) m_iFrameNumber++; // Set TRUE on every sample for uncompressed frames pSample->SetSyncPoint(TRUE); // only set discontinuous for the first...I think... pSample->SetDiscontinuity(m_iFrameNumber == 1); double fpsSinceBeginningOfTime = ((double) m_iFrameNumber)/(GetTickCount() - globalStart)*1000; LocalOutput("end total frames %d %.020Lfms, total since beginning of time %f fps (theoretical max fps %f)", m_iFrameNumber, millisThisRoundTook, fpsSinceBeginningOfTime, 1.0*1000/millisThisRoundTook); previousFrameEndTime = endFrame; return S_OK; }
int _tmain(int argc, _TCHAR* argv[]) { #if CGI char_t buf[256]; int nread = 0; //初始化,必须调用 if(init(argc, argv)<0) { wprintf(L"[-] cgi file open failed\n"); exit(-1); } write_data(L"<html>\n"); write_data(L"<head><title>CGI Output</title></head>\n"); write_data(L"<body>\n"); write_data(L"<H1>CGI Test Program</H1>\n"); write_data(L"<P>This program displays the CGI Enviroment</P>\n"); /* * Print the CGI environment variables */ write_data(L"<H2>Environment Variables<A NAME=\"env\"></A></H2>\n"); write_data(L"<P>REQUEST METHOD = %s</P>\n", gogetenv(L"REQUEST_METHOD",buf)); write_data(L"<P>QUERY STRING = %s</P>\n", gogetenv(L"QUERY_STRING",buf)); write_data(L"<P>PATH TRANSLATED = %s</P>\n", gogetenv(L"PATH_TRANSLATED",buf)); write_data(L"<P>GATEWAY INTERFACE = %s</P>\n", gogetenv(L"GATEWAY_INTERFACE",buf)); write_data(L"<P>SCRIPT NAME = %s</P>\n", gogetenv(L"SCRIPT_NAME",buf)); write_data(L"<P>PATH INFO = %s</P>\n", gogetenv(L"PATH_INFO",buf)); write_data(L"<P>HTTP HOST = %s</P>\n", gogetenv(L"HTTP_HOST",buf)); write_data(L"<P>HTTP ACCEPT = %s</P>\n", gogetenv(L"HTTP_ACCEPT",buf)); write_data(L"<P>HTTP CONNECTION = %s</P>\n", gogetenv(L"HTTP_CONNECTION",buf)); write_data(L"<P>REMOTE USER = %s</P>\n", gogetenv(L"REMOTE_USER",buf)); write_data(L"<P>REMOTE HOST = %s</P>\n", gogetenv(L"REMOTE_HOST",buf)); write_data(L"<P>REMOTE ADDR = %s</P>\n", gogetenv(L"REMOTE_ADDR",buf)); write_data(L"<P>SERVER NAME = %s</P>\n", gogetenv(L"SERVER_NAME",buf)); write_data(L"<P>SERVER PORT = %s</P>\n", gogetenv(L"SERVER_PORT",buf)); write_data(L"<P>SERVER HOST = %s</P>\n", gogetenv(L"SERVER_HOST",buf)); write_data(L"<P>SERVER PROTOCOL = %s</P>\n", gogetenv(L"SERVER_PROTOCOL",buf)); write_data(L"<P>SERVER ADDR = %s</P>\n", gogetenv(L"SERVER_ADDR",buf)); write_data(L"<P>SERVER URL = %s</P>\n", gogetenv(L"SERVER_URL",buf)); write_data(L"<P>SERVER SOFTWARE = %s</P>\n", gogetenv(L"SERVER_SOFTWARE",buf)); write_data(L"<P>CGI_Data = %s</P>\n", getCgiData(buf,sizeof(buf),&nread)); write_data(L"<P>CGI_Size = %d</P>\n", nread); write_data(L"<P>out = %s</P>\n", argv[argc-1]); write_data(L"<P>in = %s</P>\n", argv[argc-2]); write_data(L"<P>env = %s</P>\n", argv[argc-3]); #endif #if 0 int nWidth,nHeight; HBITMAP MyhBitmap; MyhBitmap = CopyScreenToBitmap(&nWidth, &nHeight ); wprintf(L"width=%d\t,height=%d\n",nWidth, nHeight); //Save16BitmapToFile( MyhBitmap, L"\\NandFlash\\go.bmp"); Save16BitmapToFile( MyhBitmap, L"go.bmp"); wprintf(L"xxxxxxxxxxx"); #endif #if CGI //销毁资源 destroy(); #endif return 0; }