Code: Tell me whats wrong !

This is a discussion on Code: Tell me whats wrong ! within the C++ Programming forums, part of the General Programming Boards category; i am using visual c++ and my errors are: --------------------Configuration: s - Win32 Debug-------------------- Compiling... s.cpp C:\Documents and Settings\Ralph\s.cpp(40) : ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    27

    Code: Tell me whats wrong !

    i am using visual c++ and my errors are:

    --------------------Configuration: s - Win32 Debug--------------------
    Compiling...
    s.cpp
    C:\Documents and Settings\Ralph\s.cpp(40) : error C2601: 'WndProc' : local function definitions are illegal
    C:\Documents and Settings\Ralph\s.cpp(95) : error C2601: 'WinMain' : local function definitions are illegal
    C:\Documents and Settings\Ralph\s.cpp(166) : fatal error C1004: unexpected end of file found
    Error executing cl.exe


    and my code is:
    Code:
    // Includes
    
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glaux.h>
    
    float angle = 0.0f;
    HDC g_HDC;
    
    void SetupPizelFormat(HDC hDC)
    {
    int nPixelFormat;
    
    static PIXELFORMATDESCRIPTOR pfd= {
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW |
    PFD_SUPPORT_OPENGL |
    PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA,
    32,
    0,0,0,0,0,0,
    0,
    0,
    0,
    0,0,0,0,
    16,
    0,
    0,
    PFD_MAIN_PLANE,
    0,
    0,0,0 };
    
    nPixelFormat = ChoosePixelFormat(hDC, &pfd);
    
    SetPixelFormat(hDC, nPixelFormat, &pfd);
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    static HGLRC hRC;
    static HDC hDC;
    char stringp[] = "Hello World";
    int width, height;
    
    switch (message)
    {
    case WM_CREATE:
         hDC = GetDC(hwnd);
         g_HDC = hDC;
         SetupPixelFormat(hDC);
    
         hRC = wglCreateContext(hDC);
         wglMakeCurrent(hDC, hRC);
    
         return 0;
         break;
    
         case WM_CLOSE:
    
         wglMakeCurrent(hDC, NULL):
         wglDeleteContext(hRC):
    
         PostQuitMessage(0);
         return 0;
         break;
    
         case WM_SIZE:
         height = HIWORD(lParam);
         width = LOWORD(lParam);
    
         if (height == 0)
             {
             height = 1;
             }
          glViewport(0,0,width,height);
          glMatrixMode(GL_PROJECTON);
          glLoadIdentity();
    
          gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
    
          glMatrixMode(GL_MODELVIEW);
          glLoadIdentity();
    
          return 0;
          break;
    
          default:
          break;
     }
      return (DefWindowProc(hwnd, message, wParam, lParam));
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    WNDCLASSEX windowClass;
    HWND hwnd;
    MSG msg;
    bool done;
    
    windowClass.cbSize = sizeof(WNDCLASSEX);
    windowClass.style = CS_HREDRAW | CS_VREDRAW;
    windowClass.lpfnWndProc = WndProc;
    windowClass.cbClsExtra = 0;
    windowClass.cbWndExtra = 0;
    windowClass.hInstance = hInstance;
    windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    windowClass.hbrBackground = NULL;
    windowClass.lpszMenuName = NULL;
    windowClass.lpszClassName = "MyClass";
    windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    
    if (!RegisterClassEx(&windowClass))
    return 0;
    
    hwnd = CreateWindowEx(NULL,"MyClass","The opengl Window Application",WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPSIBLINGS, 100,100,400,400,NULL,NULL,hInstance,NULL);
    
    if (!hwnd)
    return 0;
    
    
    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);
    
    done = false;
    
    while (!done)
    {
    PeekMessage(&msg, hwnd,NULL,NULL, PM_REMOVE);
    
    if (msg.message == WM_QUIT)
    {
    done = true;
    }
    else
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIndentity();
    
    angle = angle + 0.1f;
    if (angle >= 360.0f)
       angle = 0.0f;
    glTranslatef(0.0f,0.0f,-5.0f);
    glRotatef(angle,0.0f,0.0f,1.0f);
    
    glColor3f(1.0f,0.0f,0.0f);
    glBegin(GL_TRIANGLES);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(1.0f,0.0f,0.0f);
    glVertex3f(1.0f,1.0f,0.0f);
    
    glEnd();
    
    SwapBuffers(g_HDC);
    
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    
    }
    return msg.wParam;
    }
    Last edited by slx47; 05-09-2002 at 04:08 PM.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Please use the CODE tageTage

    Please use the code tags

    Code:
     [ CODE ] no spacing 
    [ / CODE ]
    C++
    The best

  3. #3
    Unregistered
    Guest
    >void SetupPizelFormat(HDC hDC)
    >{
    >int nPixelFormat;

    Uh... did you mean SetupPixelFormat?? Did you notice the spelling error there?

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    you haven't closed the scope of the setpixelformat function. make sure you change this:

    Code:
        SetPixelFormat(hDC, nPixelFormat, &pfd);
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    to this
    Code:
        SetPixelFormat(hDC, nPixelFormat, &pfd);
    }
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    hope this helps
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 09:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 05:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 01:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21