Please help With this Win API error

I am following a tutorial: http://pravin.insanitybegins.com/win32/lesson2

And i am doing exactly what he is, i am not copying and pasting i am actually typing out all of the code but i get these errors

C:\Users\Chay\Desktop\DrawLite\main.cpp||In function 'int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':|
C:\Users\Chay\Desktop\DrawLite\main.cpp|50|error: a function-definition is not allowed here before '{' token|
C:\Users\Chay\Desktop\DrawLite\main.cpp|61|error: expected '}' at end of input|
||=== Build finished: 2 errors, 0 warnings ===|


CODE;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <windows.h>

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE thisInst, HINSTANCE prevInst, LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    HWND hwnd;
    WNDCLASSEX wcx;

    wcx.cbSize = sizeof(WNDCLASSEX);
    wcx.style = CS_DBLCLKS;
    wcx.lpfnWndProc = MainWndProc;
    wcx.cbClsExtra = 0;
    wcx.cbWndExtra = 0;
    wcx.hInstance = thisInst;
    wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcx.hCursor = LoadCursor(NULL, IDC_HAND);
    wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    wcx.lpszMenuName = NULL;
    wcx.lpszClassName = "Program";
    wcx.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

        if(!RegisterClassEx(&wcx))
        {
            return 0;
        }

        hwnd = CreateWindowEx(0, "Program",
                              "This is a windows Api program",
                              WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
                              CW_USEDEFAULT, 500, 400, HWND_DESKTOP, NULL, thisInst, NULL);

        if(!hwnd)
        {
            return 0;
        }

        ShowWindow(hwnd, SW_SHOW);

        while(GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        return msg.wParam;

        LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
        {
            switch(msg)
            {
                case WM_DESTROY:
                    PostQuitMessage(0);
                    break;
                default:
                    return DefWindowProc(hwnd, msg, wParam, lParam);
            }
            return 0;
        }
}
You are writing the definition of MainWndProc() inside your WinMain()'s definition.

Cut lines 49-60 and paste them after the closing bracket '}' of your WinMain() (which is currently in line 61).
Last edited on
Awesome thank you for the help :)
Topic archived. No new replies allowed.