Results 1 to 20 of 20

Thread: Wrong with this code?

  1. #1
    Cloud's Hair Spray Reputation: 10

    Join Date
    Aug 2006
    Posts
    60
    Rep Power
    11

    Default 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 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 .

  2. #2
    春光乍泄 Reputation: 193
    Raiyne's Avatar
    Join Date
    May 2006
    Location
    Iguazu Falls
    Posts
    13,561
    Rep Power
    20

    Default

    Dont they show you the line on which the error is on? o_O Free C++ Compilers ftw.

    If you rescue me, I'll be your friend forever. -- Loric
    Last.fm
    Hey Raiyne

  3. #3
    Cloud's Hair Spray Reputation: 10

    Join Date
    Aug 2006
    Posts
    60
    Rep Power
    11

    Default

    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 ==========

  4. #4
    Retired Staff Reputation: 75
    Eriond's Avatar
    Join Date
    May 2006
    Location
    Montreal
    Posts
    1,790
    Rep Power
    12

    Default

    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/d...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).
    THIS MA SIGNATURE

  5. #5
    Cloud's Hair Spray Reputation: 10

    Join Date
    Aug 2006
    Posts
    60
    Rep Power
    11

    Default

    Ok thanks.

  6. #6
    Cloud's Hair Spray Reputation: 10

    Join Date
    Aug 2006
    Posts
    60
    Rep Power
    11

    Default

    Sorry for double post but Nothing happened Still an error. Any other solutions?

  7. #7
    Orc's Breathmint Reputation: 10
    pb_destiny's Avatar
    Join Date
    May 2006
    Location
    Ottawa, Ontario, Canada
    Posts
    101
    Rep Power
    11

    Default

    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
    Last edited by pb_destiny; 08-19-2006 at 06:10 PM.
    Been A Member Since May of 2005

  8. #8
    Cloud's Hair Spray Reputation: 10

    Join Date
    Aug 2006
    Posts
    60
    Rep Power
    11

    Default

    So should i Re-Download it or Just reinstall it after i'v deleted everything?

  9. #9
    Orc's Breathmint Reputation: 10
    pb_destiny's Avatar
    Join Date
    May 2006
    Location
    Ottawa, Ontario, Canada
    Posts
    101
    Rep Power
    11

    Default

    ***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.
    Last edited by pb_destiny; 08-19-2006 at 06:09 PM.
    Been A Member Since May of 2005

  10. #10
    Retired Staff Reputation: 10
    Chrono's Avatar
    Join Date
    May 2006
    Posts
    284
    Rep Power
    11

    Default

    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/ex...alc/usingpsdk/

    Goodluck with your book.

  11. #11
    Retired Staff Reputation: 75
    Eriond's Avatar
    Join Date
    May 2006
    Location
    Montreal
    Posts
    1,790
    Rep Power
    12

    Default

    Quote Originally Posted by Chrono View Post
    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/ex...alc/usingpsdk/

    Goodluck with your book.
    Hey! Don't turn him off OpenGL Who knows? He could use it instead.

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

  12. #12
    Orc's Breathmint Reputation: 10
    pb_destiny's Avatar
    Join Date
    May 2006
    Location
    Ottawa, Ontario, Canada
    Posts
    101
    Rep Power
    11

    Default

    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
    Been A Member Since May of 2005

  13. #13
    Pikachu's Flea Collar Reputation: 10

    Join Date
    Aug 2006
    Posts
    57
    Rep Power
    10

    Default

    Quote Originally Posted by pb_destiny View Post
    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....

  14. #14
    Cloud's Hair Spray Reputation: 10

    Join Date
    Aug 2006
    Posts
    60
    Rep Power
    11

    Default

    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 .

  15. #15
    Cloud's Hair Spray Reputation: 10

    Join Date
    Aug 2006
    Posts
    60
    Rep Power
    11

    Default

    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.

  16. #16
    Cloud's Hair Spray Reputation: 10

    Join Date
    Aug 2006
    Posts
    60
    Rep Power
    11

    Default

    sorry for triple post but nobody is replying. Does anybody know?

  17. #17
    Danteís Inferno Reputation: 10
    naruto1327's Avatar
    Join Date
    May 2006
    Location
    OLD PROFILE. NEW: NOODLEPOWA
    Posts
    608
    Rep Power
    11

    Default

    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

  18. #18
    Marios's Mustache Wax Reputation: 10

    Join Date
    Aug 2006
    Posts
    13
    Rep Power
    10

    Default

    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/sho...=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.

  19. #19
    Cloud's Hair Spray Reputation: 10

    Join Date
    Aug 2006
    Posts
    60
    Rep Power
    11

    Default

    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?

  20. #20
    Danteís Inferno Reputation: 10
    naruto1327's Avatar
    Join Date
    May 2006
    Location
    OLD PROFILE. NEW: NOODLEPOWA
    Posts
    608
    Rep Power
    11

    Default

    Maybe it's not the IDE, but the computer? I don't know, I'm just taking a blind guess :P.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •