我现在用mfc把Vega调用出来,然后再用GetDC()函数截取图片,但是截取的是MFC客户端的图片,而不是vega客户端的。我想截取vega客户端的图片,不要MFC客户端的,怎么办? 哪位大侠知道啊啊啊

解决方案 »

  1.   

    不行,我用的vs2003,在里面PrintWindow()没办法调用的啊
      

  2.   

    http://www.codeproject.com/Articles/20651/Capturing-Minimized-Window-A-Kid-s-Trick
      

  3.   

    “把Vega调用出来,findwindow 找到窗口,然后再用GetDC(窗口handle)函数截取图片”
      

  4.   

    可不可以具体说一下findwindow 怎么使用? 没接触过这个函数
      

  5.   

    FindWindow(
    LPCTSTR lpClassName, // pointer to class name  Vega的类名,可以 用SPY++ 找到
    LPCTSTR lpWindowName // pointer to window name Vega的窗口标题
    ); 
      

  6.   

    用SPY++找哪个窗口?是MFC调用的窗口,还是vega窗口?  FindWindow("QWidget","MyACF.acf");这样写?
      

  7.   

    vega窗口,
    类名和标题有一个就行
      

  8.   

    如:
    HWND hDlg=(HWND)::FindWindow("#32770","Dialog");
    HWND hWnd=::FindWindow(_T("360se_Frame"),NULL);
      

  9.   

    不行啊,还是老样子 没有变化 截取的还是MFC客户区的图,这个函数找到的是窗口句柄?
      

  10.   

    我也感觉PrintWindow比较靠谱。记得用正确的窗口句柄哦
      

  11.   

    回复于:2012-09-04 17:50:05http://www.codeproject.com/Articles/20651/Capturing-Minimized-Window-A-Kid-s-Trick 
     
      

  12.   

    这时GetDC要使用那个find的HWND:
    HDC hdc = ::GetDC(hVege);
      

  13.   

    本帖最后由 VisualEleven 于 2012-09-07 16:13:41 编辑
      

  14.   

    HDC hDC=::GetDC(hDlg);//屏幕DC
    CDC *pDC=CDC::FromSafeHandle(hDC);
      

  15.   

    这样写是截取全屏幕DC吧? 我只要客户区的  而且我下面用了Sleep(),程序跑起来的时候Vega的画面就不动了。是不是还要释放DC??
      

  16.   

    HDC hDC=::GetDC(hDlg);//Vege DC
    有了win handle (hDlg)什么都可做
    RECT rc;
    ::GetClientRect(hDlg,&rc);
      

  17.   

    不是啊,截取的还是全屏的DC,而且我一点击截屏,Vega窗口就卡住了。是不是sleep()函数的问题?? 还是说获取DC之后要释放,然后再进行下一张截取?
      

  18.   

    获取DC之后要释放
    DeleteObject(hDC);//Vege DC
      

  19.   

    vega定住不动是没释放DC的问题吗?加了这句之后还是老样子  vega窗口的任何东西都点不了 
      

  20.   

    还有现在截取的还是全屏幕的DC啊 HDC hDC=::GetDC(hDlg);//屏幕DC
    RECT rc;
    ::GetClientRect(hDlg,&rc);
    CDC *pDC=CDC::FromHandle(hDC);这样子?
      

  21.   

    你用‘PrtSc’键看看能不能屏幕拷贝下来。
      

  22.   

    楼上那位说的printwindow 你会吗? 那个函数是怎么用的?
      

  23.   

    “截取vega客户端的图片” 不在程序运行的屏幕上?
      

  24.   

    vega客户端是MFC调用出来的,应该属于隐藏客户端吧。现在截取的还是全屏图,而且截取的时候vega程序会被固定在那里 MFC就会停止工作。。我郁闷  要不加你QQ单独教教我吧
      

  25.   

    "隐藏客户端"
    窗口是隐藏的,
    你叫他不隐藏。
    ShowWindow(hdlg,SW_SHOW)
      

  26.   

    显示错误:“CWnd::ShowWindow":不接受2个参数。疯掉了 
      

  27.   

    ::ShowWindow(hdlg,SW_SHOW)
      

  28.   

    没用,加上这句和没加是一样的效果..  上面那位用printwindow该怎么写? 我的程序在上面 帮忙看看
      

  29.   

    你可以自己做一个试试,用vs2003MFC调用vega  prime然后再截图,要每隔5秒自动截一张图   哪位大神可以试试看啊 然后教教我怎么截图啊 
      

  30.   

    就是一个视景仿真的软件啊。。现在可以截取到VEGA里面的图片了,但是我一截取,vega窗口就固定到桌面上,而且截取的仍然是全屏幕的图。。大神啊  大神啊  求大神解决问题啊  
      

  31.   

    MSG msg;
    while(PeekMessage(&msg,(HWND)NULL,0,0,PM_REMOVE) )
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    Spleep(1);
      

  32.   

    1."现在可以截取到VEGA里面的图片了,但是我一截取,vega窗口就固定到桌面上,"
    你要让有运行的时间,不能不断的截取。2.而且截取的仍然是全屏幕的图。
    就是说全屏幕的包含vega的图
    用你findwindow得到的hwnd,
    RECT rc;
    GetWindowRect(hVega,&rc);
    按 rc的范围值 截取屏幕
      

  33.   

    果然是大神啊....灰常感谢啊! 第二个问题怎么解决啊? 就是我现在截取的还是全屏的图 我只想要MFC窗口的图啊  
      

  34.   

    “我只想要MFC窗口的图”
    到底是什么图,你得到的屏幕 包不包含你要的图? 如果包含的话,只要知道Hwnd可以得到这窗口位置 rc。
    截图时 要在 rc 的范围内 ,就得到你要的了
      

  35.   

    CRect rect;
    GetClientRect(hDlg,&rect);
    int Width = rect.Width();
    int Height = rect.Height();
      

  36.   

    参照截图软件做法:点击菜单或者按下快捷键后,先隐藏当前mfc窗口,然后再截屏(如果你的截屏代码没问题的话),一个小项目里面刚好用到截图功能。
      

  37.   

    //GDI与DX截屏API操作
    LPDIRECTDRAW        lpDD       = NULL;
    LPDIRECTDRAWSURFACE lpDDSPrime = NULL;
    LPDIRECTDRAWSURFACE lpDDSBack  = NULL;
    LPDIRECTDRAWSURFACE lpDDSGdi   = NULL;
    LPDIRECTDRAWSURFACE lpSurf     = NULL;DDSURFACEDESC DDSdesc;
    BOOL m_b24=TRUE;
    //rfbServerInitMsg m_scrinfo;
    RECT    m_bmrect;struct _BMInfo {
        BITMAPINFO bmi       ;
        BOOL       truecolour;
        RGBQUAD    cmap[256] ;
    } m_bminfo; // 用来保存位图信息的结构int DX_Init() {// DirectX初始化。返回当前表面获取一张屏幕位图的存储空间大小
        HRESULT hr;    // 初始化directX
        hr = DirectDrawCreate(0, &lpDD, 0);
        if (FAILED(hr)) return FALSE;    hr = lpDD->SetCooperativeLevel(NULL, DDSCL_NORMAL);
        if (FAILED(hr)) return FALSE;    ZeroMemory(&DDSdesc, sizeof(DDSdesc));
        DDSdesc.dwSize  = sizeof(DDSdesc);
        DDSdesc.dwFlags = DDSD_CAPS;
        DDSdesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
        hr = lpDD->CreateSurface(&DDSdesc, &lpDDSPrime, 0);
        if (FAILED(hr)) return FALSE;    hr = lpDD->GetGDISurface(&lpDDSGdi);
        if (FAILED(hr)) return FALSE;    ZeroMemory(&DDSdesc, sizeof(DDSdesc));
        DDSdesc.dwSize  = sizeof(DDSdesc);
        DDSdesc.dwFlags = DDSD_ALL;
        hr = lpDDSPrime->GetSurfaceDesc(&DDSdesc);
        if (FAILED(hr)) return FALSE;    // 初始化位图信息
        if ((DDSdesc.dwFlags & DDSD_WIDTH) && (DDSdesc.dwFlags & DDSD_HEIGHT)) {
            m_bmrect.left = m_bmrect.top = 0;
            m_bmrect.right = DDSdesc.dwWidth;
            m_bmrect.bottom = DDSdesc.dwHeight;
        } else return FALSE;    m_bminfo.bmi.bmiHeader.biCompression = BI_RGB;//BI_BITFIELDS;
        m_bminfo.bmi.bmiHeader.biBitCount = DDSdesc.ddpfPixelFormat.dwRGBBitCount;    // m_bminfo.truecolour = DDSdesc.ddpfPixelFormat.dwFlags & DDPF_RGB;
        if (m_bminfo.bmi.bmiHeader.biBitCount > 8)
            m_bminfo.truecolour = TRUE;
        else
            m_bminfo.truecolour = FALSE;    ZeroMemory(&DDSdesc, sizeof(DDSdesc));
        DDSdesc.dwSize = sizeof(DDSdesc);
        DDSdesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
        DDSdesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
        DDSdesc.dwHeight = m_bmrect.bottom - m_bmrect.top;
        DDSdesc.dwWidth  = m_bmrect.right  - m_bmrect.left;
        hr = lpDD->CreateSurface(&DDSdesc, &lpDDSBack, 0);
        if (FAILED(hr)) return FALSE;
    //  hr = lpDDSPrime->QueryInterface( IID_IDirectDrawSurface3, (LPVOID *)&lpSurf);
    //  if (FAILED(hr)) return FALSE;    switch (m_bminfo.bmi.bmiHeader.biBitCount) {
        case 32:
        case 24:
           // Update the bitmapinfo header
           m_b24 = TRUE;
           m_bminfo.bmi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
           m_bminfo.bmi.bmiHeader.biWidth = 1024;
           m_bminfo.bmi.bmiHeader.biHeight = 768;
           m_bminfo.bmi.bmiHeader.biPlanes = 1;
    //     m_bminfo.bmi.bmiHeader.biBitCount = 24;
           m_bminfo.bmi.bmiHeader.biCompression = BI_RGB;
           m_bminfo.bmi.bmiHeader.biSizeImage = abs((m_bminfo.bmi.bmiHeader.biWidth * m_bminfo.bmi.bmiHeader.biHeight * m_bminfo.bmi.bmiHeader.biBitCount)/8);
           m_bminfo.bmi.bmiHeader.biXPelsPerMeter = (1024*1000)/1024;
           m_bminfo.bmi.bmiHeader.biYPelsPerMeter = (768*1000)/768;
           m_bminfo.bmi.bmiHeader.biClrUsed   = 0;
           m_bminfo.bmi.bmiHeader.biClrImportant = 0;
           break;
        }    return m_bminfo.bmi.bmiHeader.biSizeImage;
    }BOOL CaptureScreen(RECT &rect, BYTE *scrBuff, UINT scrBuffSize) {// 捕捉屏幕。rect: 区域。scrBuff: 输出缓冲。scrBuffSize: 缓冲区大小
        HRESULT hr=0;    hr = lpDDSBack->BltFast(rect.left,rect.top,lpDDSPrime,&rect,DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
        if (FAILED(hr)) return FALSE;    DDSURFACEDESC surfdesc;
        ZeroMemory(&surfdesc, sizeof(surfdesc));
        surfdesc.dwSize = sizeof(surfdesc);    hr = lpDDSBack->Lock(&rect, &surfdesc, DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR /*|DDLOCK_NOSYSLOCK*/, NULL);
    //  hr = lpDDSPrime->Lock(&rect, &surfdesc, DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR /*|DDLOCK_NOSYSLOCK*/, NULL);
        if (FAILED(hr)) return FALSE;    // copy the data into our buffer
        BYTE * destbuffpos, * srcbuffpos;
    //  m_scrinfo.format.bitsPerPixel = 24;
        srcbuffpos = (BYTE *) surfdesc.lpSurface;
        destbuffpos = scrBuff;    memcpy( destbuffpos, srcbuffpos,m_bminfo.bmi.bmiHeader.biSizeImage);    // unlock the primary surface
    //  lpDDSPrime->Unlock(surfdesc.lpSurface);
        lpDDSBack->Unlock(surfdesc.lpSurface);
        return TRUE;
    }int SaveBitmapToFile(BITMAP *bitmap, LPSTR lpFileName,char *lpBuf) {
       DWORD dwWritten;
       BITMAPFILEHEADER   bmfHdr;
       BITMAPINFOHEADER   bi;
       HANDLE          fh=NULL;
       bi.biSize = sizeof(BITMAPINFOHEADER);
       bi.biWidth= bitmap->bmWidth;
       bi.biHeight = bitmap->bmHeight;
       bi.biPlanes = 1;
       bi.biBitCount      = bitmap->bmBitsPixel*8;
       bi.biCompression   = BI_RGB;
       bi.biSizeImage     = 0;
       bi.biXPelsPerMeter = 0;
       bi.biYPelsPerMeter = 0;
       bi.biClrUsed       = 0;
       bi.biClrImportant  = 0;
       fh = CreateFile(lpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
       if (fh == INVALID_HANDLE_VALUE) return FALSE;
       bmfHdr.bfType = 0x4D42; // "BM"
       bmfHdr.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)+bitmap->bmWidth*bitmap->bmHeight*bitmap->bmBitsPixel;
       bmfHdr.bfReserved1 = 0;
       bmfHdr.bfReserved2 = 0;
       bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER);
       WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL);
       WriteFile(fh, (char *)&bi,sizeof(BITMAPINFOHEADER), &dwWritten, NULL);
       WriteFile(fh, (char *)lpBuf,bitmap->bmWidth*bitmap->bmHeight*bitmap->bmBitsPixel, &dwWritten, NULL);
       FlushFileBuffers(fh);
       CloseHandle(fh);
       return true;
    }//(1)获取屏幕绘图设备
    //(2)创建一个与屏幕绘图设备相兼容的内存绘图设备
    //(2)在内存中创建一个与屏幕绘图设备相兼容的图像对象
    //(3)将屏幕设备中的图像复制到内存绘图设备中
    //(4)将内存图像保存到文件中
    //相关函数:
    //GetDIBits:按位的方式返回指定的BITMAP,并按指定的格式存储到内存中
    int GetBitmapFromScreen(char *lpFileName) {
        char *lpBuf;
        HBITMAP hBitmap,hOld ;
        HDC hDC,hcDC;
        BITMAP bb;
        BITMAPINFO b;
        HANDLE hp,fh=NULL;
        DWORD dwX,dwY;    dwX=GetSystemMetrics(SM_CXSCREEN);
        dwY=GetSystemMetrics(SM_CYSCREEN);
        hDC=GetDC(NULL);
        hcDC=CreateCompatibleDC(hDC);
        hBitmap=CreateCompatibleBitmap(hDC,dwX,dwY);
        hOld=(HBITMAP)SelectObject(hcDC,hBitmap);
        BitBlt(hcDC,0, 0,dwX,dwY, hDC, 0, 0, SRCCOPY);
        bb.bmWidth=dwX;
        bb.bmHeight =dwY;
        bb.bmPlanes = 1;
        bb.bmWidthBytes=bb.bmWidth*3;
        bb.bmBitsPixel=3;
        bb.bmType=0;
        b.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        b.bmiHeader.biWidth        =dwX;
        b.bmiHeader.biHeight       =dwY;
        b.bmiHeader.biPlanes       =1;
        b.bmiHeader.biBitCount     =3*8;
        b.bmiHeader.biCompression  =BI_RGB;
        b.bmiHeader.biSizeImage    =0;
        b.bmiHeader.biXPelsPerMeter=0;
        b.bmiHeader.biYPelsPerMeter=0;
        b.bmiHeader.biClrUsed      =0;
        b.bmiHeader.biClrImportant =0;
        b.bmiColors[0].rgbBlue     =8;
        b.bmiColors[0].rgbGreen    =8;
        b.bmiColors[0].rgbRed      =8;
        b.bmiColors[0].rgbReserved =0;
        hp=GetProcessHeap();
        lpBuf=(char *)HeapAlloc(hp,HEAP_ZERO_MEMORY,bb.bmHeight*bb.bmWidth*4);
        GetDIBits(hcDC,hBitmap,0,dwY,lpBuf,&b,DIB_RGB_COLORS);
        SaveBitmapToFile(&bb,lpFileName,lpBuf);
        ReleaseDC(NULL,hDC);
        DeleteDC(hcDC);
        DeleteObject(hBitmap);
        DeleteObject(hOld);
        HeapFree(hp,0,lpBuf);
        return true;
    }
      

  38.   

    截取的屏幕的确包含我要的图,HWND得到的rc??  
        CRect rc;
        ::GetClientRect(hDlg,&rc);  这样子对吗?
      

  39.   

    HWND一定是你findwindow找到的 ,对
      

  40.   

    可是还是老样子啊..   CDC *pDC;
      HWND hDlg=(HWND)::FindWindow("Vega Prime",NULL);
      CRect rect;
      ::GetClientRect(hDlg,&rect);
      HDC hDC=::GetDC(hDlg);//屏幕DC
      pDC=CDC::FromHandle(hDC);哪里有问题??
      

  41.   

    ::GetWindowRect(hDlg,&rect);
    这个rc是要用的,现在你可以用
    CDC*pDC=GetDC();
    这个DC包含了你要的图。把这个DC中的 rc 范围内容,复制到一个 MemDC
    pDC->Bitblt(MemDC,0,0,rc.width(),rc.height(),rc.left,rc.top);
    就是你要的图
      

  42.   

    报错...    HWND hDlg=(HWND)::FindWindow("Vega Prime",NULL);
        CRect rc;
        ::GetWindowRect(hDlg,&rc);    HDC hDC=::GetDC(hDlg);//屏幕DC
        CDC *pDC=GetDC();
        
        int Width = pDC->GetDeviceCaps(HORZRES);
        int Height = pDC->GetDeviceCaps(VERTRES);    CDC memDC;//内存DC
        memDC.CreateCompatibleDC(pDC);

        CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
        memBitmap.CreateCompatibleBitmap(pDC,Width,Height);    oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
        pDC->BitBlt(memDC,0,0,rc.Width,rc.Height,rc.left,rc.top);报错CDC::BitBlt 不接受7个参数??
    什么状况?
      

  43.   

    ::BitBlt(hDC1,0, 100, bmp.bmWidth, bmp.bmHeight,hDC, 0,0,SRCCOPY);
    pDC->BitBlt(memDC,0,0,rc.Width,rc.Height,rc.left,rc.top,SRCCOPY);
      

  44.   

    ::BitBlt(hDC1,0, 100, bmp.bmWidth, bmp.bmHeight,hDC, 0,0,SRCCOPY);这里面的bmp.bmWidth是什么参数??
    这样写的话还是会报错的
      

  45.   

    pDC->BitBlt(memDC,0,0,rc.Width,rc.Height,rc.left,rc.top,SRCCOPY);
      

  46.   

           HWND hDlg=(HWND)::FindWindow("Vega Prime",NULL);
           HDC hDC=::GetDC(hDlg);
           CDC *pDC=CDC::FromHandle(hDC);
           CRect rc;
           ::GetWindowRect(hDlg,&rc); 
           int Width = pDC->GetDeviceCaps(HORZRES);
           int Height = pDC->GetDeviceCaps(VERTRES);
           CDC memDC;//内存DC
           memDC.CreateCompatibleDC(pDC);

           CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
           memBitmap.CreateCompatibleBitmap(pDC,Width,Height);
           oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
           pDC->BitBlt(memDC,0,0,rc.Width,rc.Height,rc.left,rc.top,SRCCOPY);错误  CDC::Biblt不能讲参数1从CDC转换为int
      

  47.   

    HWND hDlg=(HWND)::FindWindow("Vega Prime",NULL);
    HDC hDC=::GetDC(hDlg);
    CDC *pDC=CDC::FromHandle(hDC);
    ::GetWindowRect(hDlg,&rc);
    int Width = rc.Width(); 
    int Height = rc.Height();
    CDC memDC;//内存DC
    memDC.CreateCompatibleDC(pDC);
    CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap memBitmap.CreateCompatibleBitmap(pDC,Width,Height);
    oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
    memDC.BitBlt(0,0,Width,Height,pDC,0,0,SRCCOPY);这样写倒是可以编译,但是运行的时候会出现超出内存,也给看一下吧
      

  48.   

    ::GetWindowRect(hDlg,&rc);
    int Width = rc.Width();  
    int Height = rc.Height();
    看看宽高对不对》
    另外:
    memDC.BitBlt(0,0,Width,Height,pDC,0,0,SRCCOPY);
    应该是rc.left,rc.top
      

  49.   

    int Width = rc.Width();  
    int Height = rc.Height();
    这两句是rc的实际宽度还是像素?  
        原来的语句
            int Width = pDC->GetDeviceCaps(HORZRES);
    int Height = pDC->GetDeviceCaps(VERTRES);
       好像是像素吧,要是pDC指向rc的像素的话怎么写?
    会不会是这里的问题?
      

  50.   

    出现这个提示Run-Time Check Failure #2 - Stack around the variable 'bih' was corrupted. 程序中断
      

  51.   

    int Width = rc.Width();   
    int Height = rc.Height();
    是像素 pixel int Width = pDC->GetDeviceCaps(HORZRES);
    int Height = pDC->GetDeviceCaps(VERTRES);
    是全屏大小,
    你只要 bitblt 从 vega 左上起的 宽高 到 memDC。
       
      

  52.   

    从vega左上起?? 怎么定义? 
      

  53.   

    HWND hDlg=(HWND)::FindWindow("Vega Prime",NULL);
    HDC hDC=::GetDC(hDlg);
    CDC *pDC=CDC::FromHandle(hDC);
    ::GetWindowRect(hDlg,&rc);
    int Width = pDC->GetDeviceCaps(HORZRES);
    int Height = pDC->GetDeviceCaps(VERTRES);
    CDC memDC;//内存DC
    memDC.CreateCompatibleDC(pDC);
    CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap memBitmap.CreateCompatibleBitmap(pDC,Width,Height);
    oldmemBitmap = memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
    memDC.BitBlt(0,0,Width,Height,pDC,rc.left,rc.top,0,SRCCOPY);为什么这样写截取下来的图是整个黑色屏幕 什么都没有? 
      

  54.   

    rc.left,rc.top 就是从vega左上
    你要的其实就是:
    atl+“prtsc”
    你可以试试
    让vega窗口 显示区 小于 屏幕,然后按:
    atl+“prtsc”
    打开‘画图’paste进来,可以看到只有 Vega 被截图了。
      

  55.   

    我给你做了个:
    截取“拖拉机大赛”://
    HBITMAP CopyScreenToBitmap(CRect &Rect,HWND hwnd) 
    {  
    HDC      hScrDC, hMemDC;      
    HBITMAP  hOldBitmap,hBitmap;  
    int      xScrn, yScrn;        
    hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); 
    hMemDC = CreateCompatibleDC(hScrDC); 
    //
    xScrn = GetDeviceCaps(hScrDC, HORZRES); 
    yScrn = GetDeviceCaps(hScrDC, VERTRES); 
    //
    if (Rect.left < 0)  Rect.left = 0; 
    if (Rect.top < 0)   Rect.top  = 0; 
    if (Rect.right  > xScrn)  Rect.right = xScrn; 
    if (Rect.bottom > yScrn) Rect.bottom = yScrn; 
    //
    hBitmap = CreateCompatibleBitmap(hScrDC, Rect.Width(),Rect.Height()); 
    hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap); 
    BitBlt(hMemDC,0,0,Rect.Width(),Rect.Height(),hScrDC,Rect.left,Rect.top,SRCCOPY); 
    hBitmap =(HBITMAP)SelectObject(hMemDC,hOldBitmap); 
    //
    DeleteDC(hScrDC); 
    DeleteDC(hMemDC); 
    //
    return hBitmap; 
    }      
    // 
    BOOL SaveBitmapToFile(HBITMAP hBitmap, LPCSTR lpszFileName) 

    HDC hDC; //设备描述表 
    int iBits; //当前显示分辨率下每个像素所占字节数 
    WORD wBitCount; //位图中每个像素所占字节数 
    //定义调色板大小, 位图中像素字节大小 , 位图文件大小 , 写入文件字节数 
    DWORD dwPaletteSize=0,dwBmBitsSize,dwDIBSize, dwWritten; 
    BITMAP Bitmap; //位图属性结构 
    BITMAPFILEHEADER bmfHdr; //位图文件头结构 
    BITMAPINFOHEADER bi;//位图信息头结构 
    LPBITMAPINFOHEADER lpbi; //指向位图信息头结构 
    HANDLE fh, hDib, hPal; 
    HPALETTE hOldPal=NULL;//定义文件,分配内存句柄,调色板句柄  //计算位图文件每个像素所占字节数 
    hDC = CreateDC("DISPLAY",NULL,NULL,NULL); 
    iBits = GetDeviceCaps(hDC, BITSPIXEL) * 
    GetDeviceCaps(hDC, PLANES); //?
    DeleteDC(hDC); 
    if (iBits <= 1)       wBitCount = 1; 
    else if (iBits <= 4)  wBitCount = 4; 
    else if (iBits <= 8)  wBitCount = 8; 
    else if (iBits <= 24) wBitCount = 24; 
    else               wBitCount = 32; 
    //计算调色板大小 
    if (wBitCount <= 8) dwPaletteSize=(1 << wBitCount)*sizeof(RGBQUAD);  //设置位图信息头结构 
    GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap); 
    bi.biSize = sizeof(BITMAPINFOHEADER); 
    bi.biWidth = Bitmap.bmWidth; 
    bi.biHeight = Bitmap.bmHeight; 
    bi.biPlanes = 1; 
    bi.biBitCount = wBitCount; 
    bi.biCompression = BI_RGB; 
    bi.biSizeImage = 0; 
    bi.biXPelsPerMeter = 0; 
    bi.biYPelsPerMeter = 0; 
    bi.biClrUsed = 0; 
    bi.biClrImportant = 0;  dwBmBitsSize = ((Bitmap.bmWidth*wBitCount+31)/32)*4*Bitmap.bmHeight; 
    //为位图内容分配内存 
    hDib = GlobalAlloc(GHND,dwBmBitsSize+dwPaletteSize+sizeof(BITMAPINFOHEADER)); 
    lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib); 
    *lpbi = bi; 
    // 处理调色板 
    hPal = GetStockObject(DEFAULT_PALETTE); 
    if (hPal) 

    hDC = ::GetDC(NULL); 
    hOldPal=SelectPalette(hDC,(HPALETTE)hPal,FALSE); 
    RealizePalette(hDC); 

    // 获取该调色板下新的像素值 
    GetDIBits(hDC,hBitmap,0,(UINT)Bitmap.bmHeight,(LPSTR)lpbi+sizeof(BITMAPINFOHEADER)+dwPaletteSize, (BITMAPINFO *)lpbi,DIB_RGB_COLORS); 
    //恢复调色板 
    if (hOldPal) 

    SelectPalette(hDC, hOldPal, TRUE); 
    RealizePalette(hDC); 
    ::ReleaseDC(NULL, hDC); 

    //创建位图文件 
    fh=CreateFile(lpszFileName, GENERIC_WRITE,0, NULL, CREATE_ALWAYS,
    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); 
    if (fh==INVALID_HANDLE_VALUE) return FALSE; 
    // 设置位图文件头 
    bmfHdr.bfType = 0x4D42; // "BM" 
    dwDIBSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+dwPaletteSize+dwBmBitsSize; 
    bmfHdr.bfSize = dwDIBSize; 
    bmfHdr.bfReserved1 = 0; 
    bmfHdr.bfReserved2 = 0; 
    bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER)+(DWORD)sizeof(BITMAPINFOHEADER)+dwPaletteSize; 
    // 写入位图文件头 
    WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL); 
    // 写入位图文件其余内容 
    WriteFile(fh, (LPSTR)lpbi, sizeof(BITMAPINFOHEADER)+dwPaletteSize+dwBmBitsSize , &dwWritten, NULL); 
    //清除 
    GlobalUnlock(hDib); 
    GlobalFree(hDib); 
    CloseHandle(fh);
    return TRUE; 

    // Button1 "AltPrtsc"
    void CAltPrtscDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    HWND hWnd=::FindWindow(0,"拖拉机大赛");
    if(hWnd)
    {
    CRect rc;
    ::GetWindowRect(hWnd,&rc);
    HBITMAP hBmp=CopyScreenToBitmap(rc,hWnd);
    BOOL ret=SaveBitmapToFile(hBmp, "Tmp.bmp"); 
    }
    }CAltPrtscDlg 是个只有一个按钮的对话框。
      

  56.   

    BOOL ret=SaveBitmapToFile(hBmp, "Tmp.bmp"); 
    我的 在“AltPrtsc”下,不知道你做了对话框没,还是只用了几个函数。
    搜索看看吧
      

  57.   

    其实源DC可以是2个之一:
    1。hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); // '桌面DC'
    即上次给你的。HBITMAP CopyScreenToBitmap(CRect &Rect) // hWnd 已删除2。hScrDC = ::GetDC(hwnd);// '拖拉机大赛的DC'
    用2时的程序:
    //
    HBITMAP CopyWinToBitmap(CRect &Rect,HWND hwnd) 
    {  
    HDC      hScrDC, hMemDC;      
    HBITMAP  hOldBitmap,hBitmap;  
            
    hScrDC = ::GetDC(hwnd);// '拖拉机大赛的DC'
    hMemDC = CreateCompatibleDC(hScrDC); 
    //
    hBitmap = CreateCompatibleBitmap(hScrDC, Rect.Width(),Rect.Height()); 
    hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap); 
    //
    BitBlt(hMemDC,0,0,Rect.Width(),Rect.Height(),hScrDC,Rect.left,Rect.top,SRCCOPY); 
    hBitmap =(HBITMAP)SelectObject(hMemDC,hOldBitmap); 
    //
    ::ReleaseDC(hwnd,hScrDC); 
    DeleteDC(hMemDC); 
    //
    return hBitmap; 
    }      
    // "AltPrtsc"
    void CAltPrtscDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    HWND hWnd=::FindWindow(0,"拖拉机大赛");
    if(hWnd)
    {
    CRect rc;
    ::GetWindowRect(hWnd,&rc);
    #ifdef USE_SCREEN
    HBITMAP hBmp=CopyScreenToBitmap(rc);
    #else
    ::MapWindowPoints(0,hWnd,(CPoint*)&rc,2);
            HBITMAP hBmp=CopyWinToBitmap(rc,hWnd);
    #endif 
    BOOL ret=SaveBitmapToFile(hBmp, "Tmp.bmp"); 
    }
    }
      

  58.   

    每隔1秒或者几秒钟截图问题不大,对vega的运行速度有影响。
    你试试可以到多快。
      

  59.   

    还是用Sleep函数? 保存到文件夹怎么保存? 我现在还没找到图在哪
      

  60.   

    SaveBitmapToFile这个函数只保存了一张图片?
      

  61.   

    SaveBitmapToFile这个函数只保存了一张图片?
    对,本来就是一个 Bitmap 。
    名可以是给定的。
      

  62.   

    这样你做一个基于对话框的工程。
    再拖一个按钮。
    加上按钮响应。
    // "AltPrtsc"
    void CAltPrtscDlg::OnButton1()  
    把我给你的代码复制进来。
    如果没有‘拖拉机大赛’改‘计算器’
    编译运行。
    那个tmp.bmp就在工程目录下。
      

  63.   

    我现在找到图了 但是又有一个问题 就是保存的时候,SaveBitmapToFile(hMap,"E:\\my\\0.bmp");这个函数怎么更改文件的名字啊 要不然下一张图就把上一张给覆盖了啊
      

  64.   

    如:
    void CAltPrtscDlg::OnButton1() // OnTimer
    {
    static int count=0;
    char filename[40];
    count ++;
    sprintf(filename,"E:\\my\\%d.bmp",count);

       
    // TODO: Add your control notification handler code here
        HWND hWnd=::FindWindow(0,"拖拉机大赛");    
        if(hWnd)
        {
            CRect rc;
            ::GetWindowRect(hWnd,&rc);
            HBITMAP hBmp=CopyScreenToBitmap(rc,hWnd);
            BOOL ret=SaveBitmapToFile(hBmp, filename); 
        }
    }