Archived

This topic is now archived and is closed to further replies.

xDS4Lx

Deriving from CWindow

Recommended Posts

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? Edited by - xds4lx on February 21, 2002 8:02:03 PM

Share this post


Link to post
Share on other sites
Anyone? I really need to know if this is the proper way to do this. Both of these take a WNDPROC param that is by default set to NULL in their definition. Well here are my constructors for CWindow:

            
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;
}
}


Then in my derived class CAppWindow I pass it like this:

                    
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? Its been working fine but I dont want to run into problems later. I finally got mad and had to #prgrma it b/c i got sick of seing it appear.


Edited by - xds4lx on February 22, 2002 3:15:34 AM

Edited by - xds4lx on February 22, 2002 3:16:52 AM

Share this post


Link to post
Share on other sites
Hello???? I know that I cant be the only one doing this b/c there are so many other threads here about putting window's into classes. How do other people pass their derived class's WndProc to the base class????? Ok this is pissing me off that noone ever gives the time to answer my questions, when I take my time to help others, cant anyone return the favor? What is this world coming to? Ive searched through this board and cant find anything ansering my questions. Ive also searched on other boards and everyone is just like the people here, only interested in themselves.

Edited by - xds4lx on February 22, 2002 3:07:38 AM

Share this post


Link to post
Share on other sites
Oh, shut the fuck up. Your question has been answered in your other threads. If you wish to figure out another way to achieve the same thing, don''t expect us to then respond to your every confusion. GDNet has a search tool, and several threads detail how various people solved this problem (passing this to CreateWindow*, handling WM_NCCREATE in the message router, etc). What else do you want?

Thread closed.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.