AnsweredAssumed Answered

SW 2010 API Userform Hiding Behind Windows

Question asked by Gregory Sharp on Jan 14, 2013
Latest reply on Jan 15, 2013 by Gregory Sharp

Hi, I'm running SW 2013 64-bit , and despite being new to API in Solidworks. I've managed to put together a macro that works pretty well, although I'm sure it's a hack job in terms of proper code. Now I'm trying to run it in SW 2010 64-bit, and I get a problem with the userform window hiding behind the other windows when I initiate macro with a button. I've tried the following solution form angelsix but without results:



       Declare Function SetWindowPos Lib "user32" _

       (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _

       ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongB


       Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _

          (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


       Dim res As Long

       Dim lRet As Long



Global Const SWP_NOMOVE As Long = 2

Global Const SWP_NOSIZE As Long = 1


Global Const HWND_TOPMOST As Long = -1

Global Const HWND_NOTOPMOST As Long = -2


Sub main()


Set swApp = _



Set Part = swApp.ActiveDoc

Set modeldoc2 = swApp.ActiveDoc


If modeldoc2 Is Nothing Then                                ' Is doc loaded

    MsgBox "Please Open a Part or Assembly.", vbOKOnly, "Error", False, False                                ' Nothing - Warn user


  Exit Sub


  Else                                                        ' Else check doc loaded


    filetyp = modeldoc2.GetType  

    If filetyp = swDocPART Or filetyp = swDocASSEMBLY Then


'Center part on screen


Part.ShowNamedView2 "*Front", 1



' show form


SelectNamedView.Show (False)


lRet = FindWindow(vbNullString, SelectNamedView.Caption)

res = SetWindowPos(lRet, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)




This works when I run the debugger, but doesn't seem to bring the userform window forward with the button initiated macro. Any Suggestions? Thanks