How to place userForm1 neatly beside a Visio.shape at any level of screen zoom.

I need to interact with smart tags of individual visio.shapes to call MACRO, which will in turn:
 - capture the identity of that individual shape (eg as a shapeID, objName, or via a shapesheet value).
 - open userForm1, adjacent to that individual shape, at the current level of ZOOM for laptop and extension screen.
 - UserForm1 receives input data affecting visio.shape properties and output data to a bound Excel wkbk.

A model sub in Excel showed ZOOM level affected whether UserForm1 launched adjacent to the visio.shape. The model used an ActiveX button 'CmdButton1' as a model shape, which I used to call this sub to position userform1 close to CmdButton1. Different zoom levels required different values of crn (correction) in this sub:
Sub CmdButton1_Click()
        Dim crn As Double
        crn = 0.6
        UserForm1.left = Application.left + (Me.Shapes("CmdButton1").left * crn) + (UserForm1.Width / 2)
        UserForm1.top = Application.top + (Me.Shapes("CmdButton1").top * crn) + (UserForm1.Height / 2)
        UserForm1.Show
End Sub

For different zoom levels, the optimal value of crn was judged by trial and error so UserForm1 remained at a const posn from CmdButton1,  no matter the button was at the left or right hand side of the sheet, on the laptop screen or the extension screen. For zoom of 60%, and crn = 0.6; for zoom value 50% crn = 0.498; for zoom value 70% crn = 0.78.

2. I do not know how to automate the creation the correct crn value for the current value of ZOOM.

I am aware of API methods to convert mouse click coordinates to UserForm posn coordinates: http://ramblings.mcpher.com/Home/excelquirks/snippets/mouseposition, but is that the method of choice?
I also read "Understanding Screen Scaling Issues" https://msdn.microsoft.com/en-us/library/windows/desktop/ee671605(v=vs.85).aspx. but am uncertain of its relevance

3. Application.left & Application.top (see sub above) dont exist in Visio and I've not identified the equivalent Visio variable. In visio, how do I work around this to position UserForm1 next to CmdButton1?

[THE FALL-BACK is to abandon the UserForm in favour of a visio.shape, engineered to serve a similar purpose to userForm1. This WOULD simplify positioning  (via "PinX", "PinY" etc) , BUT it is a less attractive alternative to a userForm. It is harder to construct, has a more limited repertoir of ctls, and is a less convenient interface for the User.]
---------------------------------
Hopefully, this is all subject to a well-worked solution, which is unknown to me. Otherwise, I'd be glad of advice as to where I should compromise in design to enable a practicable solution.

Competency-wise, I'm familar with handling control events via VBA classes, but by contrast would need step-by-step recipes to work with AddOns!

Many thanks
Kelvin
Kelvin4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
A couple of suggestions:
-- take a look in the Visio SDK for the Window.GetViewRect Method. It returns the coordinates of the specified window.
-- for crn value, a simple technique is to use two arrays (or a 2D array) to hold the zoom levels and corresponding crn values. When you determine the current zoom, select the closest zoom level in array 1, and then lookup the corresponding crn value in array 2. It's not elegant, and you're limited to the list of experimental values you've gathered, but you can probably generate other values by extrapolating from what you know. (You could also use a dictionary instead of a pair of arrays.)
0
Kelvin4Author Commented:
Scott:
Many thanks for speedy help..

Window.GetViewRect Method did not work for me, and I'll try to find indications why.

Window.GetWindowRect Method returned coordinates of the Visio application window which enabled me to place UserForm1 on a specific corner of the visio window.

I want to develop a bit more before signing off..

But now other experts can know ... the problem is being solved.

Kelvin
0
Kelvin4Author Commented:
Hi Scott:

My problem with GetViewRec was resolved by better window identification:

For Each win In visioApp.Windows    
        Debug.Print "win.caption = "; win.Caption & "; win.type = "; win.Type
        win.GetViewRect pinLeft, pinTop, pinWidth, pinHeight
        Debug.Print "left = "; Round(pinLeft, 0), "t = "; Round(pinTop, 0), "w = "; Round(pinWidth, 0), "h = ";    
               Round(pinHeight, 0)
Next win

GetViewRect returned negative values for the 'left' value (Round(pinLeft, 0); dim as double).
To illustrate, here is a gif of four drawing views



Does the reference point for the Left value = the centre of the drawing? And ditto for top?

Units of measurement:
Am I right in thinking that if the drawing is scaled in points then the values returned from GetViewRect will be in points?

That's me done for this Q, thanks.

Kelvin
0
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
Thanks for posting work-in-progress results, Kelvin. I recall using GetViewRect a few years ago but don't recall enough details, or have time to experiment at the moment, to answer your specific questions. You might take a look a code sample in the Visio SDK that I just found: look for "Convert Visio Coordinates to Windows Coordinates". One thing it does say is:
'The conversion of
' the Y coordinate must also take into the account the different locations of
' the origin, since Visio's origin is at the lower-left corner and the Windows
' origin is at the upper-left corner.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kelvin4Author Commented:
More fast and effective support.
Just the encouragement I was hoping for
- many thanks.
Kelvin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Visio

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.