#include
<windows.h>
#include<iostream>
#include<string>
#include<cstring>
using
namespace std;
int zaehl=0;
int mauszaehl=0;
int R_mauszaehl=0;
int D_mauszaehl=0;
LRESULT CALLBACK WndProc (HWND,
UINT, WPARAM, LPARAM) ;
int
WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance, //WINAPI=Konstante
PSTR szCmdLine,
int iCmdShow) //HINSTANCE=typedef in header
{
static char szAppName[] = "HelloWin" ;
HWND hwnd ; //Objekte von Strukturen
MSG msg ;
WNDCLASSEX wndclass ;
iCmdShow = 5; //bestimmt Positionierung beim Fensteröffnen
wndclass.cbSize
= sizeof (wndclass)
; //Der
ges. Block legt fest, wie mein
wndclass.style
= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; //Fenster aussieht
wndclass.lpfnWndProc
= WndProc ; //Zeiger
auf Fkt: Fensterprozedur
wndclass.cbClsExtra
= 0 ; //für
dieses Fenster
wndclass.cbWndExtra
= 0 ;
wndclass.hInstance
= hInstance ;
wndclass.hIcon
= LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor
= LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject
(LTGRAY_BRUSH) ; //(HBRUSH) ist typecast
wndclass.lpszMenuName = NULL ; //Zeiger für Menüleiste
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm
= LoadIcon (NULL, IDI_WINLOGO) ;
RegisterClassEx (&wndclass) ;
hwnd
= CreateWindow (szAppName, // window class name
"Begrüßungsprogramm", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow)
;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0,
0)) //Nachricht von Windows wird verarbeitet
{
TranslateMessage (&msg) ; //Nachricht übersetzen
DispatchMessage (&msg) ; //Nachricht verteilen
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT
rect ;
int l, b, c, d, e, f;
char text[20], anz_mess[100],
mauz[100], r_mauz[100], d_mauz[100];
switch (iMsg)
{
case
WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
zaehl++;
GetClientRect (hwnd, &rect) ;
TextOut(hdc, 25, 20, "Klaus Weyell",
strlen("Klaus Weyell"));
TextOut(hdc, 25, 50, "Wendelinusstr.6", strlen("Wendelinusstr.6"));
TextOut(hdc, 25, 80, "53489 Sinzig", strlen("53489
Sinzig"));
TextOut(hdc, 25, 110, "Tel.: 02642 - 41161", strlen("Tel.: 02642 - 41161"));
l = sprintf(text,
"Länge: %d", rect.bottom);
TextOut(hdc, 25, 140, text, l);
b = sprintf(text,
"Breite: %d", rect.right);
TextOut(hdc, 25, 170, text, b);
c = sprintf(anz_mess, "Das Fenster wurde %d mal neu
gezeichnet.", zaehl);
TextOut(hdc, 25, 200, anz_mess, c);
d=sprintf(mauz, "Die linke Maustaste wurde %d mal
gedrückt.", mauszaehl);
TextOut(hdc, 25, 230, mauz, d);
e=sprintf(r_mauz, "Die rechte Maustaste wurde %d mal
gedrückt.", R_mauszaehl);
TextOut(hdc, 25, 260, r_mauz, e);
f=sprintf(d_mauz, "Doppelklick(links): %d ", D_mauszaehl);
TextOut(hdc, 25, 290, d_mauz, f);
EndPaint (hwnd, &ps) ;
return
0 ;
case WM_LBUTTONDOWN:
mauszaehl++;
InvalidateRect(hwnd, NULL, true);
return 0;
case WM_RBUTTONDOWN:
R_mauszaehl++;
InvalidateRect(hwnd, NULL, true);
return 0;
case
WM_LBUTTONDBLCLK:
D_mauszaehl++;
InvalidateRect(hwnd, NULL, true);
return 0;
case
WM_DESTROY :
PostQuitMessage
(0) ;
return
0 ;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam)
;
}