Page 1 of 1

SW Addin - User Form Question

Posted: Mon Mar 27, 2023 4:28 pm
by ATANAS
Hi All,
I hope somebody will have the answer to that.

I am working on an vb.net SW add-in that will show a user form. I would like to find a way to show the form centered over Solidworks's window.
Currently I have the form's topmost property set to TRUE.
The problem is sometimes the form opens on the other screen or even when it is over the SW window I can interact with SolidWorks (not modal). I would like when calling ShowDialog() to pass the main SW window as an argument (make SW parent to this form) and cant find a way to get it.
Any suggestions?
Thank you,
Atanas

Re: SW Addin - User Form Question

Posted: Tue Mar 28, 2023 6:53 am
by JSculley
You can use P/Invoke to get the handle of the SOLIDWORKS window

Re: SW Addin - User Form Question

Posted: Tue Mar 28, 2023 10:06 am
by ATANAS
Thank you JSculley,
I am not sure if I followed exactly your proposal but it definitely pointed me in the right direction.

Here is what worked for me:

Dim hwnd As New IntPtr(iSwApp.IFrameObject.GetHWnd())
Dim swNativeWindow As New NativeWindow()

swNativeWindow.AssignHandle(hwnd)

MyFrom.ShowDialog(swNativeWindow)