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.Form sSystem.Co mponentMod el.Win32Ex ception: Error creating window handle.
at System.Windows.Forms.Nativ eWindow.Cr eateHandle (CreatePar ams cp)
at System.Windows.Forms.Contr ol.CreateH andle()
at System.Windows.Forms.Contr ol.get_Han dle()
at System.Windows.Forms.Contr ol.CreateG raphicsInt ernal()
at System.Windows.Forms.Threa dException Dialog..ct or(Excepti on t)
at System.Windows.Forms.Threa dException Dialog..ct or(Excepti on t)
at System.Windows.Forms.Threa dContext.O nThreadExc eption(Exc eption t)
at System.Windows.Forms.Contr ol.WndProc Exception( Exception e)
at System.Windows.Forms.Contr olNativeWi ndow.OnThr eadExcepti on(Excepti on e)
at System.Windows.Forms.Nativ eWindow.Ca llback(Int Ptr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeN ativeMetho ds.ShowWin dow(Handle Ref hWnd, Int32 nCmdShow)
at System.Windows.Forms.Contr ol.SetVisi bleCore(Bo olean value)
at System.Windows.Forms.Form. SetVisible Core(Boole an value)
at System.Windows.Forms.Contr ol.set_Vis ible(Boole an value)
at System.Windows.Forms.Form. ShowDialog (IWin32Win dow owner)
at System.Windows.Forms.Form. ShowDialog ()
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.Form
at System.Windows.Forms.Nativ
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Threa
at System.Windows.Forms.Threa
at System.Windows.Forms.Threa
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Nativ
at System.Windows.Forms.SafeN
at System.Windows.Forms.Contr
at System.Windows.Forms.Form.
at System.Windows.Forms.Contr
at System.Windows.Forms.Form.
at System.Windows.Forms.Form.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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
- 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
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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,
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
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(hhkLowLevel Mouse, _
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(Syste m.Reflecti on.Assembl y.GetExecu tingAssemb ly.GetModu les()(0)). ToInt32, _
0)
End Sub
Public Sub Enable()
'Release MouseTrap
UnhookWindowsHookEx(hhkLow LevelMouse )
End Sub
#End Region
End Class ' Class MouseTrap
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(hhkLowLevel
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_
AddressOf LowLevelMouseProc, _
Marshal.GetHINSTANCE(Syste
0)
End Sub
Public Sub Enable()
'Release MouseTrap
UnhookWindowsHookEx(hhkLow
End Sub
#End Region
End Class ' Class MouseTrap
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