Advertisement

Help building a window

Started by May 24, 2002 12:44 PM
4 comments, last by gamesmaster2 22 years, 5 months ago
Alright got past my very stupid question now I''m on to another one.Alright I just got the Programming Role Playing Games with Direct X.Right now I''m trying to get just a window on the screen but I keep having these problems come up mostly centered around the WindowProc area of the program.I''ve checked and rechecked the spelling against that that was in the book and it seems I have everything right but I keep getting these compiler errors.Can anyone tell me what I''m doing wrong.The code''s below. #include <windows.h> //WinMain int WINAPI WinMain( HINSTANCE hInstance, //Instance handle of application HINSTANCE hPrevInstance, //unused LPSTR lpCmdLine, //Command Line Options (if any) int nCmdShow) // Show Window Flag { WNDCLASSEX wcex = { sizeof(WNDCLASSEX),CS_CLASSDC, WindowProc,OL,OL,hInstance, NULL,NULL,NULL,NULL, "GameClass",NULL}; //Register the class if(!RegisterClassEx(&wcex)) return FALSE; //Now Create the window HWND hWnd; //Our Windows Handle hWnd = CreateWindow("GameClass", "Legend of Dragfora",WS_BORDER, 640,480,0,0,NULL,NULL,hInstance,NULL); //Return On Error if(hWnd == NULL) return FALSE; //Show the Window ShowWindow(hWnd,SW_SHOWNORMAL); UpdateWindow(hWnd); //The Message pump MSG Msg; //Clear out the Message structure ZeroMemory(&Msg,sizeof(MSG)); //Loop endlessly until you receive a quit message while(Msg.message != WM_QUIT) { //Peek into the queue and see if there''s a message if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE)) { //There''s a Message! Handle it Normally TranslateMessage(&Msg); DispatchMessage(&Msg); } else { //If there''s no messages the coputer can go ahead //and do other things like tending to sound or game //graphics } //Unregister Class UnregisterClass("GameClass",hInstance); //Exit Application return 0; } } I get about 7 errors but the errors all seem to center around this piece of code WNDCLASSEX wcex = { sizeof(WNDCLASSEX),CS_CLASSDC, WindowProc,OL,OL,hInstance, NULL,NULL,NULL,NULL, "GameClass",NULL}; I think it will be one thing wrong which when found will straighten out all 7 errors but I can''t seem to find anything.Please help! The road to hell is paved in good intentions
The road to hell is paved in good intentions
Well for starters you don''t have a WindowProc callback function.

I''m just gonna paste the fix''s to your code

when you are copying from a book. 0L the first character is zero no capital O.


  #include <windows.h>//  I ADDED THIS LINELRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);//WinMainint WINAPI WinMain(HINSTANCE hInstance, //Instance handle of applicationHINSTANCE hPrevInstance, //unusedLPSTR lpCmdLine, //Command Line Options (if any)int nCmdShow) // Show Window Flag{WNDCLASSEX wcex = { sizeof(WNDCLASSEX),CS_CLASSDC,(WNDPROC) WindowProc,0L,0L,hInstance,NULL,NULL,NULL,NULL,"GameClass",NULL};//Register the class if(!RegisterClassEx(&wcex))return FALSE;//Now Create the windowHWND hWnd; //Our Windows HandlehWnd = CreateWindow("GameClass","Legend of Dragfora",WS_BORDER,640,480,0,0,NULL,NULL,hInstance,NULL);//Return On Error if(hWnd == NULL)return FALSE;//Show the WindowShowWindow(hWnd,SW_SHOWNORMAL);UpdateWindow(hWnd);//The Message pumpMSG Msg;//Clear out the Message structureZeroMemory(&Msg,sizeof(MSG));//Loop endlessly until you receive a quit messagewhile(Msg.message != WM_QUIT)	{		//Peek into the queue and see if there''s a message 		if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))		{			//There''s a Message! Handle it Normally 			TranslateMessage(&Msg);			DispatchMessage(&Msg);		}		else		{		//If there''s no messages the coputer can go ahead 		//and do other things like tending to sound or game		//graphics		}//Unregister ClassUnregisterClass("GameClass",hInstance);//Exit Applicationreturn 0;}}//  I ADDED THIS FUNCTIONLRESULT CALLBACK WindowProc(HWND hwnd, UINT msg,							WPARAM wparam, LPARAM lparam){	switch(msg)	{	case WM_DESTROY:		PostQuitMessage(0);// destroy code out of memory		break;	default: return DefWindowProc(hwnd,msg,wparam,lparam);	}	return 0;}  
Advertisement
Have you written the WinProc callback function yet?

you need that!

When I compiled just the code above, it gave me seven errors (in MSVC++ 6.0)

Add the following above your winmain function

LRESULT WINAPI WindowProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

switch( msg )
{
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
[edit]forget it. i'm stupid [/edit]

_____________________________
If power corrupts,
and absolute power corrupts absolutly,
Then, being a programmer with absolute power over my games,
does this mean i am absolutly corrupted?
Absolutly.

[edited by - Mrbeaner on May 24, 2002 2:14:39 PM]
------------------------------------------VOTE Patrick O'GradyWrite in Presidential CandidateThe Candidate who Cares.
Also, you need to make sure and have a return 0 statement after the while(Msg.message != WM_QUIT){...}

as in:
while(Msg.message != WM_QUIT)
{
//Peek into the queue and see if there''s a message
if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
{
//There''s a Message! Handle it Normally
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else
{
//If there''s no messages the coputer can go ahead
//and do other things like tending to sound or game
//graphics

}

//Unregister Class
UnregisterClass("GameClass",hInstance);

//Exit Application
return 0;
}
return 0; //should be here
Hey there it is.I got it.Thanks alot for all your help.I hope it starts to get a little smoother from here.I guess I didn''t read quite far enough.I didn''t want to get too far and find out my code wasn''t working so at least now I''m somewhat on the right track now.Thanks alot.

The road to hell is paved in good intentions
The road to hell is paved in good intentions

This topic is closed to new replies.

Advertisement