Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Wrong with this code?

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 SettingsSeanMy DocumentsVisual Studio 2005ProjectsProject1Project1DebugBuildLog.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.

Comments

  • TheodorykTheodoryk Member Posts: 1,453
    I think you missed a 5.

    "Speaking haygywaygy or some other gibberish with your mum doesn't make you foreign."
    -baff

  • blade55555blade55555 Member Posts: 100
    What?  ARe you being serouse or sarcastic?
  • TheodorykTheodoryk Member Posts: 1,453
    I'm being silly, guess I'm in one of those moods. Pay me no heed, good luck with the code.

    "Speaking haygywaygy or some other gibberish with your mum doesn't make you foreign."
    -baff

  • blade55555blade55555 Member Posts: 100
    Yea thanks :D.
  • GruntyGrunty Member EpicPosts: 8,657

    ".maintest.c(6) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory"

    The "(6)" means the error occured in line six of your code. The path to the file windows.h is not defined in your compiler. Which probably means the paths to the next two files are not defined either.

    How do you do that? Hell if I know. Start the compiler, press F1, and start reading.

    "I used to think the worst thing in life was to be all alone.  It's not.  The worst thing in life is to end up with people who make you feel all alone."  Robin Williams
  • SnaKeySnaKey Member Posts: 3,386

    Dude. How are you this far into your program or book and dont' understand what you're doing? You can't just copy and paste code and expect to learn how it works. You actualy have to do it.

    And.... you have a problem with your windows.h. How you fix it... I dont' know. But that's where your problem is.

    If you don't know what a #include does then you need to go back to chapter 1.

    myspace.com/angryblogr
    A Work in Progress.
    Add Me
  • SnaKeySnaKey Member Posts: 3,386


    Originally posted by grunty
    How do you do that? Hell if I know.

    I don't think he understands what he's typing. He's just typing in what htey tell him. If he can't figure out how to fix something like that and realize it's a problem with an external source, then he really doesn't understand what he's doing.


    myspace.com/angryblogr
    A Work in Progress.
    Add Me
  • blade55555blade55555 Member Posts: 100
    Will I'm not that far.  I'm only on like chapter 3 or 2 one of those.  And I didn't copy and paste the code I typed it out.
  • SnaKeySnaKey Member Posts: 3,386


    Originally posted by blade55555
    Will I'm not that far. I'm only on like chapter 3 or 2 one of those. And I didn't copy and paste the code I typed it out.

    But you don't understand what you're typing. So it's the same thing.

    myspace.com/angryblogr
    A Work in Progress.
    Add Me
  • DekronDekron Member UncommonPosts: 7,359

    Follow these instructions...You should be fixed up then...

    http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/default.aspx

  • baffbaff Member Posts: 9,457


    Originally posted by SnaKey


    Originally posted by blade55555
    Will I'm not that far. I'm only on like chapter 3 or 2 one of those. And I didn't copy and paste the code I typed it out.

    But you don't understand what you're typing. So it's the same thing.



    We're all born ignorant mate.

    Typing in programs and getting them to work is the best way to learn.

Sign In or Register to comment.