Win32 HDC issue

someone 20 Reputation points
2024-11-06T21:47:39.6033333+00:00

I have a problem with drawing HDC outside WM_PAINT message, I draw in function with while(true) loop

void quadcycle() 
{
	while(true) 
	{
		hdc = GetDC(hwnd);
		RECT rc = {50,50,150,150};
		FillRect(hdc, &rc, (HBRUSH)CreateSolidBrush(RGB(255,0,std::time(NULL)*2 % 255 ))) );
		ReleaseDC(hwnd,hdc);
	}
}

To make the square change color with time, but instead of changing color I saw my square disappear :(

I checked all the places and realized that it is because of this loop, but I just slow down the loop to make it disappear a little later.

Please help, I am new to win32 development.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,666 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.