Results 1 to 10 of 10

Thread: Error creating window handle

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    48

    Question Error creating window handle

    I'm having a problem with "Showing" one particular form.

    I have a dozen forms all are children of an MDI form.

    One particular form always fails on the first "Show" with the error "Error creating window handle", then the second time I load it, the "Show" succeeds.

    I'm first attaching all the forms to the MDI form

    Code:
            frmAdmin.MdiParent = Me
            frmAdmin.Dock = DockStyle.Fill
            frmAdmin.Hide()
    Then when the time comes to Show the form, I call a Subroutine to do the job:

    Code:
        Public Sub LoadFormAndRefresh(ByRef vForm As Form)
            Const C_PROC_NAME = "LoadFormAndRefresh"
            Try
                ' hide everything
                For Each oForm As Form In Me.MdiChildren
                    oForm.Hide()
                Next
                Me.Refresh()
                vForm.Show()                  <------------------- fails here
                Me.Refresh()
            Catch ex As Exception
                If modGlobals.gDebug Then Console.Write(CODE_MODULE, C_PROC_NAME & ": " & ex.Message)
                oERR.LogFileError(vModule:=CODE_MODULE,
                                  vRoutine:=C_PROC_NAME,
                                  vEX:=ex,
                                  vLogLevel:=clsLogFile.LoggingLevel.LogEverything)
                If modGlobals.gDebug Then Stop
            End Try
        End Sub
    The code steps through the frmAdmin_Load subroutine with no errors then fails when back in the MDI routine.

    Any ideas?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Error creating window handle

    Have a look at the StackTrace of the exception. It will tell you where the actual error occurs. Almost certainly it's in an event handler that is executed due to a property that you have set in the designer. For example, if you have set the Text of a TextBox then the TextChanged event will be raised and the event handler might assume that something has happened that hasn't at that stage.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    48

    Re: Error creating window handle

    These are the Exception details for the error
    Code:
    Exception Details: 
    	HResult: -2147467259
    	Message: Error creating window handle.
    	String: System.ComponentModel.Win32Exception (0x80004005): Error creating window handle.
       at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
       at System.Windows.Forms.Control.CreateHandle()
       at System.Windows.Forms.Form.CreateHandle()
       at System.Windows.Forms.Control.get_Handle()
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.Show()
       at WindowsApplication1.mdiMain.LoadFormAndRefresh(Form& vForm) in C:\Users\usr\Documents\Visual Studio 2012\Projects\WindowsApplication1\WindowsApplication1\mdiMain.vb:line 189
    	Source: System.Windows.Forms

  4. #4
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Error creating window handle

    are you using the default instance of the form?
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: Error creating window handle

    Oh man oh man. I think MDIs are glitched in .Net. You wouldn't believe the amount of weird and unexplainable problems like this I've come across when using them. It might be something you're doing wrong but my experience tells me its more than likely another glitch. You should try to find out what conditions cause the error(bet my left foot it'll be weird conditions too) and work around them.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Error creating window handle

    Hmmm... is there an InnerException?

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    48

    Re: Error creating window handle

    I couldn't find an InnerException, but the following (very dirty) bit of code works...

    Code:
            Try
                frmAdmin.Show()
            Catch ex As Exception
                frmAdmin.Show()
            End Try
    The first attempt always fails then the second attempt always seems to work.

  8. #8
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Error creating window handle

    Try creating a new instance (do that always)

    Code:
    Using newForm as New frmAdmin
        newForm.Show()
    End Using
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  9. #9

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    48

    Re: Error creating window handle

    That new form business just make things worse. Nothing was loaded, all the forms load then vanish leaving an empty MDI container. The way I had it was better, even with the dirty workaround.

  10. #10
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Error creating window handle

    ok, do without the Using -End Using, but do not use the default instance.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width