Q
//aufgabe3.cpp (by) Matthias Walter
#include <windows.h>
#include <string>
using namespace std;
HDC dc;
MSG n;
static int x, y;
//static char a='A';
LRESULT CALLBACK Fensterfunktion(HWND hwnd,UINT message,
WPARAM wparam, LPARAM lparam) {
switch(message) {
case WM_LBUTTONDOWN:
x=LOWORD(lparam);
y=HIWORD(lparam);
dc=GetDC (hwnd);
if (dc != NULL)
{ // <- neuer Code-Block
TCHAR szBuffer[100]; // vor der iteration
for (;x<=500,y<=500;x=x+20,y=y+20,a++)
{
_stprintf(szBuffer, _T("%d"), a);
TextOut(hDc, x, y, szBuffer, _tcslen(szBuffer));
} // end for
} // end if
//TextOut (dc,x,y,a,1);
ReleaseDC(hwnd,dc);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
}
HDC GEtDC(HWND hwnd);
int Release(HWND hwnd, HDC dc);
int WINAPI WinMain(HINSTANCE dieseInstanz,HINSTANCE
vorigeInstanz,LPSTR t, int d) {
HWND f;
char szAppName[]="Eine neue Fensterklasse";
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW ;
wc.lpfnWndProc = Fensterfunktion;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = dieseInstanz;
wc.hIcon = LoadIcon(NULL, IDI_HAND);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground= CreateSolidBrush(RGB(255,255,255));
wc.lpszMenuName = NULL;
wc.lpszClassName= szAppName;
if (!RegisterClass(&wc)) {
return 0;
};
f = CreateWindow ( szAppName,
"Wir experimentieren",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100,
150,
600,
500,
NULL,
NULL,
dieseInstanz,
NULL);
while (GetMessage(&n,NULL,0,0) ) {
DispatchMessage(&n);
};
return n.wParam;
}
Du hast immer wieder TCHAR szBuffer[100] in der for-Schleife angelegt, und dann einmal den Wert von a in den String kopiert.
Schau dir den Code oben mal an.