PDA

View Full Version : Wrong with this code?


blade55555
08-18-2006, 07:57 AM
Ok I'm using Microsoft Visual c++ express edition for this programming book by Jonathan S. Harbour. Now this code below I type dit all in exactly now here is the error I get and I don't know how to fix it:

------ Build started: Project: Project1, Configuration: Debug Win32 ------
Compiling...
maintest.c
.\maintest.c(6) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
Build log was saved at "file://e:\Documents and Settings\Sean\My Documents\Visual Studio 2005\Projects\Project1\Project1\Debug\BuildLog.htm"
Project1 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========













// Beginning Game Programming
// Chapter 3
// WindowTest program

//header files to include
#include <windows.h>
#include <stdlib.h>
#include <time.h>

//application title
#define APPTITLE "Hello World"

//function prototypes (forward declarations)
BOOL InitInstance(HINSTANCE,int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);


//the window event callback function
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
char *szHello = "Hello World!";
RECT rt;
int x, y, n;
COLORREF c;
switch (message)
{
case WM_PAINT:
//get the dimensions of the window
GetClientRect(hWnd, &rt);

//start drawing on device context
hdc = BeginPaint(hWnd, &ps);

//draw some text
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER;

//draw 1000 random pixels
for (n=0; n<3000; n++)
{
x = rand() % (rt.right - rt.left);
y = rand() % (rt.bottom - rt.top);
c = RGB(rand()%256, rand()%256, rand()%256);
SetPixel(hdc, x, y, c);
}

//stop drawing
EndPaint(hWnd, &ps);
break;

case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}

//helper function to set up the window properties
ATOM MyRegisterClass(HINSTANCE hInstance)
{
//create the window class structure
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);

//fill the struct with info
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackround = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE;
wc.hIconSm = NULL;

//set up the window with the class info
return RegisterClassEx(&wc);
}

//helper function to create the window and refresh it
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

//create a new window
hWnd = CreateWindow(
APPTITLE, //window class
APPTITLE, //title bar
WS_OVERLAPPEDWINDOW, //window style
CW_USEDEFAULT, //x position of window
CW_USEDEFAULT, //y position of window
500, //width of the window
400, //height of the window
NULL, //parent window
NULL, //menu
hInstance, //application instance
NULL); //window parameters

//was there an error creating the window?
if (!hWnd)
return FALSE;

//display the window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//entry point for a Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// declare variables
MSG msg;

// register the class
MyRegisterClass(hInstance);

// initialize application
if (!InitInstance (hInstance, nCmdShow))
return FALSE;

//set random number seed
srand(time(NULL));

//main message loop
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}


Thanks in advance :D.

Raiyne
08-18-2006, 04:34 PM
Dont they show you the line on which the error is on? o_O Free C++ Compilers ftw.

blade55555
08-18-2006, 05:10 PM
Will yes here is the error code like i put on top:

------ Build started: Project: Project1, Configuration: Debug Win32 ------
Compiling...
maintest.c
.\maintest.c(6) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
Build log was saved at "file://e:\Documents and Settings\Sean\My Documents\Visual Studio 2005\Projects\Project1\Project1\Debug\BuildLog.htm "
Project1 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Eriond
08-18-2006, 07:27 PM
There seems to be a problem with your include directory.. even if you don't have the platform SDK installed, it shouldn't be a problem, windows is a standard header file.

Try downloading the Windows SDK:
http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en

It has all the header files and libraries you'll ever need. Just make sure you add that to your include directory (somewhere in options).

blade55555
08-18-2006, 08:31 PM
Ok thanks.

blade55555
08-19-2006, 01:29 AM
Sorry for double post but Nothing happened Still an error. Any other solutions?

pb_destiny
08-19-2006, 03:47 AM
I've ran into a similar problem in the past, and it had something to do with the registry of the compiler interacting with the directories. Basically, I ran into the same problem, except I was trying to include an sdl header. What I did was simply save all my source files (.cpp, .exe, and .o files - if you find including the machine code version of your programming is important) in separate folder not found in the directory. I than made sure I had the backups/install files for all the included files and extra libraries I added, saved somewhere else in a different folder not using the same directory.

Once I knew I had everything else I didn’t want to lose, I uninstalled the compiler and deleted all the directories left over. I than reinstalled the compiler and added all the extra libraries back into the include directory. Now this may seem a little extreme, so I would use this as a last resort. If you can’t find any other solutions to the problem than this should work, remember to move all your saved source code files to your original saving place.

Hope this helps,

-PB

blade55555
08-19-2006, 06:25 AM
So should i Re-Download it or Just reinstall it after i'v deleted everything?

pb_destiny
08-19-2006, 04:51 PM
***Important Point***
I just like to add that you should make sure to take Eriond's advice first and install the latest Windows SDK platform as you will run into problems with including the standard header files when using visual c++ express.

I just use Dev-C++ for all my source code compiling/linking.

Well I think reinstalling it should be fine, but if you run into the same problem you may have to redownload it, although I find that highly unlikely. If reinstalling everything doesnt do it, than there must be a problem somewere else on your system thats prevent you from including this single header file for some very strange, very random reason.

Chrono
08-20-2006, 12:07 AM
Heres a guide on how to install the Platform SDK, also while your at it you should also downlaod the DirectX SDK and install that. :)
http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/

Goodluck with your book.

Eriond
08-20-2006, 12:18 AM
Heres a guide on how to install the Platform SDK, also while your at it you should also downlaod the DirectX SDK and install that. :)
http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/

Goodluck with your book.

Hey! Don't turn him off OpenGL :D Who knows? He could use it instead.

blade: before you dl any graphics sdk, read up on them and see which want you want.

pb_destiny
08-20-2006, 05:06 AM
Well DirectX is definitely industry standard, its constantly being updated and I've heard (not as much from my own experience) that it is somewhat more powerful than opengl.

On the otherhand I think Opengl is much easier to learn, its well supported, it draws and can render objects fast enough to meet todays standards, and its also multiplatform.

I think that you can learn to use both if necessary, but unless you're really thinking that you will pursue a career in graphics programming I dont think DirectX has to be your first choice.

-PB

Scottc
08-20-2006, 08:05 AM
Well DirectX is definitely industry standard, its constantly being updated and I've heard (not as much from my own experience) that it is somewhat more powerful than opengl.

On the otherhand I think Opengl is much easier to learn, its well supported, it draws and can render objects fast enough to meet todays standards, and its also multiplatform.

I think that you can learn to use both if necessary, but unless you're really thinking that you will pursue a career in graphics programming I dont think DirectX has to be your first choice.

-PB

It won't be more powerful than OpenGL until DirectX 10 is released, which will introduce geometry shaders. At that point you'll be able to do really great things... like render realistic grass.... and hair....

blade55555
08-20-2006, 06:37 PM
Hey I think its not working because I don't have Microsoft visuall 2006 c++ express edition maybe? If somebody could link eme to that download thanks in advance :D.

blade55555
08-20-2006, 09:13 PM
Hey I think its not working because I don't have Microsoft visuall 2006 c++ express edition maybe? If somebody could link eme to that download thanks in advance .

Sorry for double post But i'm hoping to get an answer ASAP.

blade55555
08-21-2006, 09:22 PM
sorry for triple post but nobody is replying. Does anybody know?

naruto1327
08-29-2006, 10:19 PM
Since you are triple posting, I know you are desperate for an answer. Maybe try re-doing everything? Maybe you made some sort of mistake. Re-install everything. I don't know if it will work, but it's worth a try. :P

RobertW
08-29-2006, 11:18 PM
I have only used the full versions of Visual Studio, so I don't know what the limitations are of the particular express version you have. Basically your error is because the complier just can not find the windows.h file. In the full version I would just tell you to add that directory to list of include directories of the IDE.

I googled this and found this link. http://forums.microsoft.com/msdn/showpost.aspx?postid=2995&siteid=1

I would try the easier procedure first then if that still does not work move try the workaround.

Other then that, short of installing express version on a virgin machine or sitting in front of yours I don’t think I can help.

blade55555
08-29-2006, 11:22 PM
Hmmm I have re-installed it and (cries) the error stills comes. Which is why now i'm looking for a better compiler so that I don't go throught htis crap anymore. Also When I type the code and recieve an error where I shouldn't. I eventually got pist and decided to copy and paste the code just to see if it worked. But I was pist to see it didn't so that means I wasn't making an error cause it put the error's where Mine were when there are none! Any other solutions?

naruto1327
08-31-2006, 01:38 AM
Maybe it's not the IDE, but the computer? I don't know, I'm just taking a blind guess :P.