System.ComponentModel.Win32Exception: Error creating window handle.

  • Thread starter Thread starter Tushar
  • Start date Start date
T

Tushar

Hi All,

I am using WinForm and .NET 2.2 framework in my application. My application
mainly uses Infragistics WinGrid. I am extending infragistics grid to
support some functionality by adding winform's toolstrip control (which
intern hosted in a User Control) on Grid Headers. The way I extend this grid
is by implementing Infragistic's IUIElementCreationFilter interface. This
interface provides two methods, AfterCreateChildElements and
BeforeCreateChildElements. The issue that I am facing is, when I load grid,
I am getting following error and it kills my application.

"System.ComponentModel.Win32Exception: Error creating window handle".

This error occurs only when I set BackColor property of my user control to
Transparent. If I do not set BackColor or set it to some color my
application just works fine. I checked the number of window handles and also
GDI Object count at the time this error is thrown. Window handle count is
around 500 and GDI Object count is around 125. Also this error does not
occur all the time. In my application I have several modules where I use
infragisitcs WinGrid which in tern calls same implementation of
IUIElementCreationFilter interface and the code work fine for other modules.

I am not able to figure out as to why this issue is occurring sometimes and
what is that causing it.

During my investigation I found that adding user control with BackColor =
Transparent into Grid's control collection invokes OnPaint event handler and
which intern calls AfterCreateChildElements method in recursive way.
AfterCreateChildElements method is called after an element's ChildElements
have been created. The child element's can be repositioned here and/or new
element's can be added.

The stack trace is given below:

System.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.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at Orion.Dashboards.DashboardPartControl.ShowAlert(Object sender,
AlertRaisedEventArgs e) in
C:\FRSDev\DevRoot\foundation61\Orion\Source\Common\Orion.Dashboards\Controls\DashboardPartControl.cs:line
1097
at Orion.Dashboards.DashboardPartControl.OnAlertRaised(Object sender,
AlertRaisedEventArgs e) in
C:\FRSDev\DevRoot\foundation61\Orion\Source\Common\Orion.Dashboards\Controls\DashboardPartControl.cs:line
986
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at Fusion.Windows.Forms.VirtualListGrid.RaiseAlert(Exception ex) in
C:\FRSDev\DevRoot\foundation61\Fusion\Source\Presentation\Fusion.Windows.Forms\Widgets\VirtualListGrid.cs:line
1024
at Fusion.Windows.Forms.VirtualListGrid.OnPaint(PaintEventArgs pe) in
C:\FRSDev\DevRoot\foundation61\Fusion\Source\Presentation\Fusion.Windows.Forms\Widgets\VirtualListGrid.cs:line
638
at System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgs
e, Rectangle rectangle, Region transparentRegion)
at System.Windows.Forms.Control.PaintBackground(PaintEventArgs e,
Rectangle rectangle, Color backColor, Point scrollOffset)
at System.Windows.Forms.Control.PaintBackground(PaintEventArgs e,
Rectangle rectangle)
at System.Windows.Forms.Control.OnPaintBackground(PaintEventArgs pevent)
at
System.Windows.Forms.ScrollableControl.OnPaintBackground(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmEraseBkgnd(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.UserControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32
dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32
x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef
hMenu, HandleRef hInst, Object pvParam)
at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32
dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32
x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef
hMenu, HandleRef hInst, Object pvParam)
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at
Fusion.Windows.Forms.FilteringCreationFilter.AfterCreateChildElements(UIElement
parent) in
C:\FRSDev\DevRoot\foundation61\Fusion\Source\Presentation\Fusion.Windows.Forms\Widgets\FilteringCreationFilter.cs:line
106
at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase
controlElement, Boolean recursive)
at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase
controlElement, Boolean recursive)
at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase
controlElement, Boolean recursive)
at
Infragistics.Win.UltraWinGrid.RowColRegionIntersectionUIElement.VerifyChildElements(ControlUIElementBase
controlElement, Boolean recursive)
at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase
controlElement, Boolean recursive)
at
Infragistics.Win.UltraWinGrid.DataAreaUIElement.VerifyChildElements(ControlUIElementBase
controlElement, Boolean recursive)
at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase
controlElement, Boolean recursive)
at
Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(ControlUIElementBase
controlElement, Boolean recursive)
at Infragistics.Win.UIElement.VerifyChildElements(Boolean recursive)
at Infragistics.Win.ControlUIElementBase.VerifyIfElementsChanged(Boolean
verify, Boolean syncMouseEntered)
at Infragistics.Win.ControlUIElementBase.get_CurrentCursor()
at Infragistics.Win.UltraControlBase.get_Cursor()
at System.Windows.Forms.Control.WmSetCursor(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
A first chance exception of type 'System.ComponentModel.Win32Exception'
occurred in System.Windows.Forms.dll
A first chance exception of type 'System.ComponentModel.Win32Exception'
occurred in System.Windows.Forms.dll
Error creating window handle.

Please let me know incase anyone has any clue or idea as to how to proceed
on resolving this issue.

Thanks in advance,

-Tushar
 
Hi Tushar,

Based on my understanding, you're using Infragistics WinGrid control in
your application and you add a UserControl to the column headers of the
WinGrid. The problem is that if you set the BackColor of the UserControl to
Transparent, you get an error.

I do some search and find a sample project that demonstrates how to embed
any control in WinGrid column headder using IUIElementCreationFilter. I
download it and see this sample embeds Panels in the WinGrid column
headers. I set the BackColor of the Panel to Transparent and run the
application and it works well.

You may get this sample from the following link:
http://blogs.infragistics.com/blogs/tom_puglisi/archive/2007/08/31/embed-any
-control-in-wingrid-col-header-using-iuielementcreationfilter.aspx

In addition, since the Infragistics controls are 3rd party products, if you
have any technical problems, you may submit an incident to Infragistics
Developer Support:
http://devcenter.infragistics.com/Protected/SubmitSupportIssue.Aspx

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Tushar,

How about the problem now?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top