i created a class that encapsulated a superclassed tree view control. however, i can only use the class once in my program. i have added a check so that it doesn't try to Register the class again, and the error occurs during CreateWindowEx. here is the class:
Code:
class cTree
{
private:
protected:
public:
cTree(HWND parent=NULL);
~cTree();
static LRESULT CALLBACK cTreeProcA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
virtual LRESULT CALLBACK cTreeProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
HWND Create(HWND parent,HINSTANCE hInstance);
HTREEITEM Add(char *chText);
HTREEITEM Add(char *chText,HTREEITEM parent);
//HTREEITEM Add(char *chText,HTREEITEM parent,HTREEITEM insAfter);
HWND hTree;
HWND hParent;
WNDPROC wpPrev;
HINSTANCE hInst;
HIMAGELIST hList;
int left,top,width,height;
static BOOL classReg;
};
HWND cTree::Create(HWND parent,HINSTANCE hInstance)
{
WNDCLASSEX wcx;
hInst=hInstance;
hParent=parent;
if (classReg!=1)
{
GetClassInfoEx(NULL,WC_TREEVIEW,&wcx);
wpPrev=wcx.lpfnWndProc;
wcx.lpfnWndProc=(WNDPROC)cTreeProcA;
wcx.hInstance=hInst;
wcx.lpszClassName="cTree";
wcx.cbSize=sizeof(wcx);
if (!RegisterClassEx(&wcx))
return NULL;
}
classReg=1;
hTree=CreateWindowEx(WS_EX_CLIENTEDGE,"cTree",NULL,
WS_BORDER | WS_CHILD | WS_VISIBLE |
TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT,
left,top,width,height,hParent,NULL,hInst,(void *)this);
if (!hTree)
return NULL;
return hTree;
}
the way that i implement the class is this:
Code:
hwnd=CreateWindowEx(//parent window);
ShowWindow(...);
UpdateWindow(...);
cTree *ct1=new cTree(hwnd);
//set dimensions
ct1->Create(hwnd,hInst);
cTree *ct2=new cTree(hwnd);
//set dimensions
ct2->Create(hwnd,hInst);
only the first tree view control is created. for any subsequent attempts, CreateWindowEx returns NULL. i cant remember ever using a superclass twice in a program, but surely it's possible.