developer:sdksamples:screencapture


Screen Capture All Viewports

C++

Summary: Demonstrates how to screen capture all the visible viewports using the Rhino SDK.

See Also

Question

I would like to screen capture all the visible viewports to the file.

For example:

sdkscreencapture.jpg

The ScreenCaptureToFile and ViewCaptureToFile commands only capture the active viewport. Is there a way to do this?

Answer

The following sample code demonstrates how to screen capture all the visible viewports to the file.

CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
{
  AFX_MANAGE_STATE( ::RhinoApp().RhinoModuleState() );
 
  CWnd* pMainWnd = CWnd::FromHandle( RhinoApp().MainWnd() );
  if( 0 == pMainWnd )
    return failure;
 
  CRhinoGetFileDialog gf;
  gf.SetScriptMode( context.IsInteractive() ? FALSE : TRUE );
  BOOL rc = gf.DisplayFileDialog( CRhinoGetFileDialog::save_bitmap_dialog, 0, pMainWnd );
  if( !rc )
    return cancel;
 
  ON_wString filename = gf.FileName();
  filename.TrimLeftAndRight();
  if( filename.IsEmpty() )
    return nothing;
 
  // Wait for the dialog to disappear. Otherwise,
  // we might see dialog artifacts in our image.
  RhinoApp().Wait( 500 );
 
  CMDIFrameWnd* pFrameWnd = (CMDIFrameWnd*)pMainWnd;
  if( pFrameWnd )
  {
    CWnd* pClientWnd = CWnd::FromHandle( pFrameWnd->m_hWndMDIClient );
    if( pClientWnd )
    {
      CClientDC srcDC( pClientWnd );
 
      CRect rect;
      pClientWnd->GetClientRect( rect );
 
      CRhinoDib dib;
      if( dib.CreateDib(rect.Width(), rect.Height(), 24, true) )
      {
        CDC* dstDC = dib;
        if( dstDC )
        {
          dstDC->BitBlt( 0, 0, rect.Width(), rect.Height(), &srcDC, 0, 0, SRCCOPY );
          dib.CopyToClipboard( 0 );
          dib.WriteToFile( filename );
        }
      }
    }
  }
 
  return success;
}
developer/sdksamples/screencapture.txt · Last modified: 2010/01/26 16:37 (external edit) Driven by DokuWiki Recent changes RSS feed

 © 1997-2010 

McNeel North America Europe Latin AmericaAsia