Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:screencapture [2015/09/14] (current)
Line 1: Line 1:
 +====== Screen Capture All Viewports ======
 +====== C++ ======
 +> **Summary:​** //​Demonstrates how to screen capture all the visible viewports using the Rhino SDK.//
 +
 +=====See Also=====
 +[[developer:​sdksamples:​screencaptureview|Screen Capture a Viewport]]
 +
 +=====Question=====
 +I would like to screen capture all the visible viewports to the file.
 +
 +For example:
 +
 +{{:​legacy:​en:​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.
 +
 +
 +<code c++>
 +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;
 +}
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/screencapture.txt ยท Last modified: 2015/09/14 (external edit)