McNeel Wiki
Using CRhinoGetFileDialog to Preview Bitmaps
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
DeveloperC++
SummaryDemonstrates 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.

  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;
  }
rename · changes · history · subscriptions · lost and found · references · file upload