TreeView creation throws ERROR_INVALID_HANDLE

I am getting ERROR_INVALID_HANDLE when I call CreateWindowEx.

The same code works fine when I call other controls.

The only difference between the code that creates a textbox (which works) and the code creating the treeview (which doesn't work) is addition of:
 
#include <CommCtrl.h> 


And the inclusion of:
 
INITCOMMONCONTROLSEX iccex;


and...
1
2
3
iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
iccex.dwICC = ICC_TREEVIEW_CLASSES;
InitCommonControlsEx(&iccex);


I then call CreateWindow passing WC_TREEVIEW

What am I missing?

Please show how exactly you call CreaterWindowEx and in what order. InitCommonControlsEx() must be called first.

Does this sample code works ?
http://msdn.microsoft.com/en-us/library/windows/desktop/hh298371%28v=vs.85%29.aspx
It's the same really, except I am passing NULL into g_hInst

Do I take it I now need this?
I passed the instance but it didn't make a difference...

Any ideas?

I can't paste the code because it's fragmented across many classes and files.

I can assure you I am passing the handle correctly. As I say, the same code works for textbox, statics, checkboxes, radiobuttons .... and more...
It draws the control as a box but it still throws an error?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

#include <windows.h>
#include <CommCtrl.h>
#include "wf.WinCtrl.h"

class winCtrlTreeView : public winCtrl {

public:

	INITCOMMONCONTROLSEX iccex;

	winCtrlTreeView() {
		winCtrl();
		ctrlType = WC_TREEVIEW;
		options = WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;

		iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
		iccex.dwICC = ICC_TREEVIEW_CLASSES;
		InitCommonControlsEx(&iccex);
	};

	~winCtrlTreeView() {
	};

	void AddItem() {
		TV_ITEM tvI;
		TV_INSERTSTRUCT tvIns;
		tvI.mask = TVIF_TEXT | TVIF_PARAM;
		tvI.pszText = L"TEST";
		tvI.cchTextMax = lstrlen(L"TEST");
		tvIns.item = tvI;
		tvIns.hInsertAfter = (HTREEITEM)TVI_ROOT;
		tvIns.hParent = (HTREEITEM)NULL;
		HTREEITEM hItem = (HTREEITEM)SendMessage(me,
													TVM_INSERTITEM,
													0,
													(LPARAM)(LPTV_INSERTSTRUCT)&tvIns);
	};
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
	int addCtrl(winCtrl * thecontrol) {
		winCtrl ** ctrlPointersTmp = new winCtrl * [ctrlCount + 1];

		for(basicLoop i = 0; i < ctrlCount; i++){
			ctrlPointersTmp[i] = ctrlPointers[i];
		};

		thecontrol->me = CreateWindowEx(0,
			thecontrol->ctrlType,
			thecontrol->caption,
			thecontrol->options,
			thecontrol->left,
			thecontrol->top,
			thecontrol->width,
			thecontrol->height,
			parent,
			(HMENU)ctrlCount,
			hInstance,
			NULL
			);

		wfGlobal::showLastError(TEXT("Control Creation"));

		ctrlPointersTmp[ctrlCount] = thecontrol;

		ctrlPointers = ctrlPointersTmp;
		ctrlCount++;

		return 0;
	};

Topic archived. No new replies allowed.