How can I programmatically get a handle to the Visio "Shapes" wind

H

HarryH

Does anyone know how can I programmatically get a handle to the Visio
"Shapes" window to capture window events and get screen coordinates?

It seems I am unable to get a handle and resize events for the Visio
"Shapes" stencil window.

I have written an application in C# using Visio controls and I am looking to
have peristent subwindow locations between sessions, but I need to locate
access to the "Shapes" window to get and save the dimensions of this window
in my application.

Thanks.
 
J

JuneTheSecond

Coul I ask you what would you mean by "Shapes" window?
Is it a stencil window of active drawing window?
Or any other window?
 
H

HarryH

I believe I am referring to the Stencil window of the Active Drawing window.

For further clarification, I have turned the display of the search mechanism
to this control off by doing the the following:
get_ItemFromID
(Microsoft.Office.Interop.Visio.VisWinTypes.visWinIDShapeSearch).Visible =
false;

Now I want to track user modifications to the shape and location of this
window so that I can position the window correctly as the user expects when
the application is restarted.

Thanks.
 
J

JuneTheSecond

For simplicity I would like to show a VBA macro that includes the window
handle of the stencil window.
Sub test()
Dim win As Visio.Window
For Each win In ActiveWindow.Windows
Debug.Print win.Caption, win.WindowHandle32, win.ID
Next
End Sub
 
J

JuneTheSecond

Additional.
This macro show the handle of stencilwindow, just when the stencil window is
opened.
 
H

HarryH

Wow... thanks.

I see now that "Shapes" is part of a collection of windows, and I should be
able to get the window handle and set up an event for this window to notify
me when the position of the window is changed.

I will give that a try now!

Thanks.
 
H

HarryH

I thought that by having the window handle I should be able to register an
event handler to get a WindowChanged event for the "Shapes" window, but I am
finding that while I can register a WidowChanged event for the "Shapes"
window - that a resized "Shapes" window does not cause the event to be fired
and captured by my handler.

Any suggestions please?
 
N

Nikolay Belyh

I thought that by having the window handle I should be able to register an
event handler to get a WindowChanged event for the "Shapes" window, but I am
finding that while I can register a WidowChanged event for the "Shapes"
window - that a resized "Shapes" window does not cause the event to be fired
and captured by my handler.

Any suggestions please?

What for do you need the resize event for the stencil window?
Quite an odd thing to do, anyways.

In principle, you can obtain an underlaying window handle using
window.WindowHandle32 property of the stencil window. This will return
the "native" windows HWND for the stencil window. Then you can try to
subclass this stencil window, and monitor WM_SIZE message for it.

But beware: the "yellow bricks road" ends here :)

Kind regards, Nikolay.
 
H

HarryH

Thanks Nikolay.

"> What for do you need the resize event for the stencil window?"

Actually the user is free to move the "Shapes" window freely within an
application with Visio controls and I am trying to retain persistence for the
"Shapes" window location to the last known location within the application.

How else would one retain persistence of the "Shapes" stencil window?
Is there some setting for the controls I need to intialize to retain
position persistence?

The Visio application itself does retain the last position for "Shapes".

You are suggesting that I:
"> can obtain an underlaying window handle using window.WindowHandle32
property of the stencil window. This will return the "native" windows HWND
for the stencil window. Then you can try to subclass this stencil window,
and monitor WM_SIZE message for it."

I will give this a try - thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top