creating windows

Hello, I've been looking at making windows, but I don't understand it fully. Is there some tutorial on youtube / this forum ( I have searched) or yourself that can explain every line to me?
Hi,

There are plenty of resources available on internet related to GUI programming a prime and great example would be :[i]"forgers WinAPI"[/o]

Link: http://www.winprog.org/tutorial/

Sorry, but I am not going to give source code because it is all in the Link given.

Good Luck!
I don't understand this:

1
2
3
WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

How can this set the windows stuff when it's not passed through the function? Wouldn't it value to 0? and only make the window 0 (if you have more than one window it would only make the first one)?


EDIT: HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
I also don't understand the LPAram etc
Last edited on
Did this (Tried to re write the code to understand it)
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
62
63
64
65
66
67
#include <Windows.h>

//global class name
const char WindowC[] = "WindowsClass";


//this handles everything you do to the window (clicking etc)
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg) {

		//skype is a fegget
		case WM_CLOSE: MessageBox(NULL, "NO!", NULL, NULL);

	}

	return 0;
}

//the main function
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX window;//object
	HWND hwnd;//the handle
	MSG msg;//the message

	window.cbSize        = sizeof(WNDCLASSEX);
    window.style         = 0;
    window.lpfnWndProc   = WndProc;
    window.cbClsExtra    = 0;
    window.cbWndExtra    = 0;
    window.hInstance     = hInstance;
    window.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    window.hCursor       = LoadCursor(NULL, IDC_ARROW);
    window.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    window.lpszMenuName  = NULL;
    window.lpszClassName = WindowC;
    window.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

	if(!RegisterClassEx(&window))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

	hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WindowC, "Hello", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, hInstance, NULL);

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }


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

	return msg.wParam;
}


But it always says window creation failed.
SpaceWorm gave you good advice. If you followed it, you would understand why your window creation is failing.
Registered users can post here. Sign in or register to post.