?
Solved

Automatically position the application window for Visio 2013

Posted on 2014-02-07
11
Medium Priority
?
542 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 52

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 52

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 160 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 52

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
 

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 52

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 52

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Periodically someone asks me whether there’s a way to automatically convert all of the pages in a Visio drawing to PowerPoint slides. There have even been a few times when I’ve wanted to do that myself but I never really had enough incentive to figu…
The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article we’ll examine containers. We’ll explore lists (http://www.experts-exchange.com/Microsoft/Applications/M…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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