Hidden viewport using the window handle

Hello –

I have written a Grasshopper plugin that create, manages, and manipulates Rhino Viewports. I need viewports to be active so that I can capture screen content from them but have them hidden from view. One hacky way to do this is to create them with a screen rectangle that is very far from the screen coordinates, but it feels hacky and not right.

I have written a component to Hide/Show the window using the window handle, but unfortunately it doesn’t hide the window, only the contents of the window. The code is here:

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

    const int SW_HIDE = 0;
    const int SW_SHOW = 5;
    const int SW_MINIMIZE = 6;
    const int SW_RESTORE = 7;

protected override void SolveInstance(IGH_DataAccess DA)
{
IGH_Goo viewportGoo = null;
int width = 0;
int height = 0;
bool show = true;

        if (!DA.GetData(0, ref viewportGoo)) return;
        RhinoViewport viewport = null;
        viewportGoo.CastTo<RhinoViewport>(out viewport);
        if (viewport == null)
        {
            string vpString = "";
            DA.GetData(0, ref vpString);
            viewport = RhinoDoc.ActiveDoc.Views.FirstOrDefault(v => v.ActiveViewport.Name == vpString)?.ActiveViewport;
            if (viewport == null) { return; }
        }

        if (!DA.GetData(1, ref show)) return;

        RhinoView rv = viewport.ParentView as RhinoView;

        if (rv.Floating)
        {
            IntPtr hWnd = rv.Handle;
            int show_command = show ? SW_SHOW : SW_HIDE;
            ShowWindow(hWnd, show_command);

        }
    }

Questions:

  1. What type of window is the RhinoView window? WPF? Eto?
  2. How do I get the handle of the window itself? Right now the RhinoView handle seems to encapsulate only the content of the window, not the window itself. Am I going about this all wrong?

Thanks,
Marc
P.S. Working in Rhino 7 currently

On Windows, a Rhino view is a MFC View, one that inherits from CView.

The Rhino view is embedded in a CFrameWnd, also an MFC class. We don’t provide API access to this.

– Dale

Hi Dale!

Interesting. So… given my use case – wanting to hide/show or programmatically move a floating viewport in Windows screen coordinates – is there any way to accomplish this that you can think of? Any way to access the window handle through a back door way, perhaps on creation?

Hi @marcsyp,

You might try p/invoking GetParent and use that HWND.

– Dale