Thread: Deriving from CWindow

  1. #1
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630

    Deriving from CWindow

    I was just wondering how you guys go about deriving a new class from your own CWindow and how you would set it to use the WndProc from the derived class. I made it so that CWindow, the base class, takes a WNDPROC param, but it also has a default value of null then the base constructor assigns either the user specified param or the default WndProc. But when i call the derived class's constructor and pass &this->WndProc it gives me this warning:

    C:\My Documents\Projects\CBWindow\CAppWindow.cpp(4) : warning C4355: 'this' : used in base member initializer list

    Everything works and all but i was wondering if thats bad? I know if it was a variable or something it would be, but im just passing the address of a function, is that ok?
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630

    Question

    Anyone? I really need to know if this is the proper way to do this. Well here are my constructors for CWindow: You can see the cleaner looking code since the BB is nice at: http://www.gamedev.net/community/for...topic_id=81529
    Code:
    CWindow::CWindow(const HINSTANCE& hInstance,char* pszClassName, const
     WNDPROC WndProc ): hInst(hInstance), bInitFail(false), pszCName
    (pszClassName){	wndClass.cbSize = sizeof(WNDCLASSEX);
    	wndClass.cbClsExtra = 0;	wndClass.cbWndExtra = 0;
    	wndClass.hbrBackground = (HBRUSH)COLOR_WINDOW;
    	wndClass.hInstance = hInstance;	wndClass.hCursor = 
    LoadCursor(NULL,IDC_ARROW);	wndClass.hIcon = LoadIcon
    (NULL,IDI_APPLICATION);	wndClass.hIconSm = LoadIcon
    (NULL,IDI_APPLICATION);	wndClass.lpszClassName = pszClassName;
    	wndClass.lpszMenuName = NULL;	wndClass.style = 
    CS_OWNDC | CS_VREDRAW | CS_HREDRAW;		if(WndProc)	{
    	wndClass.lpfnWndProc = WndProc;			}
    	else	{	wndClass.lpfnWndProc = &(this-
    >WindowProc);	}	if(!RegisterClassEx(&wndClass))	{
    	MessageBox(NULL,"ERROR IN APPLICATION STARTUP","Error In 
    Registering Window Class",MB_OK);		bInitFail = true;	}}
    CWindow::CWindow(const HINSTANCE& hInstance, const UINT& style, const 
    HBRUSH& hBackground, 				   const 
    HICON& hIconSmall, const HICON& hIconLarge, const HCURSOR& Cursor,
    				   char* pszClassName, const 
    WNDPROC WndProc): hInst(hInstance), bInitFail(false), pszCName
    (pszClassName){	wndClass.cbSize = sizeof(WNDCLASSEX);
    	wndClass.cbClsExtra = 0;	wndClass.cbWndExtra = 0;
    	wndClass.hbrBackground = (HBRUSH)hBackground;	wndClass.hIcon 
    = hIconLarge;	wndClass.hIconSm = hIconSmall;
    	wndClass.hInstance = hInstance;	wndClass.hCursor = 
    Cursor;	wndClass.lpszClassName = pszClassName;
    	wndClass.lpszMenuName = NULL;	wndClass.style = style;
    		if(WndProc)	{	wndClass.lpfnWndProc = 
    WndProc;	}	else	{	wndClass.lpfnWndProc = &(this-
    >WindowProc);	}	if(!RegisterClassEx(&wndClass))	{
    	MessageBox(NULL,"ERROR IN APPLICATION STARTUP","Error In 
    Registering Window Class",MB_OK);		bInitFail = true;	}}

    Both of these take a WNDPROC param that is by default set to NULL in their definition. Then in my derived class CAppWindow I pass it like this:

    Code:
    CAppWindow::CAppWindow(const HINSTANCE& hInstance, char* 
    pszClassName): CWindow(hInstance,pszClassName,&this->WndProc){}
    CAppWindow::CAppWindow(const HINSTANCE& hInstance, const UINT& style, 
    const HBRUSH& hBackground,					   
    const HICON& hIconSmall,const HICON& hIconLarge, const HCURSOR& 
    hCursor,					   char* pszClassName): 
    CWindow(hInstance, style, hBackground, hIconSmall, hIconLarge, 
    hCursor, pszClassName, &this->WndProc){}
    Here you can see how Im passing the addres of the derived class's WndProc. But it generates the warning:

    C:\My Documents\Projects\CBWindow\CAppWindow.cpp(4) : warning C4355: 'this' : used in base member initializer list

    Is this the proper way of doing this?
    Last edited by xds4lx; 02-21-2002 at 09:44 PM.

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Hello????????? Anyone ever do this? I know I cant be the only one, some answere here would really be appreciated!
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Here is a discussion that is relevant to your question, although it may not initially seem so:

    http://www.cprogramming.com/cboard/s...threadid=11410

    How you design your class structure is how you do it. To me it looks like an attempt to emulate mfc with the tons of parameters being passed in. I personally wouldn't do that sort of thing but if it works for you then that's just great.

    The more you play around with your class(es) the more things will occur to you and the more tweaks you will end up making.

    Some of the pro's may be able to suggest a 'correct' or a 'right' or even a 'proper' way to set things up; as an amateur I suggest you please yourself and stick to what works best for you.

  5. #5
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    thanx, finally someone replied to me, ive been asking this on several win32 boards and noone has ansered me in the 3 or 4 days ive had them up. Im only passing a lot of params in that constructor, i have overloaded versions that use less, I made those so that I can easily change things instead of hard coding them in. Also i just looked at the thread you suggested and it is not the answer I am looking for. I have no problem setting up my WndProc for my base class. I also have no problem setting up WndProc for my derived class, what Im asking is if what im doing is proper or if theres a better way of doing it. In fact if you want im uploading the current code i have to my web page, and you can look at it if you want and give me any criticisms you may have, heres the link:
    sorry if you didnt get it already I had to take it down, my school contacted me about wasting bandwidth, sorry, if you want a copy contact me on AIM or email me,
    (Just a warning, this is on my school's server and they are having bandwidth problems latly so just wait a sec if it doesnt come up right away)
    Last edited by xds4lx; 02-23-2002 at 03:08 PM.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. deriving from std::exception
    By MarkZWEERS in forum C++ Programming
    Replies: 5
    Last Post: 05-10-2008, 02:14 PM
  2. Deriving from std::except
    By Mario F. in forum C++ Programming
    Replies: 5
    Last Post: 06-23-2007, 07:20 AM
  3. wtf...? deriving from template
    By Raven Arkadon in forum C++ Programming
    Replies: 11
    Last Post: 06-28-2005, 02:36 AM
  4. Deriving one class from another
    By SpudNuts in forum C++ Programming
    Replies: 4
    Last Post: 02-08-2005, 02:15 AM
  5. Deriving from CEditView?
    By Jamsan in forum Windows Programming
    Replies: 1
    Last Post: 04-02-2003, 08:22 AM