Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2005

Tip: Looking for answers? Try searching our database.

Displaying modeless VB6 form in a WinForms app

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WeBe - 20 Oct 2005 14:56 GMT
Hi,

We have a large application built with a PlugIn/SnapIn technology in VB6
today. We are now in the process of upgrading it to .NET 2.0. But of course
we cannot convert all SnapIns at once, some of them might exist for a long
time. So we need to use Interop...

However, when one of these SnapIns tries to display a modeless form in the
new .NET host application, the following exception is thrown:

"Non-modal forms cannot be displayed in this host application from an
ActiveX DLL, ActiveX Control, or Property Page"

All of our SnapIns use modeless forms to present data to the user, just like
Microsoft Outlook. It is just impossible to change that behavior to display
the forms a modal.

To me, this is a serious bug in .NET/VB8, and we really need this to be
fixed or worked around. I've read something about a Component Manager class
that is needed for a VB6 form to get access to the message loop. Can't a
.NET client supply this class via COM Interop?

As a note, the KB article
http://support.microsoft.com/default.aspx?scid=kb;EN-US;171978 states that
VB 5.0 and later applications support this. Isn't VB8.0 later?

regards,
Staffan
Ken Halter - 20 Oct 2005 19:36 GMT
> Hi,
>
[quoted text clipped - 16 lines]
> regards,
> Staffan

That article, as you've found, is pretty much worthless <g>. The code below
*will* fix the problem and C++ isn't the only client enviroment that
complains ;-) Basically, VB5/6 is the only enviroment that can show VB5/6
Modeless forms.... unless you use the API shown here.

Basically, replace all calls to FormName.Show with ShowWindow(FormName.hWnd,
SW_SHOW)
'=========================
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal
nCmdShow As Long) As Long
Private Const SW_SHOW = 5

Public Sub ShowForm()
  ' Exposed method uses API call
  Dim frm As New frmMyForm
  Call ShowWindow(frm.hWnd, SW_SHOW)
End Sub

'......or......
'=========================
Option Explicit

'Setup an enum to take advantage of intellisense.
Public Enum ShowWinStates
  SW_HIDE = 0
  SW_SHOWNORMAL = 1
  SW_NORMAL = 1
  SW_SHOWMINIMIZED = 2
  SW_SHOWMAXIMIZED = 3
  SW_MAXIMIZE = 3
  SW_SHOWNOACTIVATE = 4
  SW_SHOW = 5
  SW_MINIMIZE = 6
  SW_SHOWMINNOACTIVE = 7
  SW_SHOWNA = 8
  SW_RESTORE = 9
  SW_SHOWDEFAULT = 10
  SW_FORCEMINIMIZE = 11
  SW_MAX = 11
End Enum

Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal
nCmdShow As Long) As Long

'Add an hWnd param if you want this to go in a bas module (etc). As coded,
it only works with the current form (obviously <g>)
Public Sub ShowForm(State As ShowWinStates)
  Call ShowWindow(Me.hWnd, State)
End Sub
'======================

Signature

Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..

Ken Halter - 20 Oct 2005 20:14 GMT
> Hi,
>
> As a note, the KB article
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;171978 states that
> VB 5.0 and later applications support this. Isn't VB8.0 later?

Thought I'd mention one more detail since you seem to be confused about
versions.... VB6 is the final version of VB. Period. Some refer to it as VB
Classic, others as VB.Com, regardless, B#, VB#, VB.Net, VB2005, whatever you
want to call it is *not* a newer version of "VB" so very few KB articles you
find that specify VB5 or VB6 will do much good in B#

Anything.Net may share "some" syntax but I guarantee you, it's not VB. It
doesn't depend on the vb runtime for one thing, it depends on .Net. If it
were truly VB, you could open a VBP file and simply run. Just like
VB3/VB4/VB5 and VB6 could... that is, open any project from the previous
version and simply run (not counting the VBX to OCX transition). Of course,
new language features present in VB6 wouldn't work in VB5 or VB4 but that's
obviously a different situation.

Signature

Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.