vba userform application.width

So I'm updating a macro that broke when IT updated my computer to Windows 10.  I'm trying to add some additional functionality while I'm updating the macro anyway.  I have a userform that I have set to modeless and am trying to move the userform to the right edge of the screen.  I have done this in excel with the call:

    me.Left = Application.Width - me.Width

However Solidworks informs me that:

So what is the equivalent Solidowrks version of the call.

Thanks in advance for any assistance you are able to provide.

SolidworksApi/macros
Answers 6
JB
AM
AM 2021-04-08

It's nowhere near as elegant as ‌'s code but this is what I have reduced the code to.

modelWindows = swFrame.modelWindows
Set swModelWindow = modelWindows(0)
' 'Get and print the model window handle
hWnd = swModelWindow.hWnd
Debug.Print (" Model window handle: " & hWnd)


GetWindowRect hWnd, swRect
Debug.Print "Desk:", DeskWidth, DeskHt
Debug.Print , "LEFT", "RIGHT", "TOP", "BOTT"
Debug.Print "SW Window:", swRect.Left, swRect.Right, swRect.Top, swRect.Bottom

AM
AM 2021-04-08

I should clarify, I have realized that if I use an OVERSIZE = 8 and have (swRect.Right - OVERSIZE) * .75 I get really close to my value from when I manually position the form.  My question is why? I can't figure out why I have a 3/4 ratio from form to pixels.

AM
AM 2021-04-08

Alright ‌ I took your code and..... well it wasn't pretty.

What I've got now is this abbreviated piece of code:

'First, get the entire desktop size.
DeskWidth = GetSystemMetrics32(DT_WID)
DeskHt = GetSystemMetrics32(DT_HT)

'Now get the rectangle for the SW child window area.
modelWindows = swFrame.modelWindows
For Each obj In modelWindows
Set swModelWindow = obj
'Get the model document in this model window
Set swModel = swModelWindow.ModelDoc
'Show the model window
swFrame.ShowModelWindow swModelWindow
'Get and print the model window handle
hWnd = swModelWindow.hWnd
Debug.Print (" Model window handle: " & hWnd)
Exit For
Next obj
'DocWindow = WindowUnderMouse
'It's the parent of the window under the mouse found below.
'GetWindowRect GetParent(DocWindow), swRect
GetWindowRect hWnd, swRect
Debug.Print "Desk:", DeskWidth, DeskHt
Debug.Print , "LEFT", "RIGHT", "TOP", "BOTT"
Debug.Print "SW Window:", swRect.Left, swRect.Right, swRect.Top, swRect.Bottom

The problem I have now is trying to understand the Form.Left value I see and how I'm supposed to evaluate to get to it.

swrect.right = 1928

form.width = 282

but when I manually align the form to the right edge of my left screen the value of form.left =1162

or when the form is at center form.left = 579

....I'm confused.

JB
JB 2021-04-08

That gets a little more complicated. 

This thread contains code and explanation for how to get all the info you want about SW document windows:

 

AM
AM 2021-04-08

Thanks ‌.  This was what I needed to find.  Now to figure out how to figure out dual screens....