RE: VB6 calling modal .net dialog
Hi Greg, Did you try the forms interop toolkit ? http://msdn.microsoft.com/en-us/vstudio/bb419144 Failing that, I would have tried the .NET UI as a user control ;) |-Original Message- |From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet- |boun...@ozdotnet.com] On Behalf Of Greg Keogh |Sent: Wednesday, 14 December 2011 4:55 PM |To: 'ozDotNet' |Subject: RE: VB6 calling modal .net dialog | |In VB6 the main window handle is actually a hidden window, so you'd |need to get the form's handle | |Good grief! I suppose that makes sense considering how VB6 windows behave. | |It would be quicker to re-write the pop up form in VB6, and add the |.net |database |layer logic as dll with a com wrapper, if there is one, or just |implement |some ado |in vb6 for the database stuff. Or we-write the vb6 stuff in .net :) | |My colleague has decided to write the picker UI in VB6 and all the data stuff will |be in a .NET DLL with an Interop wrapper. | |The lesson from this is that VB6-.NET Interop of library code is not too hard, but |doing so with Forms/dialogs is very hard to improbable. I haven't tried wrapping |.NET Controls as ActiveX for VB6 to consume, I almost did a few weeks ago and |then remembered all the registering of COM and the install footprint and I |abandoned the idea. | |Greg
RE: VB6 calling modal .net dialog
Did you try the forms interop toolkit ? http://msdn.microsoft.com/en-us/vstudio/bb419144 Hey now that's really interesting. The trouble is the web page doesn't explain how it works. I'll install the MSI and see if it has technical information on what it does. I'm wondering if it avoids COM registration. Failing that, I would have tried the .NET UI as a user control ;) Yes, we're not going to try and make VB6 call .NET Forms (separate windows). Our first option was to write everything but the UI in .NET, leaving only a thin shell of a UI in VB6. Now we have a second option ... if this Interop kits works well then we can perhaps easily reuse complete .NET controls in the VB6 app and slowly phase it out. Greg
RE: VB6 calling modal .net dialog
| |Did you try the forms interop toolkit ? |http://msdn.microsoft.com/en-us/vstudio/bb419144 | |Hey now that's really interesting. The trouble is the web page doesn't explain how |it works. I'll install the MSI and see if it has technical information on what it does. |I'm wondering if it avoids COM registration. | It provides templates and will generate COM wrappers as well. For VB6 you still need COM registration or write a SxS manifest for it (probably too painful to get the VB6 IDE to recognise the manifest though (never tried)) From .NET the SxS stuff should just work. |Failing that, I would have tried the .NET UI as a user control ;) | |Yes, we're not going to try and make VB6 call .NET Forms (separate windows). |Our first option was to write everything but the UI in .NET, leaving only a thin |shell of a UI in VB6. | |Now we have a second option ... if this Interop kits works well then we can |perhaps easily reuse complete .NET controls in the VB6 app and slowly phase it |out. | Good luck
VB6 calling modal .net dialog
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
RE: VB6 calling modal .net dialog
Why not just manually disable the parent form while the dialog is visible? That's pretty much all a modal dialog is really doing anyway. If that's not enough, the SetParent win32 api function may also help. Regards, Nathan Keir Systems Analyst John Deere Financial Limited A.C.N. 078 714 646 Australian Credit Licence Number 391484 Incorporated in Queensland, Australia 166-170 Magnesium Drive, Crestmead, QLD, Australia 4132 PO Box 1544, Browns Plains BC, QLD, Australia 4118 +61 7 3802 3274 (office) +61 7 3802 3142 (fax) keirnat...@johndeere.commailto:namey...@johndeere.com www.JohnDeere.com.auhttp://www.johndeere.com.au/ CONFIDENTIALITY. This message, including attachments, may be confidential. If you believe this message was sent to you in error, do not read it. If you are not the intended recipient, any retention, dissemination, distribution, or copying of this communication is strictly prohibited. Please reply to the sender that you have received the message in error and delete it. From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet-boun...@ozdotnet.com] On Behalf Of Greg Keogh Sent: Wednesday, 14 December 2011 9:57 AM To: 'ozDotNet' Subject: VB6 calling modal .net dialog 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
Re: VB6 calling modal .net dialog
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
RE: VB6 calling modal .net dialog
Matt, I tried something similar with an nunit test, like this: IntPtr hwnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; var win = new NativeWindow(); win.AssignHandle(hwnd); var picker = new MyPicker(); var result = picker.ShowDialog(win); I was hoping that this would set the nunit app window to be the owner of the ShowDialog, but sadly two things go wrong: (1) It's not modal, but that might be a quirk with using the nunit window (2) The dialog doesn't appear in the CenterParent position, it goes to screen top-left. Greg
Re: VB6 calling modal .net dialog
Sorry, I missed the NativeWindow bit. I have some other code for doing this (my scenario, native window, out of process) with WPF windows which is a little different and uses WindowInteropHelper and the SetWindowLong Win32 API function (because using just WindowInteropHelper doesn't give modal behaviour). I'm not sure why my code uses SetWindowLong instead of SetParent like Nathan suggested. On Wed, Dec 14, 2011 at 10:38 AM, Greg Keogh g...@mira.net wrote: Matt, I tried something similar with an nunit test, like this: ** ** IntPtr hwnd = System.Diagnostics.Process .GetCurrentProcess().MainWindowHandle; var win = new NativeWindow(); win.AssignHandle(hwnd); var picker = new MyPicker(); var result = picker.ShowDialog(win); ** ** I was hoping that this would set the nunit app window to be the owner of the ShowDialog, but sadly two things go wrong: (1) It’s not modal, but that might be a quirk with using the nunit window (2) The dialog doesn’t appear in the CenterParent position, it goes to screen top-left. ** ** Greg ** **
RE: VB6 calling modal .net dialog
In VB6 the main window handle is actually a hidden window, so you'd need to get the form's handle |-Original Message- |From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet- |boun...@ozdotnet.com] On Behalf Of Greg Keogh |Sent: Wednesday, 14 December 2011 11:39 AM |To: 'ozDotNet' |Subject: RE: VB6 calling modal .net dialog | |Matt, I tried something similar with an nunit test, like this: | | | |IntPtr hwnd = |System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; | |var win = new NativeWindow(); | |win.AssignHandle(hwnd); | |var picker = new MyPicker(); | |var result = picker.ShowDialog(win); | | | |I was hoping that this would set the nunit app window to be the owner of the |ShowDialog, but sadly two things go wrong: (1) It's not modal, but that might be |a quirk with using the nunit window (2) The dialog doesn't appear in the |CenterParent position, it goes to screen top-left. | | | |Greg | |
RE: VB6 calling modal .net dialog
It would be quicker to re-write the pop up form in VB6, and add the .net database layer logic as dll with a com wrapper, if there is one, or just implement some ado in vb6 for the database stuff. Or we-write the vb6 stuff in .net :) From: bill.mccarthy.li...@live.com.au To: ozdotnet@ozdotnet.com Subject: RE: VB6 calling modal .net dialog Date: Wed, 14 Dec 2011 13:49:33 +1100 In VB6 the main window handle is actually a hidden window, so you'd need to get the form's handle |-Original Message- |From: ozdotnet-boun...@ozdotnet.com [mailto:ozdotnet- |boun...@ozdotnet.com] On Behalf Of Greg Keogh |Sent: Wednesday, 14 December 2011 11:39 AM |To: 'ozDotNet' |Subject: RE: VB6 calling modal .net dialog | |Matt, I tried something similar with an nunit test, like this: | | | |IntPtr hwnd = |System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; | |var win = new NativeWindow(); | |win.AssignHandle(hwnd); | |var picker = new MyPicker(); | |var result = picker.ShowDialog(win); | | | |I was hoping that this would set the nunit app window to be the owner of the |ShowDialog, but sadly two things go wrong: (1) It's not modal, but that might be |a quirk with using the nunit window (2) The dialog doesn't appear in the |CenterParent position, it goes to screen top-left. | | | |Greg | |
RE: VB6 calling modal .net dialog
In VB6 the main window handle is actually a hidden window, so you'd need to get the form's handle Good grief! I suppose that makes sense considering how VB6 windows behave. It would be quicker to re-write the pop up form in VB6, and add the .net database layer logic as dll with a com wrapper, if there is one, or just implement some ado in vb6 for the database stuff. Or we-write the vb6 stuff in .net :) My colleague has decided to write the picker UI in VB6 and all the data stuff will be in a .NET DLL with an Interop wrapper. The lesson from this is that VB6-.NET Interop of library code is not too hard, but doing so with Forms/dialogs is very hard to improbable. I haven't tried wrapping .NET Controls as ActiveX for VB6 to consume, I almost did a few weeks ago and then remembered all the registering of COM and the install footprint and I abandoned the idea. Greg