Solved

Automatically position the application window for Visio 2013

Posted on 2014-02-07
11
527 Views
Last Modified: 2014-02-12
I use Excel 2010 and Visio 2013.
Excel file (name: 'XL_driver') creates/ selects a type of Visio file (name: 'vis_slave'), via early binding, and xl vba procedures control all vis-slave vba procedures.

I wish the XL-diver application window to appear on screen above vis_slave application window, so the USER can conveniently use xl's ribbon buttons to work with vis_slave. Thus, when the USER drags xl_Driver about the screen, its vis_slave should follow.

First steps in xl_driver code show evidence of progress (#2), but ultimate failure (#3):

1. Application.top and Application.height give the correct top and height values for the xl_driver app window

2. Accessing the visio application object model from Excel:
  'early binding
    Set visioApp = New Visio.Application
  'VisioApp is legitimate: the following exits visio application
  If Not visioApp Is Nothing Then visioApp.Quit
  Set visioApp = Nothing

3. 'Now try to position visio app window below foot of xl app window
    Set visioApp.top = Application.top + Application.height << BUG

Bug: 'Object does not support this property or method.
Problem: I cant find a path through the object model from visio application to .top

How do I do this, please?

Kelvin4
0
Comment
Question by:Kelvin4
  • 6
  • 5
11 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39841506
Hi,

After point 2 I do not see an "End If"
visioApp is already Nothing when your bug appear

EDIT Maybe

visioApp.ActiveWindow.Top

Open in new window


Visio.Application  has no Top Property

Regards
0
 

Author Comment

by:Kelvin4
ID: 39841546
Rgonzo,
Thanks, my text was not quite clear.  To clarify:  #2 was an independent bit of evidence that 'visioApp' is a legitimate object in my code ( though I inadvertently omitted 'End If' from the copied snippet ).

I confirm that in my development code, visioApp was not preceded by  Set visioApp = Nothing. So visioApp had value, but '.Top' was incorrectly assigned as a property in:
Set visioApp.top = Application.top + Application.height

Unfortunately in your EDIT: 'Top' is not a child property of the 'ActiveWindow' object either.

Kelvin
0
 
LVL 49

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 80 total points
ID: 39841590
Hi,

in Visio you have the WindowHandle32  property

Private Declare Function MoveWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Public Sub Example() 
 
Dim vsoWindow As Visio.Window 
Dim lngWindowHandle32 As Long 

Set vsoWindow = ActiveWindow 
 
lngWindowHandle32 = vsoWindow.WindowHandle32 
 
lDone = MoveWindow(ByVal lngWindowHandle32, ByVal 0, ByVal 0, ByVal 1920, ByVal 1200, ByVal 1)
If lDone = False Then MsgBox "Failed" 
End Sub 

Open in new window

not tested
EDIT

to find the Application window you could loop them in Application.Windows and test for

Window.Type = visApplication ' 5
 
Regards
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39841627
Hi,


to find actual position pls try

Private Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As IntPtr, ByRef lpRect As RECT) As Integer


Private Structure RECT
    Public Left As Int32
    Public Top As Int32
    Public Right As Int32
    Public Bottom As Int32
End Structure


Dim visRect As RECT

lngWindowHandle32 = vsoWindow.WindowHandle32 
intResult = GetWindowRect(byVal lngWindowHandle32, visRect)

Open in new window

0
 

Author Comment

by:Kelvin4
ID: 39841705
Thanks, .... digesting!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Kelvin4
ID: 39841778
Hi, Rgonzo

I took up your text
<<<<      to find the Application window you could loop them in Application.Windows and test for Window.Type = visApplication ' 5     >>>>>

... and ran this sub  in a visio standard module:

Sub getDrawingWindow() ------------------------------------------------------------------
Dim win As Visio.Window

For Each win In Visio.Application.Windows
  Debug.Print "win.type = "; win.Type & "; win.subType = "; win.SubType & "; win.ID = "; win.ID
Next

'Debug.Print output was:  win.type = 1; win.subType = 128; win.ID =  8642

End Sub -------------------------------------------------------------------------------------------

win.type = 1 is the drawing window.
In this loop, I'm missing the Application window (win.type = 5)?

Can you advise, thanks
Kelvin
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39841794
Hi,

Somewhere I saw

Application.WindowHandle32

Could that be the solution?
0
 

Accepted Solution

by:
Kelvin4 earned 0 total points
ID: 39841817
Below, I copy some stuff where WindowHandle32 object is defined via the ActiveWindow object. My problem is to set the top level Application window as an object as the first step.
 
Lets see what other advice we get,
Regards
Kelvin

http://msdn.microsoft.com/en-us/library/office/ff768775.aspx:

Public Sub WindowHandle32_Example()
 
 Dim vsoWindow As Visio.Window
 Dim lngWindowHandle32 As Long
 
 'Get the active window.
 Set vsoWindow = ActiveWindow
 
 'Get the 32-bit handle of the active window.
 lngWindowHandle32 = vsoWindow.WindowHandle32
 
 'Verify that you got the handle.
 Debug.Print "The active window handle is"; lngWindowHandle32
 
End Sub
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39842117
Hi,

pls try
Set visioApp = New Visio.Application 
lngWindowHandle32 =  visioApp.WindowHandle32 

Open in new window


Regards
0
 

Assisted Solution

by:Kelvin4
Kelvin4 earned 0 total points
ID: 39842261
I'm afraid I do not know how to use your suggested start point (above).
I'm not certain it is so clear a start point, but if you can show it is, then I'd be delighted to pay you my points.

I believe a successful answer would provide a window object with window.type = 5.  
I do welcome a solution that demonstrates  that outcome.

thanks
0
 

Author Closing Comment

by:Kelvin4
ID: 39852819
This a new part of the Visio object model to me

My question had a typo in it, and some clarification was needed.
The Expert gave me one important piece of information:
for the Application window: Window.Type = visApplication  , and value = 5.
I'd like to suggest that could be worth 80 points.

From the above advice, I then made some minor progress, but got no solution to the question that was clearly stated in the Title and subsequent text.

I now know that the Application Window object is accessed via:
Application.Window, for example:
Application.Window.Caption = "Visio Professional"

However, Application.Window is READ ONLY source: http://msdn.microsoft.com/en-us/library/office/ff769161.aspx 
.. and so position properties like .top .left etc do not exist.

Thus a different method of positioning the visio application window is required (if it exists).

I now wish to close this question fairly and ask another to meet the original need.

I appreciate the Experts' interest and input, but I suggest this question beat us both?
I am open to comment.

Kelvin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever created a custom Visio stencil – a collection of your own unique master shapes – and then created a drawing by dragging masters onto the drawing page? Have you then made changes to the stencil master and wondered why the shapes on the …
Scott A. Helmers Partner, Harvard Computing Group Microsoft Visio MVP Background Microsoft has added more enhancements and new features to Visio 2010 than to any release since they purchased the Visio product line in 2000. In addition, the com…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now