Error creating window handle

  • Thread starter Joel Whitehouse
  • Start date
J

Joel Whitehouse

Hello All,

I'm haveing a problem instantiating a form. When I try to instantiate
my form and call it's ShowDialog() method, I get the following error
message:

An unhandled exception of type 'System.ComponentModel.Win32Exception'
occurred in system.windows.forms.dll
Additional information: Error creating window handle.


Dim frm As New modMastController.frmSubClass
frm.ShowDialog()


Here's the Form Code:
_____________________________________________________________
Public Class frmSubClass
Inherits System.Windows.Forms.Form


Public Event UserMessage(ByVal uMsg As System.Int32, ByVal
wParam As System.Int32, ByVal lParam As System.Int32)


#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer


<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(424, 253)
Me.Name = "frmSubClass"
Me.Text = ""
Me.ResumeLayout(False)

End Sub

#End Region

Public Const WM_APP As System.Int32 = &H8000&

#Region "Subclassing Current Form Only"
Protected Overrides Sub WndProc(ByRef m As Message)
If (m.Msg > WM_APP) Then
RaiseEvent UserMessage(m.Msg, m.WParam.ToInt32,
m.LParam.ToInt32)
End If
End Sub
#End Region
End Class
__________________________________________________________________


I have no idea what I'm doing wrong. Any ideas? Thanks!

-Joel
 
J

Joel Whitehouse

Joel said:
Hello All,

I'm haveing a problem instantiating a form. When I try to instantiate
my form and call it's ShowDialog() method, I get the following error
message:

An unhandled exception of type 'System.ComponentModel.Win32Exception'
occurred in system.windows.forms.dll
Additional information: Error creating window handle.


Dim frm As New modMastController.frmSubClass
frm.ShowDialog()


Here's the Form Code:
_____________________________________________________________
Public Class frmSubClass
Inherits System.Windows.Forms.Form


Public Event UserMessage(ByVal uMsg As System.Int32, ByVal
wParam As System.Int32, ByVal lParam As System.Int32)


#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer


<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(424, 253)
Me.Name = "frmSubClass"
Me.Text = ""
Me.ResumeLayout(False)

End Sub

#End Region

Public Const WM_APP As System.Int32 = &H8000&

#Region "Subclassing Current Form Only"
Protected Overrides Sub WndProc(ByRef m As Message)
If (m.Msg > WM_APP) Then
RaiseEvent UserMessage(m.Msg, m.WParam.ToInt32,
m.LParam.ToInt32)
End If
End Sub
#End Region
End Class
__________________________________________________________________


I have no idea what I'm doing wrong. Any ideas? Thanks!

-Joel

Hey guys, I found it! The key is to add this line to the end of the
Protected Overrides Sub WndProc(ByRef m As Message) function link this:


Protected Overrides Sub WndProc(ByRef m As Message)
If (m.Msg > WM_APP) Then
RaiseEvent UserMessage(m.Msg, m.WParam.ToInt32, m.LParam.ToInt32)
End If
MyBase.WndProc(m) '**************Essential line of code!
End Sub


So many people have had this problem and never posted the answer. I
hope google caches this a few times, for other people's sakes.

-Joel
 

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