0

Error in creating windows handle

"Error Creating Window Handle"

The general consensus found in most of these threads is that my application isn't disposing of various controls properly. However, that's not the case for me.

enter image description here

As far as I know, none of those values seem out of the ordinary. Also, I get this error when I try to load a form. It consists of a DotNetBar AdvTree with ~28 nodes. 26 of them have 2 cells, and the second cell has a hosted control using a DotNetBar TextBoxX. If I load any fewer number of nodes, the error goes away.

Am I missing something? I'm fairly certain that disposing objects isn't the issue as I encounter this problem when I load the form.

Here is the stack trace:

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.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.ControlCollection.Add(Control value)
   at DevComponents.AdvTree.AdvTree.Ú›()
   at DevComponents.AdvTree.AdvTree.Ú“(Rectangle Ú‘, Rectangle Ú’)
   at DevComponents.AdvTree.AdvTree.Ú()
   at DevComponents.AdvTree.AdvTree.RecalcLayout()
   at DevComponents.AdvTree.Node.OnDisplayChanged()
   at DevComponents.AdvTree.Cell.OnSizeChanged()
   at DevComponents.AdvTree.Cell.HostedControlSizedChanged(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
   at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
   at System.Windows.Forms.Control.UpdateBounds()
   at System.Windows.Forms.Control.WmCreate(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
   at System.Windows.Forms.TextBox.WndProc(Message& m)
   at DevComponents.DotNetBar.Controls.TextBoxX.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)

Answer:

With the custom controls, there is a Hosted Control property. The order of objects I was creating happened like this:

  1. Create a node
  2. Create a cell
  3. Create the hosted control
  4. Set the cell's hosted control property to the control in step 3.
  5. Add the cell to the node.Cells collection
  6. Add the node to the tree.

Since in step 4, the cell didn't have a parent, it was essentially just there. My speculation is that neither the hosted control nor the cell had a parent, so it couldn't properly locate these controls. Either way, I needed to set the parent of the hosted control to the form. This seemed to fix my problem:

Hosted Control ctrl.Parent = this;

Community
  • 1
  • 1
boiledham
  • 147
  • 8
  • 3
    Boiledhan, it would behoove you to post some code so someone can help you – MethodMan Feb 14 '13 at 17:15
  • Done. I don't know if it will make a difference but I pasted how I call the form – boiledham Feb 14 '13 at 17:21
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Feb 14 '13 at 17:22
  • Ah thank you, I was getting the error that the title already existed, so I tried to make it more specific. – boiledham Feb 14 '13 at 17:24
  • boiedham I can't tell looking at your code where you are even setting and or checking for `title` can you post all code that pertains to your question at hand..? – MethodMan Feb 14 '13 at 17:29
  • I'm not sure I get what you mean by checking for `title`. When I assign properties, I'm just assigning a list of items via `form.ListOfItemsToAdd = listOfItems;` – boiledham Feb 14 '13 at 17:41
  • With the custom controls, there is a Hosted Control property. I needed to set the parent of the hosted control to the form. This seemed to fix my problem: `Hosted Control ctrl.Parent = this;` – boiledham Feb 14 '13 at 17:57
  • @boiledham: expound on your solution and you can provide that as an answer to your own question. – IAbstract Feb 14 '13 at 18:57

1 Answers1

0

With the custom controls, there is a Hosted Control property. The order of objects I was creating happened like this:

1. Create a node
2. Create a cell
3. Create the hosted control
4. Set the cell's hosted control property to the control in step 3.
5. Add the cell to the node.Cells collection
6. Add the node to the tree.

Since in step 4, the cell didn't have a parent, it was essentially just there. My speculation is that neither the hosted control nor the cell had a parent, so it couldn't properly locate these controls. Either way, I needed to set the parent of the hosted control to the form. This seemed to fix my problem:

Hosted Control ctrl.Parent = this;

boiledham
  • 147
  • 8