Error creating window handle

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joel Whitehouse

    #1

    Error creating window handle

    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.Compone ntModel.Win32Ex ception'
    occurred in system.windows. forms.dll
    Additional information: Error creating window handle.


    Dim frm As New modMastControll er.frmSubClass
    frm.ShowDialog( )


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


    Public Event UserMessage(ByV al 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.
    InitializeCompo nent()

    'Add any initialization after the InitializeCompo nent() 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.Disp ose()
    End If
    End If
    MyBase.Dispose( disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.Componen tModel.IContain er


    <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
    InitializeCompo nent()

    'frmMain
    '
    Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
    Me.ClientSize = New System.Drawing. Size(424, 253)
    Me.Name = "frmSubClas s"
    Me.Text = ""
    Me.ResumeLayout (False)

    End Sub

    #End Region

    Public Const WM_APP As System.Int32 = &H8000&

    #Region "Subclassin g Current Form Only"
    Protected Overrides Sub WndProc(ByRef m As Message)
    If (m.Msg > WM_APP) Then
    RaiseEvent UserMessage(m.M sg, m.WParam.ToInt3 2,
    m.LParam.ToInt3 2)
    End If
    End Sub
    #End Region
    End Class
    _______________ _______________ _______________ _______________ ______


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

    -Joel
  • Joel Whitehouse

    #2
    Re: Error creating window handle

    Joel Whitehouse wrote:
    [color=blue]
    > 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.Compone ntModel.Win32Ex ception'
    > occurred in system.windows. forms.dll
    > Additional information: Error creating window handle.
    >
    >
    > Dim frm As New modMastControll er.frmSubClass
    > frm.ShowDialog( )
    >
    >
    > Here's the Form Code:
    > _______________ _______________ _______________ _______________ _
    > Public Class frmSubClass
    > Inherits System.Windows. Forms.Form
    >
    >
    > Public Event UserMessage(ByV al 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.
    > InitializeCompo nent()
    >
    > 'Add any initialization after the InitializeCompo nent() 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.Disp ose()
    > End If
    > End If
    > MyBase.Dispose( disposing)
    > End Sub
    >
    > 'Required by the Windows Form Designer
    > Private components As System.Componen tModel.IContain er
    >
    >
    > <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
    > InitializeCompo nent()
    >
    > 'frmMain
    > '
    > Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
    > Me.ClientSize = New System.Drawing. Size(424, 253)
    > Me.Name = "frmSubClas s"
    > Me.Text = ""
    > Me.ResumeLayout (False)
    >
    > End Sub
    >
    > #End Region
    >
    > Public Const WM_APP As System.Int32 = &H8000&
    >
    > #Region "Subclassin g Current Form Only"
    > Protected Overrides Sub WndProc(ByRef m As Message)
    > If (m.Msg > WM_APP) Then
    > RaiseEvent UserMessage(m.M sg, m.WParam.ToInt3 2,
    > m.LParam.ToInt3 2)
    > End If
    > End Sub
    > #End Region
    > End Class
    > _______________ _______________ _______________ _______________ ______
    >
    >
    > I have no idea what I'm doing wrong. Any ideas? Thanks!
    >
    > -Joel[/color]

    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.M sg, m.WParam.ToInt3 2, m.LParam.ToInt3 2)
    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

    Comment

    Working...