Help Wanted

CONFUSED – buddboy

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
lol... i'm trying to learn DirectX in C++... i bought a book... i'm at the part where you learn a little bit of Windows programming (which I'll need later on), and i can't figure it out... i keep getting these errors... two sets of errors, one for a certain way I set up my code, the second one for a different way... here's the two sets, and the code for them...
(BTW, i'll put the error numbers next to the code that gets the error, so you're sure)

#include <windows.h>

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

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


1 int WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_CLASSDC, \
WindowProc, OL, OL, hInstance, \
NULL, NULL, NULL, NULL, \
"GameClass", NULL);


ATOM RegisterClassEx(CONST WNDCLASSEX *lpcwcx);


ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

MSG Msg;
while(GetMessage(&Msg, NULL, 0, 0)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg)
}


return 0;
2 }


errors:
1.) "WNDCLASSEX" does not name a type
2.) expecting '}' at end of input

i've fixed number 2, but i think it just gave more errors
can anyone help me with this?

------------------
In the stock market, you must buy high and sell low...Wait! That's not right!
--------------
Yes, I can be intelligent at times!!

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
here's the second set:

#include <windows.h>

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

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


WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_CLASSDC, \
WindowProc, OL, OL, hInstance, \
NULL, NULL, NULL, NULL, \
"GameClass", NULL);


ATOM RegisterClassEx(CONST WNDCLASSEX *lpcwcx);


ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

MSG Msg;
while(GetMessage(&Msg, NULL, 0, 0)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg)
}


return 0;
}
}

(BTW, i fixed the second error in the first post by adding a second '}' )

here's the errors:

1.) "WindowProc" undeclared (first use this function)
i have to go... can't finish this up... i'll edit it later... sorry... lol...

------------------
In the stock market, you must buy high and sell low...Wait! That's not right!
--------------
Yes, I can be intelligent at times!!

dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
lol, I have no idea why you have that "typedef struct _WNDCLASSEX..." thats weird if the book said to use that. are you sure they are not just showing you what the _WNDCLASSEX structure has??

below is the templated win32 C++ code for Dev-C++... (meaning this is not my code, this is the templates code)


#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

Hopefully that will help you.

------------------
"But it is God who judges: He brings one down, he exalts another." - Psalm 76:7

Startup Christian Games Company Producing Mobile/PC Games/Tools

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
well, you were right... it was just showing me the structure... lol... i was confused... lol... i've got it figured out tho lol... thnx...

------------------
In the stock market, you must buy high and sell low...Wait! That's not right!
--------------
Yes, I can be intelligent at times!!

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
well, i figured out what i'm supposed to be typing in, but it doesn't work... lol.. and for some reason, the program on the cd that comes with the book, that corresponds to this chapter, is totally different from the one it has in the book... lol... hey dartsman you mind if i send you my source and you look at it, and try compiling it?

------------------
In the stock market, you must buy high and sell low...Wait! That's not right!
--------------
Yes, I can be intelligent at times!!

dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
no prob... ur on my msn, so just chat there if you want... u can send me source code stuff... but i don't accept .exe's (for obvious reasons, plus in msn they don't let ya )

yay... 50 posts :P

------------------
"But it is God who judges: He brings one down, he exalts another." - Psalm 75:7

Startup Christian Games Company Producing Mobile/PC Games/Tools

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
lol... they will if you put them in .zips....lol...

------------------
In the stock market, you must buy high and sell low...Wait! That's not right!
--------------
Yes, I can be intelligent at times!!

dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
yeah, but still I won't accept .exes :P haha

just don't quite trust running an .exe from overseas...

------------------
"But it is God who judges: He brings one down, he exalts another." - Psalm 75:7

Startup Christian Games Company Producing Mobile/PC Games/Tools