0

CDCを使用してグリッドを描画したアプリケーションがあります(テキスト、長方形、およびビットマップがあります)。保存時に完成したグリッドのスクリーンショットを撮り、そのスクリーンショットをファイルの「プレビュー」として使用したいと思います。

アプリケーションのスクリーンショットを撮って保存するにはどうすればよいですか?

ありがとうございました、

4

2 に答える 2

0

答えはこちら

void CScreenShotDlg::OnPaint()
{
    // device context for painting
    CPaintDC dc(this);

    // Get the window handle of calculator application.
    HWND hWnd = ::FindWindow( 0, _T( "Calculator" ));

    // Take screenshot.
    PrintWindow( hWnd,
                 dc.GetSafeHdc(),
                 0 );
}
于 2012-08-07T00:31:01.837 に答える
0

ウィンドウの隠れた部分もキャプチャしたかったので、最終的にはこのようにしました(コンテンツが画面を超えてスクロールする必要があるため)。

CDC* WindowToCaptureDC = AfxGetMainWnd()->GetWindowDC();
CDC CaptureDC;
CDC MemDC;
MemDC.CreateCompatibleDC(WindowToCaptureDC);
CaptureDC.CreateCompatibleDC(WindowToCaptureDC);

CBitmap CaptureBmp;
CBitmap ResizeBmp;
int pWidth = grid.tableWidth + grid.marginLeft*2;
int pHeight = grid.tableHeight + grid.marginBottom; 

CaptureBmp.CreateCompatibleBitmap( WindowToCaptureDC, pWidth, pHeight);
CaptureDC.SelectObject(&CaptureBmp);

CBrush brush(RGB(255, 255, 255));
CaptureDC.SelectObject(&brush);
CaptureDC.Rectangle(0, 0, pWidth, pHeight);

///OnDraw で行ったように、CaptureDC にアイテムを描画しました ///

double width = //desired width;
double height = //desired width;

    //maintain aspect ratio
if(pWidth!=width || pHeight!=height)
{
    double w = width/pWidth;
    double h = height/pHeight;
    if(w < h)
        height = height*w;
    else
        width = width*h;
}

ResizeBmp.CreateCompatibleBitmap(WindowToCaptureDC, width, height);
MemDC.SelectObject(&ResizeBmp);

MemDC.StretchBlt(0, 0, width, height, &CaptureDC, 0, 0, pWidth, pHeight, SRCCOPY);

CImage TempImageObj;
TempImageObj.Attach((HBITMAP)ResizeBmp.Detach());
CString filePath = _T("LOCATION\\image.bmp");
TempImageObj.Save(filePath);
于 2012-08-08T00:00:19.890 に答える