Visual Studio 2010 Visio Com Add In: Add Form to Window in Visio

Started by DotFlyer, June 27, 2013, 07:20:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DotFlyer

Hi all,

I'm trying to add a window to Visio that contains a windows form.  I'm able to add the window, but only if I use certain VisTypes, mainly, the one's that end in 'Addon', and this makes sense.  But I can't add my form to that window.  Here's my code:


        frm2 = New Form2()

        vsoApp = GetObject(, "Visio.Application")
        windowstate = Visio.VisWindowStates.visWSVisible '+ Visio.VisWindowStates.visWSDockedBottom
        wintype = Visio.VisWinTypes.visDockedStencilAddon

        'progwindow = vsoApp.Windows.Add("Name", windowstate, wintype, 8, 10, 250, 250, 0, 0, 0)
        progwindow = vsoApp.Windows(1).Windows.Add("Name", windowstate, wintype, 8, 10, 250, 250, 0, 0, 0)
        progwindow.add(frm2)

        frm2.Parent = progwindow
        frm2.Show(progwindow)



I just happen to have the VisDockedStencilAddon as my VisType right now; I don't believe that's the one I want.  At any rate, you can see I tried progwindow.add to add the form, frm2.Parent to set the parent, and including progwindow in the call to show; none of this gets my form into the window I've created.

What's the right way to do this?

Thanks!

DotFlyer

Also, as a followup, I've seen the thread from 2009http://visguy.com/vgforum/index.php?topic=821.0 on these forums, which talks about using the code located in this msdn article on setting up an anchored window: http://msdn.microsoft.com/en-us/library/office/ff767674.aspx

The relevant code from the msdn article is in VBA however, here it is for reference:


Public Sub AddWindow_Example()

Dim vsoWindow As Visio.Window
Dim frmNewWindow As UserForm
Dim lngFormHandle As Long

'Add a new Anchor Bar window docked to the bottom of the Visio drawing window
Set vsoWindow = ActiveWindow.Windows.Add("My New Window", visWSVisible + visWSDockedBottom, visAnchorBarAddon, , , 300, 210)

'Create a new windows form
Set frmNewWindow = New frmMain

'Get the 32-bit handle of the new window.
lngFormHandle = FindWindow(vbNullString, "My New Window")

SetWindowLong lngFormHandle, GWL_STYLE, WS_CHILD Or WS_VISIBLE
SetParent lngFormHandle, vsoWindow.WindowHandle32

End Sub


And I've had no luck trying to translate the last line into something that works in VB (or, at least, achieves the desired result).  Furthermore, I'm not really setting up an anchor window I don't think, as I don't require (or want to require) a visio document to be open in which to anchor it; that said, using the vistype visAnchorAddon does produce a window, an odd looking window that isn't bound to anything, but does not display my form.

So I still haven't gotten this to work, although I do believe it to be possible, as I've seen other addons which open what definitely appears to be a custom form within the Visio application as a child window, that can be arranged, etc, just like a document would be.  I'm still unclear on what vistype to use for my window (or why), and haven't figured out how to get my form in there.

My reason for wanting to do things this way is I'd like a window that shows progress on iterating through a number of Visio documents, making modifications.  I originally just displayed my form normally, using .Show(), which worked, but the changes I'm making require me to use SendKeys to send keystrokes to a number of modal windows another Visio add-on pops up, and when my window is active, I am unable to reacquire focus to these modal popup windows, no matter what I do; spawn mine in a separate thread, grab the modal windows hwnds and try appactivate, setfocus using user32.dll functions, nothing seemed to work.  So my latest idea is to display it in a form in Visio as a kind of separate window, which I can then arrange so its all visible, and hopefully will not impact the focus of the modal popups.

If anyone has done this, I'd love to hear about it!  Thanks!

aledlund

I'd probably start with the v2010 sdk which has a working example of a vb.net anchor window form, and then work from there.
al