我想做个截屏和数据打包的工具,现在使用的单文档,上面绑定了一个按钮,按下按钮就和QQ一样,可以全屏选择截屏,截屏完后就在单文档特定的一块区域上面显示这张图,但是我本人没学过MFC,一点思路都没有,哪人牛人能知道下在下,给点思路就行,谢谢.

解决方案 »

  1.   

    http://download.csdn.net/detail/wanchuxu/1459907
      

  2.   


    void CDeskDlg::OnButtonMap() 
    {
    // TODO: Add your control notification handler code here



    CDC* pDeskDC =  GetDesktopWindow()->GetDC(); //获取桌面画布对象
    CRect rc;
    GetDesktopWindow()->GetClientRect(rc); //获取屏幕的客户区域
    CDC  memDC; //定义一个内存画布
    memDC.CreateCompatibleDC(pDeskDC); //创建一个兼容的画布
    CBitmap bmp;
    bmp.CreateCompatibleBitmap(pDeskDC,rc.Width(),rc.Height()); //创建兼容位图
    memDC.SelectObject(&bmp); //选中位图对象
    BITMAP bitmap;
    bmp.GetBitmap(&bitmap);
    memDC.BitBlt(0,0,bitmap.bmWidth,bitmap.bmHeight,pDeskDC,0,0,SRCCOPY);


    DWORD size=bitmap.bmWidthBytes*bitmap.bmHeight;
    LPSTR lpData=(LPSTR)GlobalAlloc(GPTR,size);
    int panelsize  = 0; //记录调色板大小
    if(bitmap.bmBitsPixel<16) //判断是否为真彩色位图
    panelsize = pow(2,bitmap.bmBitsPixel*sizeof(RGBQUAD));
    BITMAPINFOHEADER *pBInfo = (BITMAPINFOHEADER*)LocalAlloc(LPTR,
    sizeof(BITMAPINFO)+panelsize);
    pBInfo->biBitCount       = bitmap.bmBitsPixel;
    pBInfo->biClrImportant   = 0;
    pBInfo->biCompression    = 0;
    pBInfo->biHeight         = bitmap.bmHeight;
    pBInfo->biPlanes         = bitmap.bmPlanes;
    pBInfo->biSize           = sizeof(BITMAPINFO);
    pBInfo->biSizeImage      = bitmap.bmWidthBytes*bitmap.bmHeight;
    pBInfo->biWidth          = bitmap.bmWidth;
    pBInfo->biXPelsPerMeter  = 0;
    pBInfo->biYPelsPerMeter  = 0;

    GetDIBits(memDC.m_hDC,bmp,0,pBInfo->biHeight,lpData,
    (BITMAPINFO*)pBInfo,DIB_RGB_COLORS);

    CString path,name,m_number;
    CTime time = CTime::GetCurrentTime();

    name = "D:\\"+time.Format("%Y%m%d%H%M%S")+".bmp";
    BITMAPFILEHEADER bfh;
    bfh.bfReserved1 = bfh.bfReserved2 = 0;
    bfh.bfType      = ((WORD)('M'<< 8)|'B');
    bfh.bfSize      = 54+size;
    bfh.bfOffBits   = 54;
    CFile file;
    if(file.Open(name,CFile::modeCreate|CFile::modeWrite))
    {
    file.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
    file.WriteHuge(pBInfo,sizeof(BITMAPINFOHEADER));
    file.WriteHuge(lpData,size);
    file.Close();
    }}把这段代码添加到button的响应函数中,点击按钮保存图片到D盘,楼主看看能改改吧。
      

  3.   

    http://download.csdn.net/download/weiym/1955621