Window form not working

Si I try hard to get windows form for my OpenGL project. Don't ask me why I don't use libraries(it's a self challenge)

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <Windows.h>
#include <tchar.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hInstancePrev, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wcex;
	HWND window;
	TCHAR ClassName[] = _T("OpenGL");

	int width = 640, height = 480;

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

	if (!RegisterClassEx(&wcex))
		return 1;

	window = CreateWindowEx(0, ClassName, _T("openGl test"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, hInstance, NULL);

	ShowWindow(window, nCmdShow);

	if (!window)
	{
		MessageBox(NULL,
			_T("Call to CreateWindow failed!"),
			_T("Win32 Guided Tour"),
			NULL);

		return 1;
	}


	return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_CLOSE:
		PostQuitMessage(0);
		break;
	case WM_DESTROY:
		return 0;
		case WM_KEYDOWN:
		{
			switch (wParam)
			{
			case VK_ESCAPE:
				PostQuitMessage(0);
				break;
			}
		}
	}

	return 0;
}

so I don't get why I get error fro:

[code]
	if (!window)
	{
		MessageBox(NULL,
			_T("Call to CreateWindow failed!"),
			_T("Win32 Guided Tour"),
			NULL);

		return 1;
	}
 


why does this dialog is showing up
You need to add return DefWindowProc(hwnd, uMsg, wParam, lParam); at the end of your WndProc instead of returning 0. You return TRUE or FALSE only for messages you have handled.
you are right! But I don't get why in visual studio 2015 worked this was, and in vs 2017 it didn't.
Actually on my VS 2015 CE Win7 64bit it didn't work.
Ahhh, no! all I forgot to do was to add a default that return what you said, sorry.
Topic archived. No new replies allowed.