Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:getfiledialog [2015/09/14] (current)
Line 1: Line 1:
 +====== Using CRhinoGetFileDialog to Preview Bitmaps ======
 +====== C++ ======
 +> **Summary:​** //​Demonstrates how to use the CRhinoGetFileDialog class to preview bitmap images.//
 +
 +=====Question=====
 +Can you show me a small sample that explain the use of CRhinoGetFileDialog class? I just want to get a bitmap file, have a preview of it, and use the filename in a texture class.
 +
 +=====Answer=====
 +The follow example code demonstrates the use of the CRhinoGetFileDialog class.
 +
 +
 +<code c++>
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  ON_wString filename;
 +
 +  // Prompt for a bitmap filename
 +  CRhinoGetFileDialog gf;
 +  gf.SetScriptMode( context.IsInteractive() ? FALSE : TRUE );
 +  BOOL rc = gf.DisplayFileDialog( ​
 +        CRhinoGetFileDialog::​open_bitmap_dialog, ​
 +        filename, ​
 +        CWnd::​FromHandle( RhinoApp().MainWnd() )
 +        );
 +  if( !rc )
 +    return cancel;
 +
 +  // Verify filename
 +  filename = gf.FileName();​
 +  filename.TrimLeftAndRight();​
 +  if( filename.IsEmpty() )
 +    return cancel;
 +
 +  // Verify the file
 +  if( !CRhinoFileUtilities::​FileExists(filename) )
 +  {
 +    ON_wString error = L"The specified file was not found.\n";​
 +    if( context.IsInteractive() )
 +      ::​RhinoMessageBox( error, L"​Test",​ MB_OK | MB_ICONEXCLAMATION );
 +    else
 +      RhinoApp().Print( error );
 +    return CRhinoCommand::​failure;​
 +  }
 +
 +  // Verify the bitmap
 +  CRhinoDib dib;
 +  if( !dib.ReadFromFile(filename) )
 +  {
 +    ON_wString error = L"The specified file cannot be identifed as a supported type.\n";​
 +    if( context.IsInteractive() )
 +      ::​RhinoMessageBox( error, L"​Test",​ MB_OK | MB_ICONEXCLAMATION );
 +    else
 +      RhinoApp().Print( error );
 +    return CRhinoCommand::​failure;​
 +  }
 +
 +  // To do...
 +
 +  return success;
 +}
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/getfiledialog.txt ยท Last modified: 2015/09/14 (external edit)