3 Replies Latest reply on Apr 1, 2009 2:03 PM by Jeff Drost

    remembering window size

    Jeff Drost
      I recently added a second monitor for using SW with both displays. I unchecked the "Maximize window on open" option so the files don't open across both screens. The window that opens now is only slightly smaller than a "maximized" window and is not a useful size spanning across both onf the monitors. I can resize the window to smaller than a single monitor to work more efficiently but SW does not save this size and always opens at near maximum.

      Is there a way to have SW remeber the window size like othe applications?
        • remembering window size
          Dale Dunn
          Not that I'm aware of.

          There may be another option that will at least help get things under control. If you are using an nVidia graphics card, you can turn on "desktop management" and some of the tools there will add window controls to allow you to maximize a window to one monitor, even if the application spans more than one monitor. It's been a while since I did this, so I can't remember specifically how to do it. It's probably different in different versions of the driver anyway.

          If you have ATI, I would think that something similar should be available.
          • remembering window size
            Josh Brady
            Jeff,
            I've used the macro below for years to throw windows back and forth between monitors when SW spans both monitors. Depending on your screen resolution, there are numbers in one line (as noted in the code) that you will need to modify so that the window size fits your monitors. You need two versions of this code with different numbers in that line, one to "throw" the window left and one to "throw" the window right. I have the two macros mapped to mouse buttons, so I can "page through" open windows very quickly, sort of like a book. The macro operates on the window under the cursor, but does not activate that window, so that if you're paging through different windows it skips the sometimes very time-consuming automatic rebuilds and stuff.

            Dim swApp As SldWorks.SldWorks
            Dim Part As SldWorks.ModelDoc2
            Dim boolstatus As Boolean
            Dim longstatus As Long, longwarnings As Long
            Dim FeatureData As Object
            Dim Feature As Object
            Dim Component As Object
            Dim MainHandle As Long
            Dim ActiveHandle As Long
            Dim ApiHandle As Long
            Dim ParentHandle As Long
            Dim ClassName As String


            Const TOPWINDOWCLASS As String = "MDIClient"


            Dim myPt As POINTAPI

            Private Type POINTAPI
            X As Long
            Y As Long
            End Type

            Private Declare Function GetCursorPos Lib "user32" (lpPoint As _
            POINTAPI) As Long

            Private Declare Function WindowFromPoint Lib "user32" _
            (ByVal Xpt As Long, ByVal Ypt As Long) As Long

            Private Declare Function GetClassName Lib "user32" Alias _
            "GetClassNameA" (ByVal hWnd As Long, ByVal lpClass _
            As String, ByVal nMaxCount As Long) As Long

            Private 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 uFlags As Long) As Boolean

            Private Declare Function GetParent Lib "user32" _
            (ByVal hWnd As Long) As Long




            Sub main()

            Set swApp = Application.SldWorks
            Set Part = swApp.ActiveDoc

            longstatus = GetCursorPos(myPt)

            ApiHandle = WindowFromPoint(myPt.X, myPt.Y)

            ClassName = String$(256, " ")
            longstatus = GetClassName(GetParent(ApiHandle), ClassName, 255)
            ClassName = Left$(ClassName, InStr(ClassName, _
            vbNullChar) - 1)
            Debug.Print ClassName
            Do While StrComp(ClassName, TOPWINDOWCLASS, vbTextCompare) <> 0
            ''''getting class name
            ApiHandle = GetParent(ApiHandle)
            ClassName = String$(256, " ")
            longstatus = GetClassName(GetParent(ApiHandle), ClassName, 255)
            If Len(Trim(ClassName)) = 0 Then
            Exit Sub
            End If
            ClassName = Left$(ClassName, InStr(ClassName, _
            vbNullChar) - 1)
            '''''end getting class name
            'Debug.Print ClassName
            Loop

            ''''************************************
            'Edit the numbers in the next line to change position.
            'First number is always 0, next is Left, Top, Width, Height, then always 16
            ''''*************************************
            boolstatus = SetWindowPos(ApiHandle, 0, -7, -8, 1625, 901, 16) 'For 2 monitors
            'boolstatus = SetWindowPos(ApiHandle, 0, -7, -8, (1625 / 2) - 7, 985, 16) 'for 1 monitor


            End Sub
              • remembering window size
                Jeff Drost
                Josh,

                thanks for the code, I have it working well with my resolution

                I did have some trouble with it. I saved it as a macro, assigned it to a button and a keyboard shorcut but I got no reaction from it.

                When I tried running the macro in the editor, I got an error

                Compile Error:
                Ambiguous name detected; swApp

                and the line Dim swApp As SldWorks.SldWorks is highlighted

                I just commented the line and it started working,

                thanks again