各位大虾如何获得我抓取的屏幕里显示的文本,谢谢

解决方案 »

  1.   

    什么意思呀?讲得不清不楚。是不是要抓屏保存为成BMP呀?
    void CCaptureView::OnCaptureScreen() 
    {
    // TODO: Add your command handler code here
    CDC dc;
    dc.CreateDC("DISPLAY",NULL,NULL,NULL);
    int SrcWidth=GetSystemMetrics(SM_CXSCREEN);
    int SrcHeight=GetSystemMetrics(SM_CYSCREEN);
    // int Width=384,Height=288;
    int Width=SrcWidth,Height=SrcHeight;
    /* CDC memdc;
    memdc.CreateCompatibleDC(&dc);
    memdc.StretchBlt(0,0,Width,Height,&dc,0,0,SrcWidth,SrcHeight,SRCCOPY);
    */
    CBitmap bm;
    bm.CreateCompatibleBitmap(&dc,Width,Height);
    CDC tdc;
    tdc.CreateCompatibleDC(&dc);
    CBitmap*pOld=tdc.SelectObject(&bm);
    tdc.SetStretchBltMode(STRETCH_HALFTONE);
    tdc.StretchBlt(0,0,Width,Height,&dc,0,0,SrcWidth,SrcHeight,SRCCOPY);
    // tdc.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY);
    tdc.SelectObject(pOld);
    BITMAP btm;
    bm.GetBitmap(&btm);
    DWORD size=btm.bmWidthBytes*btm.bmHeight;
    LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);
    /////////////////////////////////////////////
    BITMAPINFOHEADER bih;
    bih.biBitCount=btm.bmBitsPixel;
    bih.biClrImportant=0;
    bih.biClrUsed=0;
    bih.biCompression=0;
    bih.biHeight=btm.bmHeight;
    bih.biWidth=btm.bmWidth;
    bih.biPlanes=1;
    bih.biSize=sizeof(BITMAPINFOHEADER);
    bih.biSizeImage=size;
    bih.biXPelsPerMeter=0;
    bih.biYPelsPerMeter=0;
    ///////////////////////////////////
    GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
    // bm.GetBitmapBits(size,lpData); //此函数在处理5-5-5模式的16位色下会出现颜色混乱
    //////////////////////////////
    static int filecount=0;
    BITMAPFILEHEADER bfh;
    bfh.bfReserved1=bfh.bfReserved2=0;
    bfh.bfType=((WORD)('M'<< 8)|'B');
    bfh.bfSize=54+size;
    bfh.bfOffBits=54;
    CFile bf;
    if(bf.Open("capture.bmp",CFile::modeCreate|CFile::modeWrite)){
    bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
    bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));
    bf.WriteHuge(lpData,size);
    bf.Close();
    // nCount++;
    }
    GlobalFreePtr(lpData);
    UpdateData(FALSE);
    }
      

  2.   

    void CCaptureView::OnCaptureScreen()
    {
    // TODO: Add your command handler code here
    CDC dc;
    dc.CreateDC("DISPLAY",NULL,NULL,NULL);
    int SrcWidth=GetSystemMetrics(SM_CXSCREEN);
    int SrcHeight=GetSystemMetrics(SM_CYSCREEN);
    // int Width=384,Height=288;
    int Width=SrcWidth,Height=SrcHeight;
    /* CDC memdc;
    memdc.CreateCompatibleDC(&dc);
    memdc.StretchBlt(0,0,Width,Height,&dc,0,0,SrcWidth,SrcHeight,SRCCOPY);
    */
    CBitmap bm;
    bm.CreateCompatibleBitmap(&dc,Width,Height);
    CDC tdc;
    tdc.CreateCompatibleDC(&dc);
    CBitmap*pOld=tdc.SelectObject(&bm);
    tdc.SetStretchBltMode(STRETCH_HALFTONE);
    tdc.StretchBlt(0,0,Width,Height,&dc,0,0,SrcWidth,SrcHeight,SRCCOPY);
    // tdc.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY);
    tdc.SelectObject(pOld);
    BITMAP btm;
    bm.GetBitmap(&btm);
    DWORD size=btm.bmWidthBytes*btm.bmHeight;
    LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);
    /////////////////////////////////////////////
    BITMAPINFOHEADER bih;
    bih.biBitCount=btm.bmBitsPixel;
    bih.biClrImportant=0;
    bih.biClrUsed=0;
    bih.biCompression=0;
    bih.biHeight=btm.bmHeight;
    bih.biWidth=btm.bmWidth;
    bih.biPlanes=1;
    bih.biSize=sizeof(BITMAPINFOHEADER);
    bih.biSizeImage=size;
    bih.biXPelsPerMeter=0;
    bih.biYPelsPerMeter=0;
    ///////////////////////////////////
    GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
    // bm.GetBitmapBits(size,lpData); //此函数在处理5-5-5模式的16位色下会出现颜色混乱
    //////////////////////////////
    static int filecount=0;
    BITMAPFILEHEADER bfh;
    bfh.bfReserved1=bfh.bfReserved2=0;
    bfh.bfType=((WORD)('M'<< 8)|'B');
    bfh.bfSize=54+size;
    bfh.bfOffBits=54;
    CFile bf;
    if(bf.Open("capture.bmp",CFile::modeCreate|CFile::modeWrite)){
    bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
    bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));
    bf.WriteHuge(lpData,size);
    bf.Close();
    // nCount++;
    }
    GlobalFreePtr(lpData);
    UpdateData(FALSE);
    }
      

  3.   

    void CCaptureView::OnCaptureScreen()
    {
    // TODO: Add your command handler code here
    CDC dc;
    dc.CreateDC("DISPLAY",NULL,NULL,NULL);
    int SrcWidth=GetSystemMetrics(SM_CXSCREEN);
    int SrcHeight=GetSystemMetrics(SM_CYSCREEN);
    // int Width=384,Height=288;
    int Width=SrcWidth,Height=SrcHeight;
    /* CDC memdc;
    memdc.CreateCompatibleDC(&dc);
    memdc.StretchBlt(0,0,Width,Height,&dc,0,0,SrcWidth,SrcHeight,SRCCOPY);
    */
    CBitmap bm;
    bm.CreateCompatibleBitmap(&dc,Width,Height);
    CDC tdc;
    tdc.CreateCompatibleDC(&dc);
    CBitmap*pOld=tdc.SelectObject(&bm);
    tdc.SetStretchBltMode(STRETCH_HALFTONE);
    tdc.StretchBlt(0,0,Width,Height,&dc,0,0,SrcWidth,SrcHeight,SRCCOPY);
    // tdc.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY);
    tdc.SelectObject(pOld);
    BITMAP btm;
    bm.GetBitmap(&btm);
    DWORD size=btm.bmWidthBytes*btm.bmHeight;
    LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);
    /////////////////////////////////////////////
    BITMAPINFOHEADER bih;
    bih.biBitCount=btm.bmBitsPixel;
    bih.biClrImportant=0;
    bih.biClrUsed=0;
    bih.biCompression=0;
    bih.biHeight=btm.bmHeight;
    bih.biWidth=btm.bmWidth;
    bih.biPlanes=1;
    bih.biSize=sizeof(BITMAPINFOHEADER);
    bih.biSizeImage=size;
    bih.biXPelsPerMeter=0;
    bih.biYPelsPerMeter=0;
    ///////////////////////////////////
    GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
    // bm.GetBitmapBits(size,lpData); //此函数在处理5-5-5模式的16位色下会出现颜色混乱
    //////////////////////////////
    static int filecount=0;
    BITMAPFILEHEADER bfh;
    bfh.bfReserved1=bfh.bfReserved2=0;
    bfh.bfType=((WORD)('M'<< 8)|'B');
    bfh.bfSize=54+size;
    bfh.bfOffBits=54;
    CFile bf;
    if(bf.Open("capture.bmp",CFile::modeCreate|CFile::modeWrite)){
    bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
    bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));
    bf.WriteHuge(lpData,size);
    bf.Close();
    // nCount++;
    }
    GlobalFreePtr(lpData);
    UpdateData(FALSE);
    }