<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bildschirmschoner langsamer als normales Programm]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich hab da einen Bildschirmschoner, der viel langsamer läuft als er sollte.<br />
Als normales Windows-Progamm rennt er mit Sleep(100), aber als Schoner schleicht er.</p>
<p>Woran liegt das?<br />
Hier mal der Code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include &lt;scrnsave.h&gt;

#define TIMER 1

int cxClient, cyClient, i;
POINT apt[4], sapt[4];

LONG WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

	long sec;
	time(&amp;sec);
	srand((unsigned)sec);

	HDC hdc;
	HPEN hPenRed = CreatePen(PS_SOLID, 3, RGB(150,0,0));
	HPEN hPenBlack = CreatePen(PS_SOLID, 1, RGB(0,0,0));

	hdc = GetDC(hwnd);

	switch(message) {

		case WM_CREATE:
			cxClient = GetSystemMetrics(SM_CXSCREEN);
			cyClient = GetSystemMetrics(SM_CYSCREEN);

			for(i = 0; i &lt; 4; i++) {
				apt[i].x = rand() % cxClient;
				apt[i].y = rand() % cyClient;
			}

			SetTimer(hwnd, TIMER, 1, NULL);
			break;

		case WM_TIMER:

			// Löschen
			SelectObject(hdc, hPenBlack);
			PolyBezier(hdc, sapt, 4);

			MoveToEx(hdc, sapt[0].x, sapt[0].y, NULL);
			LineTo(hdc, sapt[1].x, sapt[1].y);

			MoveToEx(hdc, sapt[2].x, sapt[2].y, NULL);
			LineTo(hdc, sapt[3].x, sapt[3].y);

			// Zeichnen
			SelectObject(hdc, hPenRed);
			PolyBezier(hdc, apt, 4);

			MoveToEx(hdc, apt[0].x, apt[0].y, NULL);
			LineTo(hdc, apt[1].x, apt[1].y);

			MoveToEx(hdc, apt[2].x, apt[2].y, NULL);
			LineTo(hdc, apt[3].x, apt[3].y);

			// Speichern
			for(i = 0; i &lt; 4; i++) sapt[i] = apt[i];

			// Zufallszahlen
			for(i = 0; i &lt; 4; i++) {
				apt[i].x = rand() % cxClient;
				apt[i].y = rand() % cyClient;
			}
			break;

		case WM_DESTROY:
			KillTimer(hwnd, TIMER);
			ReleaseDC(hwnd, hdc);
			break;
	}
	return DefScreenSaverProc(hwnd, message, wParam, lParam);
}

BOOL WINAPI ScreenSaverConfigureDialog(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

	switch(message) {
		case WM_INITDIALOG:
			return TRUE;

		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDOK:
					EndDialog(hwnd, 0);
					return TRUE;

				case IDCANCEL:
					EndDialog(hwnd, 0);
					return TRUE;
			}
			break;
	}
	return FALSE;
}

BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { return TRUE; }
</code></pre>
<p>Eine andere Version läuft übrigens mit richtiger Geschwindigkeit.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/135212/bildschirmschoner-langsamer-als-normales-programm</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 03:43:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/135212.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 31 Jan 2006 15:56:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bildschirmschoner langsamer als normales Programm on Tue, 31 Jan 2006 15:56:21 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich hab da einen Bildschirmschoner, der viel langsamer läuft als er sollte.<br />
Als normales Windows-Progamm rennt er mit Sleep(100), aber als Schoner schleicht er.</p>
<p>Woran liegt das?<br />
Hier mal der Code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include &lt;scrnsave.h&gt;

#define TIMER 1

int cxClient, cyClient, i;
POINT apt[4], sapt[4];

LONG WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

	long sec;
	time(&amp;sec);
	srand((unsigned)sec);

	HDC hdc;
	HPEN hPenRed = CreatePen(PS_SOLID, 3, RGB(150,0,0));
	HPEN hPenBlack = CreatePen(PS_SOLID, 1, RGB(0,0,0));

	hdc = GetDC(hwnd);

	switch(message) {

		case WM_CREATE:
			cxClient = GetSystemMetrics(SM_CXSCREEN);
			cyClient = GetSystemMetrics(SM_CYSCREEN);

			for(i = 0; i &lt; 4; i++) {
				apt[i].x = rand() % cxClient;
				apt[i].y = rand() % cyClient;
			}

			SetTimer(hwnd, TIMER, 1, NULL);
			break;

		case WM_TIMER:

			// Löschen
			SelectObject(hdc, hPenBlack);
			PolyBezier(hdc, sapt, 4);

			MoveToEx(hdc, sapt[0].x, sapt[0].y, NULL);
			LineTo(hdc, sapt[1].x, sapt[1].y);

			MoveToEx(hdc, sapt[2].x, sapt[2].y, NULL);
			LineTo(hdc, sapt[3].x, sapt[3].y);

			// Zeichnen
			SelectObject(hdc, hPenRed);
			PolyBezier(hdc, apt, 4);

			MoveToEx(hdc, apt[0].x, apt[0].y, NULL);
			LineTo(hdc, apt[1].x, apt[1].y);

			MoveToEx(hdc, apt[2].x, apt[2].y, NULL);
			LineTo(hdc, apt[3].x, apt[3].y);

			// Speichern
			for(i = 0; i &lt; 4; i++) sapt[i] = apt[i];

			// Zufallszahlen
			for(i = 0; i &lt; 4; i++) {
				apt[i].x = rand() % cxClient;
				apt[i].y = rand() % cyClient;
			}
			break;

		case WM_DESTROY:
			KillTimer(hwnd, TIMER);
			ReleaseDC(hwnd, hdc);
			break;
	}
	return DefScreenSaverProc(hwnd, message, wParam, lParam);
}

BOOL WINAPI ScreenSaverConfigureDialog(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

	switch(message) {
		case WM_INITDIALOG:
			return TRUE;

		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDOK:
					EndDialog(hwnd, 0);
					return TRUE;

				case IDCANCEL:
					EndDialog(hwnd, 0);
					return TRUE;
			}
			break;
	}
	return FALSE;
}

BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { return TRUE; }
</code></pre>
<p>Eine andere Version läuft übrigens mit richtiger Geschwindigkeit.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/982200</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/982200</guid><dc:creator><![CDATA[Angel of Darkness]]></dc:creator><pubDate>Tue, 31 Jan 2006 15:56:21 GMT</pubDate></item><item><title><![CDATA[Reply to Bildschirmschoner langsamer als normales Programm on Tue, 31 Jan 2006 16:04:42 GMT]]></title><description><![CDATA[<blockquote>
<p>Woran liegt das?</p>
</blockquote>
<p>Ein Bildschirmschoner läuft vom Betriebssystem wahrscheinlich einfach mit niedriger Priorität</p>
]]></description><link>https://www.c-plusplus.net/forum/post/982209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/982209</guid><dc:creator><![CDATA[Vertexwahn]]></dc:creator><pubDate>Tue, 31 Jan 2006 16:04:42 GMT</pubDate></item><item><title><![CDATA[Reply to Bildschirmschoner langsamer als normales Programm on Tue, 31 Jan 2006 16:19:34 GMT]]></title><description><![CDATA[<p>Heißt also man kann nichts machen?<br />
Aber es laufen doch nicht alle so langsam.</p>
<p>Thx</p>
]]></description><link>https://www.c-plusplus.net/forum/post/982228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/982228</guid><dc:creator><![CDATA[Angel of Darkness]]></dc:creator><pubDate>Tue, 31 Jan 2006 16:19:34 GMT</pubDate></item><item><title><![CDATA[Reply to Bildschirmschoner langsamer als normales Programm on Thu, 02 Feb 2006 22:36:21 GMT]]></title><description><![CDATA[<pre><code>[cpp]    case WM_CREATE:
        cxClient = GetSystemMetrics(SM_CXSCREEN);
        cyClient = GetSystemMetrics(SM_CYSCREEN);

        for(i = 0; i &lt; 4; i++) {
            apt[i].x = rand() % cxClient;
            apt[i].y = rand() % cyClient;
        }

        [b]SetTimer(hwnd, TIMER, [u]1[/u], NULL);[/b]
        break;
[/cpp]
</code></pre>
<p>is das so gewollt, das dein timer-proc 1000mal pro sekunde aufgerufen wird? reicht da nich auch 100mal? oder 10mal?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/984619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/984619</guid><dc:creator><![CDATA[hebbele]]></dc:creator><pubDate>Thu, 02 Feb 2006 22:36:21 GMT</pubDate></item></channel></rss>