I'm using Autodesk Inventor Profesional 2026 with a VB.NET 4.8 project inside visual studio. The sourcecode is below and should make it clear what I am trying to do/create but is with a bit of copy paste from AI's because I was just trying to make stuff work when changing the HWND of the viewframe to the xaml window did not work.
After this I tried also making my program to be always on top but that still hides the inventor viewport/viewframe after this.
But basically I'm trying to make a preview window that I can control that will always be on top / docked to the side in inventor like my screenshot below

then while working on a assembly where I can show a changing highlightset of the part I'm copying based on the existing constraints while working in the assemblydocument to re-constraint a copy of the original based on the user input and constraints that were available on the original part. However currently after selecting anything in the assembly it puts that window on top (which is expected for any normal usecase) but I would love to be able to set that particular window to be on top within my code until I don't need it anymore.
This is to give more movability/freedom than to just create a screenshot of the part with the highlightset and display that, I prefer a seperate viewport so I can actually be able to move the part around when the highlightset is not created a clear view of what the user should try to re-constrain.
the WH_solutions.Fnc is used for the inventor connection but only has 2 references InvApp (which basically gets the running inventor application).
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Windows.Forms.Integration
Imports System.Windows.Interop
Imports Inventor
Imports WH_solutions.Fnc
Imports WH_solutions.MainWindow
Public Class TESTshit
'Old code
Private PreviewPanel As System.Windows.Forms.Panel
Private PreviewView As Inventor.View
Private XamlWindowHandle As IntPtr
Private UsedAssemblyDocument As Document
'latest gatgpt addition:
Private DockWindow As Inventor.DockableWindow
Private DockPanel As System.Windows.Forms.Panel
Private PreviewHost As System.Windows.Forms.Panel
'Private PreviewRootHandle As IntPtr
' <DllImport("user32.dll", SetLastError:=True)>
' Private Shared Function SetParent(
' hWndChild As IntPtr,
' hWndNewParent As IntPtr
') As IntPtr
' End Function
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function GetWindow(
hWnd As IntPtr,
uCmd As UInteger
) As IntPtr
End Function
Private Const GW_OWNER As UInteger = 4
' <DllImport("user32.dll", SetLastError:=True)>
' Private Shared Function SetWindowPos(
' hWnd As IntPtr,
' hWndInsertAfter As IntPtr,
' X As Integer,
' Y As Integer,
' cx As Integer,
' cy As Integer,
' uFlags As UInteger
') As Boolean
' End Function
<DllImport("user32.dll")>
Private Shared Function GetAncestor(
hWnd As IntPtr,
gaFlags As UInteger
) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="SetWindowLongPtrW", SetLastError:=True)>
Private Shared Function SetWindowLongPtr64(
hWnd As IntPtr,
nIndex As Integer,
dwNewLong As IntPtr
) As IntPtr
End Function
Private Const GA_ROOT As UInteger = 2
Private Const GWLP_HWNDPARENT As Integer = -8
Public Sub New(PreviewPanel As System.Windows.Forms.Panel, xamlWindowHandle As IntPtr)
Me.PreviewPanel = PreviewPanel
Me.XamlWindowHandle = xamlWindowHandle
End Sub
Public Sub Testing()
UsedAssemblyDocument = InvApp.ActiveDocument
'-----------------------------------------
' 1. Get the selected occurrence
'-----------------------------------------
Dim picked As Object =
InvApp.CommandManager.Pick(
Inventor.SelectionFilterEnum.kAssemblyOccurrenceFilter,
"Select the component to preview"
)
If picked Is Nothing Then Return
Dim occurrence As Inventor.ComponentOccurrence =
TryCast(picked, Inventor.ComponentOccurrence)
If occurrence Is Nothing Then Return
'Get the source document
Dim sourceDoc As Inventor.Document =
occurrence.Definition.Document
'ORIGINAL CODE WORKING________________________________________________
'Create another view of that document
PreviewView = sourceDoc.Views.Add
'Prepare the view
PreviewView.GoHome()
PreviewView.Fit()
'Move this view into its own ViewFrame
Dim viewFrame As Inventor.ViewFrame =
PreviewView.ViewTab.MoveToNewViewFrame(
100, 'Left
100, 'Top
400, 'Width
300 'Height
)
'Dim viewFrameHandle As IntPtr = New IntPtr(CLng(viewFrame.HWND)) 'uncommented
Dim previewHand As IntPtr = New IntPtr(CLng(PreviewView.HWND))
Dim previewRootHandle As IntPtr = GetAncestor(previewHand, GA_ROOT)
Dim originalOwner As IntPtr =
GetWindow(previewRootHandle, GW_OWNER)
' MsgBox(
' "Preview HWND: " & previewRootHandle.ToString() &
' vbCrLf &
' "Original Owner: " & originalOwner.ToString() &
' vbCrLf &
' "XAML HWND: " & XamlWindowHandle.ToString()
')
previewRootHandle = previewRootHandle
Dim result As IntPtr =
SetWindowLongPtr64(
previewRootHandle,
GWLP_HWNDPARENT,
XamlWindowHandle
)
Dim newOwner As IntPtr =
GetWindow(previewRootHandle, GW_OWNER)
' MsgBox(
' "New Owner: " & newOwner.ToString() &
' vbCrLf &
' "XAML HWND: " & XamlWindowHandle.ToString()
')
End Sub
Public Sub ClosePreview()
If PreviewView Is Nothing Then Return
Try
UsedAssemblyDocument.Activate()
PreviewView.Close()
Catch ex As Exception
MsgBox("Could not close preview: " & ex.Message)
End Try
PreviewView = Nothing
End Sub
End Class
@w_heuvelmanXKEG7 - this post has been edited due to Community Rules & Etiquette violation.