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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#include<windows.h>
//Prototype of Callback-Function
LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//Main Program
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpcmdline, int ncmdshow)
{
WNDCLASSEX windowclass; //Structure for Windowsettings
HWND hWnd; //Window-Handle
MSG message; //Message
//The Classname of the Window is free to choose
const TCHAR szClassName[] = TEXT("Standard Window");
//Fill in Structures with your Settings
//Buffer size of Structure
windowclass.cbSize = sizeof (WNDCLASSEX);
//Redraw Window if moved
windowclass.style = CS_HREDRAW | CS_VREDRAW;
//Pointer on Callback-Function
windowclass.lpfnWndProc = WindowProc;
//More Settings
windowclass.cbClsExtra;
windowclass.cbWndExtra;
//Save Intstance
windowclass.hInstance = hInst;
//Set Icons and Cursors
windowclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
windowclass.hIconSm = LoadIcon (NULL, IDI_WINLOGO);
windowclass.hCursor = LoadIcon (NULL, IDC_WAIT);
//Set Background Colour
windowclass.hbrBackground = (HBRUSH)COLOR_BACKGROUND+1;
//Menue
windowclass.lpszMenuName = NULL;
//Class Name
windowclass.lpszClassName = szClassName;
//Register Windowclass
if (!RegisterClassEx (&windowclass) )
return (0);
//CreateWindow
hWnd = CreateWindowEx (NULL,
szClassName,
TEXT("Das erste Fenster"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100,
300, 250,
NULL,
NULL,
hInst,
NULL);
//Check, if all worked
if (hWnd == NULL)
return (0);
//"Heartbeat" of Program,
//All Messages will be fetched,
//translated and redirected here.
while (GetMessage (&message, NULL, 0, 0) )
{
TranslateMessage (&message);
DispatchMessage (&message);
}
//End Program
return(int)(message.wParam);
}//WinMain
//Callback-Function for Message Processing
//
LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//Analysing Message
switch (message)
{
//Closing Window
case WM_DESTROY:
{
//Send Message to end
PostQuitMessage (0);
return(0);
}
//Key was pressed
case WM_KEYDOWN:
{
//Switching for each Key pressed
switch (wParam)
{
//"Esc" was pressed
case VK_ESCAPE:
{
//Send Message to end
PostQuitMessage (0);
return (0);
}
}
} break;
}
//Messages which are not processed by the user
//will be processed by Windows
return (DefWindowProc (hWnd, message, wParam, lParam) );
} //WindowProc
|