SW Addin - User Form Question

Programming and macros
ATANAS
Posts: 4
Joined: Mon Mar 27, 2023 12:43 pm
Answers: 0

SW Addin - User Form Question

Unread post 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
by JSculley » Tue Mar 28, 2023 6:53 am
You can use P/Invoke to get the handle of the SOLIDWORKS window
Go to full post
User avatar
JSculley
Posts: 574
Joined: Tue May 04, 2021 7:28 am
Answers: 52
x 7
x 806

Re: SW Addin - User Form Question

Unread post by JSculley »

You can use P/Invoke to get the handle of the SOLIDWORKS window
ATANAS
Posts: 4
Joined: Mon Mar 27, 2023 12:43 pm
Answers: 0

Re: SW Addin - User Form Question

Unread post 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)
Post Reply