Skip to main content
gamedev.net
🔒 Locked

Problem with 'Game Programming Genesis' Tutorial - Please Help!

Started by Radagar 5 replies 650+ views
Original Post
Radagar
Radagar
When I enter this code from the Game Programming Genesis Part I: Beginning Windows Programming Tutorial, it gives me compiler errors. The problem is with the typdef struct WNDCLASSEX. can someone check to see what I did wrong? or what is typed wrong in the tutorial? I'm using MSVC++ 6.0 with a Win32 Application project type. Thanks!
    
#include <windows.h>

#include <windowsx.h>

#include <conio.h>

#include <stdio.h>

#define WIN32_LEAN_AND_MEAN

typedef struct WNDCLASSEX {
	UINT	cbSize;
	UINT	style;
	WNDPROC lpfnWndProc;
	int		cbClsExtra;
	int		cbWndExtra;
	HANDLE	hInstance;
	HICON	hIcon;
	HCURSOR	hCursor;
	HBRUSH	hBrush;
	LPCTSTR	lpszMenuName;
	LPCTSTR	lpszClassName;
	HICON	hIconSm;
} WNDCLASSEX;

WNDCLASSEX GameWindow;

GameWindow.cbSize =			sizeof(WNDCLASSEX);
GameWindow.style =			CS_DBLCLKS | CS_OWNDC |
					CS_HREDRAW | CS_VREDRAW;
// ... ... ..



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	return 0;
}
    
The Compiler Errors are.... :\My Documents\WinGame\Wyrm.cpp(8) : error C2371: 'WNDCLASSEX' : redefinition; different basic types c:\program files\microsoft visual studio\vc98\include\winuser.h(1177) : see declaration of 'WNDCLASSEX' C:\My Documents\WinGame\Wyrm.cpp(25) : error C2143: syntax error : missing ';' before '.' C:\My Documents\WinGame\Wyrm.cpp(25) : error C2501: 'GameWindow' : missing storage-class or type specifiers C:\My Documents\WinGame\Wyrm.cpp(25) : error C2371: 'GameWindow' : redefinition; different basic types C:\My Documents\WinGame\Wyrm.cpp(23) : see declaration of 'GameWindow' C:\My Documents\WinGame\Wyrm.cpp(25) : error C2143: syntax error : missing ';' before '.' C:\My Documents\WinGame\Wyrm.cpp(26) : error C2143: syntax error : missing ';' before '.' C:\My Documents\WinGame\Wyrm.cpp(26) : error C2501: 'GameWindow' : missing storage-class or type specifiers C:\My Documents\WinGame\Wyrm.cpp(26) : error C2371: 'GameWindow' : redefinition; different basic types C:\My Documents\WinGame\Wyrm.cpp(23) : see declaration of 'GameWindow' C:\My Documents\WinGame\Wyrm.cpp(26) : error C2143: syntax error : missing ';' before '.' Error executing cl.exe. ~~~~~~~~~~~ Chris Vogel ~~~~~~~~~~~ [edited by - Radagar on June 13, 2002 12:07:21 PM]
WyrmSlayer RPG - In Early Development
Radagar
Radagar
Well.. That helped a little, but It's still not working. Here is what I have now. Any suggestions?


      
#define WIN32_LEAN_AND_MEAN

#include <windows.h>

#include <windowsx.h>

#include <conio.h>

#include <stdio.h>

/* typedef struct WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hBrush;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX; */


WNDCLASSEX gameWindow;

gameWindow.cbSize = sizeof(WNDCLASSEX);
gameWindow.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
return 0;
}

And The Errors....

C:\My Documents\WinGame\Wyrm.cpp(25) : error C2143: syntax error : missing ';' before '.'
C:\My Documents\WinGame\Wyrm.cpp(25) : error C2501: 'gameWindow' : missing storage-class or type specifiers
C:\My Documents\WinGame\Wyrm.cpp(25) : error C2371: 'gameWindow' : redefinition; different basic types
C:\My Documents\WinGame\Wyrm.cpp(23) : see declaration of 'gameWindow'
C:\My Documents\WinGame\Wyrm.cpp(25) : error C2143: syntax error : missing ';' before '.'
C:\My Documents\WinGame\Wyrm.cpp(26) : error C2143: syntax error : missing ';' before '.'
C:\My Documents\WinGame\Wyrm.cpp(26) : error C2501: 'gameWindow' : missing storage-class or type specifiers
C:\My Documents\WinGame\Wyrm.cpp(26) : error C2371: 'gameWindow' : redefinition; different basic types
C:\My Documents\WinGame\Wyrm.cpp(23) : see declaration of 'gameWindow'
C:\My Documents\WinGame\Wyrm.cpp(26) : error C2143: syntax error : missing ';' before '.'
Error executing cl.exe.

Wyrm.obj - 8 error(s), 0 warning(s)


[edited by - Radagar on June 13, 2002 2:28:39 PM]

[edited by - Radagar on June 13, 2002 2:29:31 PM]
WyrmSlayer RPG - In Early Development
alexk7
alexk7
You have instructions outside of any functions!
Put these three lines:
WNDCLASSEX gameWindow;
gameWindow.cbSize = sizeof(WNDCLASSEX);
gameWindow.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
in your main(), before "return 0;"
alexk7
Radagar
Radagar
LOL, amazing how well that worked. I didn''t even realize I started building the class OUTSIDE of WinMain. Oops!

Thanks all!



~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
WyrmSlayer RPG - In Early Development
matrix2113
matrix2113
Well I need my practice, so I''ll just write out a (n almost) working plain window, and you can figure it out:


  
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);/*You can name this whatever you want;
Windows calls it from TranslateMessage() or DispatchMessage or something...*/

int WINAPI WinMain(/*Don''t remember parameters oh well*/)
{
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;

winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;//Different settings for window
winclass.lpfnWndProc = WinProc;/*Tell Windows what you named that weird
looking function up above*/
winclass.cbClsExtra = 0; //Ah who cares what this does
winclass.cbWndExtra = 0;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.hInstance = hInstance;//Make sure to use the same one you declared in WinMain()
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);//Standard
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);//Standard
winclass.cursor = LoadCursor(NULL, IDC_ARROW);//Standard
winclass.hbrBackground = (HBRUSH)(GetStockObject(BLACK_BRUSH));//Black Background
winclass.lpszMenuName = NULL//No Menu
winclass.lpszClassName = "Hi!"

//Register the Class
if(!RegisterClassEx(&winclass))
return 0;//Error checking

//Create the Window
if(!(hwnd = CreateWindowEx("Hi!",//Make sure it''s the same^
"Hi again!",//Title
"WS_POPUP | WS_VISIBLE,//More settings
0,0,//x and y
400, 400,//Width and Height
NULL, NULL,//Handle to Parent and Menu
hInstance, //hInstance from WinMain()
NULL)))//I don''t even know what this does
return 0;//Error Checking

While(1)//Main loop
{
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))//Check for messages
{
//If there''re any...
if (msg.message == WM_QUIT)//Quit the program
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}//end if
}//end while
return (msg.wParam);//For some reason you return like this...?
}//End WinMain

//Define WinProc
LRESULT CALLBACK WinProc(/*All that stuff I had up there*/
)
{
switch (msg)
{
//do stuff here

default:break;
}
return(DefWindowProc(hwnd, msg, wParam, lParam));//Windows handles messages that you don''t

}//end WinProc()



"I''ve learned something today: It doesn''t matter if you''re white, or if you''re black...the only color that really matters is green"
-Peter Griffin
"I've learned something today: It doesn't matter if you're white, or if you're black...the only color that really matters is green"-Peter Griffin

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.