Here's a sample that uses a thread.
Put the following function in any Win32 application:
You start the thread using the following code:Code:DWORD WINAPI MyThread(LPVOID lpParameter) { HDC hdc; SIZE s; s.cx = ::GetSystemMetrics(SM_CXSCREEN); s.cy = ::GetSystemMetrics(SM_CYSCREEN); int x, y, z, r, g, b; HBRUSH hbr, hbrOld; while(TRUE) { x = s.cx * rand() / RAND_MAX; // position x y = s.cy * rand() / RAND_MAX; // position y z = 100 * rand() / RAND_MAX; // radius r = 255 * rand() / RAND_MAX; // red color componennt g = 255 * rand() / RAND_MAX;// green color component b = 255 * rand() / RAND_MAX;// blue color component hbr = ::CreateSolidBrush(RGB(r,g,b)); hdc = ::GetDCEx(NULL, 0, 0); hbrOld = (HBRUSH) ::SelectObject(hdc, hbr); ::Ellipse(hdc, x - z, y - z, x + z, y + z); ::SelectObject(hdc, hbrOld); ::DeleteObject(hbr); ::ReleaseDC(NULL, hdc); ::Sleep(20); } }
This line can be antwhere in the Win32 application, just make sure it's in a place where it will be excuted exactly once (you can place it in the InitInstance function).Code:::CreateThread(0, 0, MyThread, 0, 0, 0);
It will fill the whole screen with colorfull circles.




Reply With Quote