I am learning how to program through the windows.h library and was following a tutorial. After I copied the code to just create a window I got a lot of errors
here is the code

#include <windows.h>
#define WNDCLASSNAME "wndclass"
//the needed global variables
using namespace std;
HWND handleWin;
HDC hdc;
bool quit = FALSE;

//the main function
WINAPI WinMain (HINSTANCE hinstance,
                HINSTANCE hprevinstance,
                LPSTR lpcmdline,
                int nshowcmd)
{
    //set up the window class
    MSG msg;
    WINCLASSEX ex;
    ex.cbSize = sizeof(WNDCLASSEX);
    ex.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
    ex.lpfnWinProc = WinProc;
    ex.cbClsExtra = 0;
    ex.cbWndExtra = 0;
    ex.hInstance = hinstance;
    ex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    ex.hCursor = LoadCursor(NULL, IDC_ARROW);
    ex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    ex.lpszMenuName = NULL;
    ex.lpszClassName = WNDCLASSNAME;
    ex.IconSm = NULL;

    RegisterClassEx(&ex);

    //create the window
    hwnd = CreateWindowEx(NULL,
                          WNDCLASSNAME,
                          "Window",
                          WS_OVERLAPPEDWINDOW,
                          0, 0,
                          300, 300,
                          NULL, NULL,
                          hinstance,
                          NULL);
    ShowWindow(handleWin, SM_SHOW);
    UpdateWindow(handleWin);

    //the message loop
    while(!quit){
        if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)){
            if (msg.message == WM_QUIT){
                quit = TRUE;
                TranslateMessge(&msg);
                DispatchMessage(&msg);
                }
        }
    }
    return msg.lParam;
}

here are the errors I get

C:\C++\Graph\testers\main.c|4|error: syntax error before "namespace"|
C:\C++\Graph\testers\main.c|4|warning: type defaults to `int' in declaration of `std'|
C:\C++\Graph\testers\main.c|4|warning: data definition has no type or storage class|
C:\C++\Graph\testers\main.c|7|error: syntax error before "quit"|
C:\C++\Graph\testers\main.c|7|warning: type defaults to `int' in declaration of `quit'|
C:\C++\Graph\testers\main.c|7|warning: data definition has no type or storage class|
C:\C++\Graph\testers\main.c|14|warning: return type defaults to `int'|
C:\C++\Graph\testers\main.c||In function `WinMain':|
C:\C++\Graph\testers\main.c|17|error: `WINCLASSEX' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|17|error: (Each undeclared identifier is reported only once|
C:\C++\Graph\testers\main.c|17|error: for each function it appears in.)|
C:\C++\Graph\testers\main.c|17|error: syntax error before "ex"|
C:\C++\Graph\testers\main.c|18|error: `ex' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|20|error: `WinProc' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|34|error: `hwnd' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|42|warning: passing arg 1 of `CreateWindowExA' makes integer from pointer without a cast|
C:\C++\Graph\testers\main.c|43|error: `SM_SHOW' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|48|warning: passing arg 3 of `PeekMessageA' makes integer from pointer without a cast|
C:\C++\Graph\testers\main.c|48|warning: passing arg 4 of `PeekMessageA' makes integer from pointer without a cast|
C:\C++\Graph\testers\main.c|51|warning: implicit declaration of function `TranslateMessge'|
||=== Build finished: 10 errors, 9 warnings ===|

I went over the code a couple of times to make sure I copied everything right and it seems that I did I don't know what is wrong.

I went over this code with the default windows app code generated by dev C++ and I just see lots of errors.

For example:
Line 18: WINCLASSEX ex;
should be WNDCLASSEX ex;

Line 44: ShowWindow(handleWin, SM_SHOW);
should be ShowWindow(handleWin, nshowcmd);

Those are just a few if you want the template I have just ask and I'll post it since it isnt that long.

yes could you post that code so I can compare it my self and see what I did wrong

Sorry for the late reply.

#include <windows.h>

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

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

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)
{
    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 color 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 */
        "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, nFunsterStil);

    /* 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)
{
    switch (message)                  /* handle the messages */
    {
        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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.