Witching Hour
01-06-2001, 07:13 AM
in the following example, i created a class to set the winapi WNDCLASS
structure and register that class, but this class can't work without
arguments being passed to the overloaded constructor, in this example they
are wndclass, hinstance, address of wndproc function and the name of that
wndclass structure.
i have also created a default constructor and placed it in private, so it
won't be accessed, but i cannot write the implementation for that default
constructor because hinst and wndproc are references and they are required
in the member initialization list, and i can't set them to NULL.
leaving the default constructor without implementation works, and not
declaring a default constructor also worked, but i want to declare it and
write the implementation :) so plz help, this is the first time that i used
c++ with winapi
thank you
here's the code:
///////////////////////////////////////////////////////////////////
class InitClass
{
public:
InitClass(WNDCLASS *wndclass,HINSTANCE & hInst,WNDPROC wp,TCHAR
*classname);
~InitClass();
bool RegisterInitClass();
private:
InitClass(); // what's the implementation for this default constructor
WNDCLASS *initclasswc;
HINSTANCE &initclasshInst; // must be in member initialization list
WNDPROC &initclasswndproc;
TCHAR *initclassname;
};
//////////////////////////////////////////////////////////
//implementation for the InitClass class
/////////////////////////////////////////////////////////
//destructor
InitClass::~InitClass()
{
}
//overloaded constructor
InitClass::InitClass(WNDCLASS *wndclass,HINSTANCE &hInst,WNDPROC wp,TCHAR
*classname)
:initclasswc(wndclass),initclasshInst(hInst),initclasswndproc(wp),
initclassname(classname)
{
initclasswc->style = CS_HREDRAW | CS_VREDRAW;
initclasswc->lpfnWndProc = initclasswndproc;
initclasswc->cbClsExtra = 0;
initclasswc->cbWndExtra = 0;
initclasswc->hInstance = initclasshInst;
initclasswc->hIcon = LoadIcon(NULL,IDI_APPLICATION);
initclasswc->hCursor = LoadCursor(NULL,IDC_ARROW);
initclasswc->hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
initclasswc->lpszMenuName = NULL;
initclasswc->lpszClassName = initclassname;
}
bool InitClass::RegisterInitClass()
{
if(!::RegisterClass(initclasswc))
{
::MessageBox(NULL,"Registration Failed!!","Error",0);
return false;
}
return true;
}
structure and register that class, but this class can't work without
arguments being passed to the overloaded constructor, in this example they
are wndclass, hinstance, address of wndproc function and the name of that
wndclass structure.
i have also created a default constructor and placed it in private, so it
won't be accessed, but i cannot write the implementation for that default
constructor because hinst and wndproc are references and they are required
in the member initialization list, and i can't set them to NULL.
leaving the default constructor without implementation works, and not
declaring a default constructor also worked, but i want to declare it and
write the implementation :) so plz help, this is the first time that i used
c++ with winapi
thank you
here's the code:
///////////////////////////////////////////////////////////////////
class InitClass
{
public:
InitClass(WNDCLASS *wndclass,HINSTANCE & hInst,WNDPROC wp,TCHAR
*classname);
~InitClass();
bool RegisterInitClass();
private:
InitClass(); // what's the implementation for this default constructor
WNDCLASS *initclasswc;
HINSTANCE &initclasshInst; // must be in member initialization list
WNDPROC &initclasswndproc;
TCHAR *initclassname;
};
//////////////////////////////////////////////////////////
//implementation for the InitClass class
/////////////////////////////////////////////////////////
//destructor
InitClass::~InitClass()
{
}
//overloaded constructor
InitClass::InitClass(WNDCLASS *wndclass,HINSTANCE &hInst,WNDPROC wp,TCHAR
*classname)
:initclasswc(wndclass),initclasshInst(hInst),initclasswndproc(wp),
initclassname(classname)
{
initclasswc->style = CS_HREDRAW | CS_VREDRAW;
initclasswc->lpfnWndProc = initclasswndproc;
initclasswc->cbClsExtra = 0;
initclasswc->cbWndExtra = 0;
initclasswc->hInstance = initclasshInst;
initclasswc->hIcon = LoadIcon(NULL,IDI_APPLICATION);
initclasswc->hCursor = LoadCursor(NULL,IDC_ARROW);
initclasswc->hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
initclasswc->lpszMenuName = NULL;
initclasswc->lpszClassName = initclassname;
}
bool InitClass::RegisterInitClass()
{
if(!::RegisterClass(initclasswc))
{
::MessageBox(NULL,"Registration Failed!!","Error",0);
return false;
}
return true;
}