Archived

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

MsgHandler: undeclared identifier

This topic is 5651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I''m following the "Game Programming Genesis Part I : Beginning Windows Programming" tutorial by Joseph Farrell on this site. I''ve gotten the basics of the code written up and am copiling to clean out any errors I made. I am now getting a C:\Documents and Settings\JS\Desktop\Scripts\C\Win\win.cpp(21) : error C2065: ''MsgHandler'' : undeclared identifier error when compiling. Here is the code I have so far.
  
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>

//#define DEBUG_MODE
//#ifdef DEBUG_MODE
//#endif



int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{



WNDCLASSEX sampleClass_s;

sampleClass_s.cbSize =			sizeof(WNDCLASSEX);
sampleClass_s.style =			CS_DBLCLKS | CS_OWNDC |
								CS_HREDRAW | CS_VREDRAW;
sampleClass_s.lpfnWndProc =		MsgHandler;
sampleClass_s.cbClsExtra =		0;
sampleClass_s.cbWndExtra =		0;
sampleClass_s.hInstance =		hinstance;
sampleClass_s.hIcon =			LoadIcon(NULL, IDI_WINLOGO);
sampleClass_s.hCursor =			LoadCursor(NULL, IDC_ARROW);
sampleClass_s.hbrBackground =	(HBRUSH)GetStockObject(BLACK_BRUSH);
sampleClass_s.lpszMenuName =	NULL;
sampleClass_s.lpszClassName =	"Sample Class";
sampleClass_s.hIconSm =			LoadIcon(NULL, IDI_WINLOGO);

RegisterClassEx(&sampleClass_s);


HWND hwnd;
if (!(hwnd = CreateWindowEx(NULL,
							"Sample Class",
							"Sample Window",
							WS_POPUP | WS_VISIBLE,
							0, 0, 320, 240,
							NULL,
							NULL,
							hinstance,
							NULL)))
	return(0);


}
  
Anyone know what might cause this. As you can probably guess I am new to Windows programming (why else would I be going through the tutorial) so I might be missing something obvious. Any help is much appreciated.

Share this post


Link to post
Share on other sites
Yeah, you're missing the actual definition of your window procedure -- MsgHandler. You need the message handler function to register your window class.

[edited by - IndirectX on June 23, 2002 11:38:52 PM]

Share this post


Link to post
Share on other sites
You need a function named MsgHandler. Look up WndProc in the MSDN library. What you do when you write lpfnWndProc = MsgHandler is that you tell Windows that you want the MsgHandler function to be called whenever something happens to your window.

Share this post


Link to post
Share on other sites
Thanks for the responses guys. I was under the impression that the msghandler function was included in one of the windows header files. If I had just been patient I would have noticed that the tutorial covered this a page or two later. I''ll also check out the WndProc documetation. Thanks again.

Share this post


Link to post
Share on other sites