my wndProc is out of scope
After reading this great article on simple window c++ class at foosyerdoos , i decided to write my window class.
However, i encounter this:
Code:
--------------------Configuration: skeleton - Win32 Debug--------------------
Compiling...
mainFrame.cpp
C:\Documents and Settings\Edmund\My Documents\My eBooks\My expt files\windows workspace\skeleton\mainFrame.cpp(24) : error C2440: 'type cast' : cannot convert from '' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
None of the functions with this name in scope match the target type
Error executing cl.exe.
skeleton.exe - 1 error(s), 0 warning(s)
I think my wndProc is out of scope. Can someone tell me why? What can i do? I dont want to have a global wndProc that calls the window class object's wndProc like what the website did. Here are part of my code(mainFrame.cpp(line 24) is provide at bottom):
Code:
//--------winMain()-------------//
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)
{
MSG msg;
mainFrame mainframe(hInstance, IDR_MAIN,IDS_MAINTITLE,nCmdShow);
// instance initialization
if(!(mainframe.initInstance()))
return 0;
// GetMessage() :
// first parameter stores the message obtained from message loop
// second parameter specify the window handle for which to retrieve a msg
// if second parameter is NULL, the next message belonging to the application is obtained
// 3rd and 4th specify the range of message to obtain
// GetMessage() return 0 when WM_QUIT is retrieved
while(GetMessage(&msg,NULL,0,0))
{TranslateMessage(&msg); // translate the virtual keys for WinProc to intepret
DispatchMessage(&msg); // send message to WinProc
}
return msg.wParam;
}
//---------------skeleton.h---------------------------//
// abstract class for any windows
class skeleton
{
public:
// 1. constructor
skeleton(HINSTANCE hInst, UINT name, UINT wndTitle, int nCmdShow);
// 2. destructor
virtual ~skeleton(){};
// 3. function to register window class
virtual bool registerWindowClass(HINSTANCE hinst, UINT resPoolID) = 0;
// 4. function to create window
virtual HWND createWindow(HINSTANCE hinst, int nCmdShow, UINT resPoolID, UINT title) = 0;
// 5. window processing window
virtual LRESULT CALLBACK wndProc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam) = 0;
//6. initiliaze the window
bool initInstance();
private:
HINSTANCE hInstance; // instance handle of application
UINT classname; // class name
UINT title; // title of window
int nWinMode; // default height of window
};
#endif
//----------------mainFrame.h------------------------//
class mainFrame:public skeleton // skeleton as base class
{
public:
mainFrame(HINSTANCE hInst, UINT name, UINT wndTitle, int nCmdShow);
~mainFrame(){};
// function to register window class
virtual bool registerWindowClass(HINSTANCE hinst, UINT resPoolID);
// function to create window
virtual HWND createWindow(HINSTANCE hinst, int nCmdShow, UINT resPoolID, UINT title);
// window processing window
virtual LRESULT CALLBACK wndProc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam);
private:
void mainWindow_onDestroy(HWND hwnd);
void mainWindow_onCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
};
//-----------------------mainFrame.cpp---------------------------//
// NOTE: I believe this is where the problem is. My wndProc that i registered is in the scope of the mainFrame class.
// function to register window class
bool mainFrame::registerWindowClass(HINSTANCE hinst, UINT resPoolID)
{
WNDCLASSEX wc; // window class structure
TCHAR ClassName[MAX_RESOURCESTRING+1]; // string to load classname
// load class name into ClassName
LoadString(hinst,resPoolID,ClassName,DIM(ClassName));
// fill in window classs structure with parameters that describe the window
wc.cbSize = sizeof(WNDCLASSEX); // specify size of window class structure
wc.style = CS_HREDRAW | CS_VREDRAW ; // window class style
// THIS IS WHERE mainFrame.cpp(line 24) IS
//---------------------------------------------------------------------------
wc.lpfnWndProc = (WNDPROC) wndProc; // window process function
//---------------------------------------------------------------------------
wc.cbClsExtra = 0; // extra byte(s) to store additional information about a class,
//shared by all windows of the class
wc.cbWndExtra = 0; // extra byte(s) for each window to store additional window data
wc.hInstance = hinst; // instance handler of applcation
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); // large icon for window , NULL for default
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // cursor for mouse
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // handle of brush for window background
wc.lpszMenuName = MAKEINTRESOURCE(resPoolID); // menu for window, NULL if no menu
wc.lpszClassName = ClassName; // window class name
wc.hIconSm = LoadIcon(NULL,IDI_WINLOGO); // small icon for window
// register class into Windows and return the ATOM result
// 0 if fail
if(!RegisterClassEx(&wc))
return false;
return true;
}
Thanks for reading this post!