User forums > Help

WIN-API - stupid errors.

<< < (2/4) > >>

Culfa:

--- Code: ---#include <windows.h>

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

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

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    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 colour 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 */
           "Code::Blocks Template 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, nCmdShow);

    /* 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)
{
    static POINT point;

    switch (message)                  /* handle the messages */
    {
        case WM_CREATE:
            point.x = -1; // noch nicht gesetzt deswegen -1
            point.y = -1;

            return 0;
        case WM_RBUTTONDOWN: // wenn Rechte Maustaste gedrückt wurde
            InvalidateRect(hwnd, NULL, TRUE); // alles neuzeichen
            return 0;

        case WM_LBUTTONDOWN:
            {
                HDC hdc = GetDC(hwnd);
                {
                    SetPixel(hdc, LOWORD(lParam), HIWORD(lParam),RGB( rand()%256, rand()%256, rand()%256));
                }
                ReleaseDC(hwnd,hdc);

                point.x = LOWORD(lParam);
                point.y = HIWORD(lParam);
                return 0;
            }

        case WM_LBUTTONUP:
            {
                if(point.x != -1)
                {
                    HDC hdc = GetDC(hwnd);
                        MoveToEx(hdc, point.x, point.y, NULL);
                        LineTo(hdc,LOWORD(lParam),HIWORD(lParam));
                    ReleaseDC(hwnd, hdc);
                point.x = -1;
                point.y = -1;
                }

                return 0;
            }


        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;
}

--- End code ---

Errors:


--- Quote ----------------- Build: Debug in ddds ---------------

main.cpp
main.cpp(1) : error C2059: syntax error : '+'
main.cpp(30) : error C2332: 'class' : missing tag name
main.cpp(32) : error C2001: newline in constant
main.cpp(32) : error C2015: too many characters in constant
main.cpp(35) : error C2332: 'class' : missing tag name
main.cpp(39) : error C2001: newline in constant
main.cpp(39) : error C2015: too many characters in constant
main.cpp(43) : error C2653: 'Code' : is not a class or namespace name
main.cpp(83) : error C2143: syntax error : missing ';' before '.'
main.cpp(83) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(88) : error C2065: 'hwnd' : undeclared identifier
main.cpp(88) : error C2065: 'NULL' : undeclared identifier
main.cpp(88) : error C2065: 'TRUE' : undeclared identifier
main.cpp(88) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(88) : error C2078: too many initializers
main.cpp(88) : error C2143: syntax error : missing ';' before '+'
main.cpp(92) : error C2059: syntax error : '+'
main.cpp(105) : error C2059: syntax error : '+'
main.cpp(122) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(122) : error C2143: syntax error : missing ';' before '+'
main.cpp(124) : error C2059: syntax error : '/'
main.cpp(124) : error C2001: newline in constant
main.cpp(124) : error C2015: too many characters in constant
Process terminated with status 2 (0 minutes, 6 seconds)
23 errors, 0 warnings

--- End quote ---

stahta01:
Which Compiler are you using?
Do you have the search directory setup right?
Looks like it is not finding <windows.h>

I would turn on full compiler logging.
And post the results.

Tim S


Culfa:
I use Visual Studio 2008 by MS.



This is the search directory setup.

But what do you mean with "full compiler logging"? I find it nowhere in the compiler settings.

MortenMacFly:

--- Quote from: Culfa on January 03, 2008, 04:01:48 pm ---But what do you mean with "full compiler logging"? I find it nowhere in the compiler settings.

--- End quote ---
Read my sig... ;-)

Culfa:
Lol thx^^


-------------- Build: Debug in ddds ---------------

cl.exe /nologo /W3  /Zi /D_DEBUG    /I"C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2\include" /I"C:\Programme\Microsoft Visual Studio 9.0\VC\include" /I"C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2\Include" /I"C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2\Lib"  /c main.cpp /Foobj\Debug\main.obj
main.cpp
main.cpp(1) : error C2059: syntax error : '+'
main.cpp(30) : error C2332: 'class' : missing tag name
main.cpp(32) : error C2001: newline in constant
main.cpp(32) : error C2015: too many characters in constant
main.cpp(35) : error C2332: 'class' : missing tag name
main.cpp(39) : error C2001: newline in constant
main.cpp(39) : error C2015: too many characters in constant
main.cpp(43) : error C2653: 'Code' : is not a class or namespace name
main.cpp(83) : error C2143: syntax error : missing ';' before '.'
main.cpp(83) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(88) : error C2065: 'hwnd' : undeclared identifier
main.cpp(88) : error C2065: 'NULL' : undeclared identifier
main.cpp(88) : error C2065: 'TRUE' : undeclared identifier
main.cpp(88) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(88) : error C2078: too many initializers
main.cpp(88) : error C2143: syntax error : missing ';' before '+'
main.cpp(92) : error C2059: syntax error : '+'
main.cpp(105) : error C2059: syntax error : '+'
main.cpp(122) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
main.cpp(122) : error C2143: syntax error : missing ';' before '+'
main.cpp(124) : error C2059: syntax error : '/'
main.cpp(124) : error C2001: newline in constant
main.cpp(124) : error C2015: too many characters in constant
Process terminated with status 2 (0 minutes, 4 seconds)
23 errors, 0 warnings
 

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version