the new guy

Usually I make console programs but I'm looking into windows programming but my programs just aren't working. Can someone tell me what's wrong with this program.
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
#include <windows.h>
LRESULT CALLBACK WindowProcedure
(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam);
class WinClass
{
public:
WinClass (WNDPROC winProc, char const * className, HINSTANCE hInst);
void Register ()
{
::RegisterClass (&_class);
}
private:
WNDCLASS _class;
};
WinClass::WinClass
(WNDPROC winProc, char const * className, HINSTANCE hInst)
{
_class.style = 0;
_class.lpfnWndProc = winProc;
_class.cbClsExtra = 0;
_class.cbWndExtra = 0;
_class.hInstance = hInst;
_class.hIcon = 0;
_class.lpszMenuName = 0;
_class.lpszClassName = className;
}
Last edited on
It does nothing because there is no WinMain function and the WindowProcedure function is also not defined...?


http://www.winprog.org/tutorial/simple_window.html
Hello,

If you want to write a programme with WinAPI, then I will be glad to show the example for you.

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
84
85
86
#define  UNICODE
#define _UNICODE

#include <windows.h>
#include <tchar.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

INT WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE, PTSTR pszCmd, INT iSc)
{
	MSG msg;
	HWND hWnd;
	WNDCLASSEX wnd;

	wnd.cbSize		= sizeof(wnd);
	wnd.cbClsExtra		= NULL;
	wnd.cbWndExtra		= NULL;
	wnd.hbrBackground	= (HBRUSH)GetStockObject(WHITE_BRUSH);
	wnd.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wnd.hIcon		= LoadIcon(NULL, IDI_WINLOGO);
	wnd.hIconSm		= LoadIcon(NULL, IDI_WINLOGO);
	wnd.hInstance		= hInst;
	wnd.lpfnWndProc		= WndProc;
	wnd.lpszClassName	= _T("My_class_name");
	wnd.lpszMenuName	= NULL;
	wnd.style		= CS_HREDRAW | CS_VREDRAW;

	if(!RegisterClassEx(&wnd))
	{
		// Error ...
		// MessageBox(NULL, _T("ERROR #1"), _T("Error"), MB_ICONSTOP | MB_OK);
		return FALSE;
	}

	hWnd = CreateWindowEx(NULL, _T("My_class_name"), _T("WinAPI Programme"), WS_OVERLAPPEDWINDOW, 200, 200, 500, 300, 0, 0, hInst, 0);

	if(!hWnd)
	{
		// Error ...
		// MessageBox(NULL, _T("ERROR #2"), _T("Error"), MB_ICONSTOP | MB_OK);
		return FALSE;
	}

	ShowWindow(hWnd, iSc);

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

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HDC hDC;
	PAINTSTRUCT ps;
	static RECT rect;

	switch(uMsg)
	{
	case WM_PAINT:
		hDC = BeginPaint(hWnd, &ps);
		DrawText(hDC, _T("Hello Win32 world ! :)"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
		EndPaint(hWnd, &ps);	
		break;

	case WM_SIZE:
		GetClientRect(hWnd, &rect);
		break;

	case WM_CLOSE:
		DestroyWindow(hWnd);
		break;

	case WM_DESTROY:
		PostQuitMessage(NULL);
		break;

	default:
		return DefWindowProc(hWnd, uMsg, wParam, lParam);
	}

	return FALSE;
}
Last edited on
Topic archived. No new replies allowed.