Quite some time ago I played around with porting a VB6 app to .NET.  It was
too large to do it all at once so I had to look at using .NET for new stuff
and using interop.  It was an internal app and so in the end it didn't have
enough time budgeted to do the work, but I seem to recall modal dialogs
being a rather large stumbling block (brick wall?).

If I understand your scenario correctly, there may be hope.  I have a .NET
app where I set the main form's owner to a window from another process
using a HWND.

The first step is to implement System.Windows.Forms.IWin32Window:

    public class Win32Window : IWin32Window
    {
        public Win32Window(IntPtr handle)
        {
            this.Handle = handle;
        }

        public IntPtr Handle { get; private set; }
    }

Then once you have your HWND in an IntPtr you could do something like:

            var owner = new Win32Window(hwnd);
            myForm.ShowDialog(owner);


Maybe this will work in your scenario.

On Wed, Dec 14, 2011 at 9:57 AM, Greg Keogh <g...@mira.net> wrote:

> Folks, I have a working .NET Form that runs fine as a modal dialog in
> managed apps, it’s used to pick an item from a list and it returns the
> Int32 Id of the selected item. Now I have to make this dialog available to
> VB6. I’ve done plenty of Interop before to wrap managed library methods as
> ComVisible, but this is the first time I’ve tried this with a Window.Forms
> class.****
>
> ** **
>
> I presume the VB6 caller can only pass me a HWND, so I ran a few
> experiments to see if I could convert a HWND from an NUnit test to an Owner
> of my dialog, but I can’t figure that out. I then tried HWND to
> NativeWindow to ShowDialog(owner) on the caller side, but it doesn’t run
> modal. It’s not looking good so far.****
>
> ** **
>
> I have a feeling I’m heading into a world of pain trying make the modal
> behaviour work with a VB6 caller. I can’t get any definitive advice from
> web searches so far, so I thought I’d ask first to see if anyone has been
> there before.****
>
> ** **
>
> Greg****
>

Reply via email to