Link to home
Start Free TrialLog in
Avatar of delphikit
delphikit

asked on

vb.net Error creating window handle

Hi All expert,
I have no ideal why and when this error happen every day. I cannot similate the error. Do your have any ideal?

Error creating window handle.System.Windows.FormsSystem.ComponentModel.Win32Exception: Error creating window handle.
   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Control.get_Handle()
   at System.Windows.Forms.Control.CreateGraphicsInternal()
   at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
   at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
   at System.Windows.Forms.ThreadContext.OnThreadException(Exception t)
   at System.Windows.Forms.Control.WndProcException(Exception e)
   at System.Windows.Forms.ControlNativeWindow.OnThreadException(Exception e)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at System.Windows.Forms.Form.ShowDialog()
Avatar of NeoEGM
NeoEGM
Flag of Argentina image

It's probably because a lack of memory... Try to cleanup as much as you can of what you allocate...

Take a look at this:
http://www.google.com/search?q=cache:wCsVCwJJajMJ:thedotnet.com/howto/work245730.aspx+%22Error+creating+window+handle%22+VB.NET&hl=es&gl=ar&ct=clnk&cd=9

Regards,
NeoEGM
ASKER CERTIFIED SOLUTION
Avatar of Eduard Ghergu
Eduard Ghergu
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of delphikit
delphikit

ASKER

Dear NeoEGM,

It could be this reason. Anywhere I will try it 1st. But i notice that the memory Usage always go between 40k to 60k. Is there any where to cut it down?
A way to know more about your process is by going to Windows Task Manager->"Processes" tab->"View" menu->Select columns->Check:

- USER objects
- Handle Count
- Thread Count
- GDI Objects

You should try to keep them as low as possible...

Don't worry so much about the memory usage of the .NET Framework... VB.NET uses to allocate lots of memory and it isn't always a problem... you should reduce the amount of handles/objects in use; it's the best place to start from...

Regards,
NeoEGM
Dear NeoEGM,

Thank you again for your reply. I had tested few transaction in my application and this is the result i get from the Windows Task Manager.
 USER objects = 307
 Handle Count =485
 Thread Count =11
 GDI Objects =679

It is normal?.. What is the limit for thoese usage?

Thanks

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Jobrienct,

How to position the cursor offscreen and how to lock the cursor using windows API?
Can you send me the code how to do that?

Thanks,
sure, sounds a bit OT for your Q but ...

Dim iWidth As Integer = 720
Dim iHeght As Integer = 480
Cursor.Position = PointToScreen(New Point(iWidth + 10, iHeight + 10))

will position your cursor off and to the bottom right of your screen. I use an API to set the screen resolution when the prgram starts.

more later
In declarations add:

Friend Mouse As New MouseTrap

Then use the following class to disable...

Mouse.Dsable()

or enable...

Mouse.Enable()

your mouse - which either allows or disallows mouse movements while your application has the focus.

Public Class MouseTrap

#Region "Declarations - Constants"

    Private Const HC_ACTION As Integer = 0
    Private Const WH_MOUSE_LL As Integer = 14
    Private Const WM_MOUSEMOVE As Integer = &H200
    Private Const WM_LBUTTONDOWN As Integer = &H201
    Private Const WM_LBUTTONUP As Integer = &H202
    Private Const WM_LBUTTONDBLCLK As Integer = &H203
    Private Const WM_RBUTTONDOWN As Integer = &H204
    Private Const WM_RBUTTONUP As Integer = &H205
    Private Const WM_RBUTTONDBLCLK As Integer = &H206
    Private Const WM_MBUTTONDOWN As Integer = &H207
    Private Const WM_MBUTTONUP As Integer = &H208
    Private Const WM_MBUTTONDBLCLK As Integer = &H209
    Private Const WM_MOUSEWHEEL As Integer = &H20A

#End Region

#Region "Declarations - Structures"

    Private Structure POINT

        Private x As Integer
        Private y As Integer

    End Structure

    Private Structure MSLLHOOKSTRUCT

        Private pt As POINT
        Private mouseData As Integer
        Private flags As Integer
        Private time As Integer
        Private dwExtraInfo As Integer

    End Structure

#End Region

#Region "Declarations - Win32 API's"

    Private Declare Function SetWindowsHookEx Lib "user32" _
        Alias "SetWindowsHookExA" ( _
        ByVal idHook As Integer, _
        ByVal lpfn As LowLevelMouseProcDelegate, _
        ByVal hmod As Integer, _
        ByVal dwThreadId As Integer) As Integer

    Private Declare Function CallNextHookEx Lib "user32" ( _
        ByVal hHook As Integer, _
        ByVal nCode As Integer, _
        ByVal wParam As Integer, _
        ByVal lParam As MSLLHOOKSTRUCT) As Integer

    Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
        ByVal hHook As Integer) As Integer

#End Region

    Private hhkLowLevelMouse As Integer

#Region "Declarations - Functions"

    Private Function LowLevelMouseProc( _
        ByVal nCode As Integer, _
        ByVal wParam As Integer, _
        ByVal lParam As MSLLHOOKSTRUCT) As Integer

        If (nCode = HC_ACTION) Then

            If wParam = WM_MOUSEMOVE Or _
                wParam = WM_LBUTTONDOWN Or _
                wParam = WM_LBUTTONUP Or _
                wParam = WM_LBUTTONDBLCLK Or _
                wParam = WM_RBUTTONDOWN Or _
                wParam = WM_RBUTTONUP Or _
                wParam = WM_RBUTTONDBLCLK Or _
                wParam = WM_MBUTTONDOWN Or _
                wParam = WM_MBUTTONUP Or _
                wParam = WM_MBUTTONDBLCLK Or _
                wParam = WM_MOUSEWHEEL Then

                Return 1

            End If

            Return CallNextHookEx(hhkLowLevelMouse, _
                nCode, wParam, lParam)

        End If

    End Function

    Private Delegate Function LowLevelMouseProcDelegate( _
        ByVal nCode As Integer, _
        ByVal wParam As Integer, _
        ByVal lParam As MSLLHOOKSTRUCT) As Integer

#End Region

#Region "Declarations - Mouse Public Class Methods"

    Public Sub Disable()

        'Set MouseTrap
        hhkLowLevelMouse = SetWindowsHookEx(WH_MOUSE_LL, _
            AddressOf LowLevelMouseProc, _
            Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, _
            0)

    End Sub

    Public Sub Enable()

        'Release MouseTrap
        UnhookWindowsHookEx(hhkLowLevelMouse)

    End Sub

#End Region

End Class ' Class MouseTrap