McNeel Wiki
How To: Maximize a View
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
SummaryDemonstrates how to maximize a view using the Rhino SDK.

C++

  CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
  {
    CRhinoGetString gs;
    gs.SetCommandPrompt( L"Name of viewport to maximize" );
    gs.GetString();
    if( gs.CommandResult() != CRhinoCommand::success )
      return gs.CommandResult();


    ON_wString view_name( gs.String() );
    view_name.TrimLeftAndRight();
    if( view_name.IsEmpty() )
      return CRhinoCommand::cancel;


    ON_SimpleArray<CRhinoView*> view_list;
    int view_count = context.m_doc.GetViewList( view_list );


    CRhinoView* active_view = NULL;
    int i;


    for( i = 0; i < view_count; i++ )
    {
      CRhinoView* view = view_list[i];
      if( view && view_name.CompareNoCase(view->Viewport().Name()) == 0 )
      {
        active_view = view;
        break;
      }
    }


    if( !active_view )
    {
      RhinoApp().Print( L"Unable to find viewport named %s\n", view_name );
      return CRhinoCommand::nothing;
    }


    ::RhinoApp().SetActiveView( active_view );
    CWnd* frame_wnd = active_view->GetParent();
    if( frame_wnd )
    {
      frame_wnd->ShowWindow( SW_SHOWMAXIMIZED );
      frame_wnd->BringWindowToTop();
    }
    return CRhinoCommand::success;
  }

VB.NET (Rhino 4)

  <DllImport("user32.dll", ExactSpelling:=True, CharSet:=CharSet.Auto)> _
  Private Shared Function GetParent(ByVal hWnd As IntPtr) As IntPtr
  End Function


  <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
  Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As Long
  End Function


  '''<summary> This gets called when when the user runs this command.</summary>
  Public Overrides Function RunCommand(ByVal context As RMA.Rhino.IRhinoCommandContext)_
    As RMA.Rhino.IRhinoCommand.result


    Dim gs As New MRhinoGetString()
    gs.SetCommandPrompt("Name of viewport to maximize")
    gs.GetString()
    If (gs.CommandResult() <> IRhinoCommand.result.success) Then Return gs.CommandResult()


    Dim view_name As String = gs.String()
    view_name = view_name.Trim()
    If (String.IsNullOrEmpty(view_name)) Then Return IRhinoCommand.result.cancel


    Dim view_list As MRhinoView() = Nothing
    Dim view_count As Integer = context.m_doc.GetViewList(view_list)
    If (view_list Is Nothing) Then Return IRhinoCommand.result.failure


    Dim active_view As MRhinoView = Nothing
    For Each view As MRhinoView In view_list
      Dim s As String = view.MainViewport().Name()
      If (s.Equals(view_name, System.StringComparison.OrdinalIgnoreCase)) Then
        active_view = view
        Exit For
      End If
    Next


    If (active_view Is Nothing) Then
      RhUtil.RhinoApp().Print("Unable to find viewport named " + view_name + "\n")
      Return IRhinoCommand.result.nothing
    End If


    RhUtil.RhinoApp().SetActiveView(active_view)
    Dim wnd As System.Windows.Forms.IWin32Window = active_view.m_hWnd
    Dim parent_handle As IntPtr = GetParent(wnd.Handle)
    If (parent_handle <> IntPtr.Zero) Then
      ShowWindow(parent_handle, 3)
    End If
    Return IRhinoCommand.result.success
  End Function

C# (Rhino 4)

  [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
  public static extern IntPtr GetParent(IntPtr hWnd);


  [DllImport("user32.dll")]
  static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);


  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    MRhinoGetString gs = new MRhinoGetString();
    gs.SetCommandPrompt( "Name of viewport to maximize" );
    gs.GetString();
    if (gs.CommandResult() != IRhinoCommand.result.success)
      return gs.CommandResult();


    string view_name = gs.String();
    view_name = view_name.Trim();
    if (string.IsNullOrEmpty(view_name))
      return IRhinoCommand.result.cancel;


    MRhinoView[] view_list = null;
    int view_count = context.m_doc.GetViewList( ref view_list);
    if( view_list == null )
      return IRhinoCommand.result.failure;


    MRhinoView active_view = null;
    foreach (MRhinoView view in view_list)
    {
      string s = view.MainViewport().Name();
      if( s.Equals( view_name, System.StringComparison.OrdinalIgnoreCase))
      {
        active_view = view;
        break;
      }
    }


    if( active_view == null)
    {
      RhUtil.RhinoApp().Print( "Unable to find viewport named " + view_name + "\n" );
      return IRhinoCommand.result.nothing;
    }


    RhUtil.RhinoApp().SetActiveView( active_view );
    System.Windows.Forms.IWin32Window wnd = active_view.m_hWnd;
    IntPtr parent_handle = GetParent(wnd.Handle);
    if (parent_handle != null)
      ShowWindow(parent_handle, 3);


    return IRhinoCommand.result.success;
  }
rename · changes · history · subscriptions · lost and found · references · file upload