SOLIDWORS PDM API TIP: What is Hwnd?


Hwnd appears in many PDM API calls as a parameter and is unfortunately not well-defined in the SOLIDWORKS PDM API documentation. 


Hwnd: Handle of window: a unique identifier in Win32.

It identifies a window in File Explorer and is not persistent across different sessions of File Explorer (explorer.exe). This means that the window handle may change for the window. 
In the context of the SOLIDWORKS PDM API, the window handle is especially important because it allows: 

  • The blue login dialog box is to be shown atop the host application window. If you specify zero in the LoginAuto method, the login dialog box may NOT be rendered in the right area of your screen causing the user to be confused. The host application’s control will be given away to the login box which is not visible to the user. A common consequence is the host application window flashing and not responding to the user input.
  • A similar behavior may concur as well for API calls such as the check in API call. The check in API call may trigger some PDM dialog boxes to render in the wrong area of the screen if Hwnd is not specified.

💡HOW TO GET THE WINDOW HANDLE IN .NET:

In WinForms, use to get the handle of the form.

In a Console app, use Process.GetCurrentProcess().MainWindowHandle.ToInt32()

In a WPF app, use new WindowInteropHelper(this).Handle.ToInt32() to get the handle of the active window.

Leave a Comment