letavino
Goto Top

Fenster wird nicht neu gezeichnet

Hallo,
ich bin gerade dabei, mich in WinAPI und C++ einzuarbeiten.
Dabei hab ich folgendes Problem:

Ich habe einen Quellcode aus einem Tutorial abgewandelt, um zu sehen, ob ich alles verstanden habe.
Dabei soll in meinem Programm nichts weiter passieren, als dass ein Kreis von links nach rechts fährt.
Das ganze funktioniert soweit auch, wie man sehen kann, wenn man das Fenster in der Größe verändert,
nur wird es nicht von alleine neu gezeichnet.

Woran liegt das? Was fehlt in meinem Code noch?

#include <windows.h>
#include <math.h>

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

#define ID_ERSTER_TIMER 1

wchar_t szAppName = L"Ball'";  

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	MSG		msg;
	HWND		hWnd;
	WNDCLASS	wc;

	wc.cbClsExtra		= 0;
	wc.cbWndExtra		= 0;
	wc.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.hCursor			= LoadCursor(NULL, IDC_CROSS);
	wc.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wc.hInstance		= hInstance;
	wc.lpfnWndProc		= WndProc;
	wc.lpszClassName	= szAppName;
	wc.lpszMenuName		= NULL;
	wc.style			= CS_HREDRAW | CS_VREDRAW;

	RegisterClass(&wc);

	hWnd = CreateWindow( szAppName,
						 szAppName,
						 WS_OVERLAPPEDWINDOW,
						 CW_USEDEFAULT,
						 CW_USEDEFAULT,
						 CW_USEDEFAULT,
						 CW_USEDEFAULT,
						 NULL,
						 NULL,
						 hInstance,
						 NULL);

	ShowWindow(hWnd, iCmdShow);
	UpdateWindow(hWnd);

	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static RECT		rect;
	static double	horizontal;

	switch(message)
	{
		case WM_CREATE:
		{
			SetTimer(hWnd, ID_ERSTER_TIMER, 10, NULL);
			return 0;
		}

		case WM_SIZE:
		{
			rect.right	= LOWORD(lParam);
			rect.bottom	= HIWORD(lParam);
			return 0;
		}

		case WM_PAINT:
		{
			PAINTSTRUCT	ps;
			HDC			hDC;

			hDC = BeginPaint(hWnd, &ps);


			{
				HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, CreateSolidBrush(RGB(0,0,255)));

				Ellipse(hDC, 0+horizontal,50,50+horizontal,100); //links, oben, rechts, unten

				DeleteObject(SelectObject(hDC,hOldBrush));
			}
			EndPaint(hWnd, &ps);
			return 0;
		}

		case WM_TIMER:
		{
			switch(wParam)
			{
				case ID_ERSTER_TIMER:
				{
					RECT InvalRect;

					horizontal += 5;
				
					InvalRect.left	=	 0 + horizontal		-50;
					InvalRect.top	=	50			-50;
					InvalRect.right =	50 + horizontal	+50;
					InvalRect.left	=	100			+50;

					InvalidateRect(hWnd, &InvalRect, TRUE);

					break;
				}
			}
			return 0;
		}

		case WM_DESTROY:
		{
			KillTimer(hWnd, ID_ERSTER_TIMER);
			PostQuitMessage(0);
			return 0;
		}
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}

Content-Key: 179256

Url: https://administrator.de/contentid/179256

Printed on: April 26, 2024 at 05:04 o'clock

Member: Letavino
Letavino Jan 20, 2012 at 11:47:55 (UTC)
Goto Top
Ok, hat sich Erledigt.
Der Fehler lag in Zeile 104, da ich versehentlich statt Bottom, top geschrieben hatte.

Mfg