Bildschirmschoner langsamer als normales Programm
-
Hi,
Ich hab da einen Bildschirmschoner, der viel langsamer läuft als er sollte.
Als normales Windows-Progamm rennt er mit Sleep(100), aber als Schoner schleicht er.Woran liegt das?
Hier mal der Code:#include <windows.h> #include <stdlib.h> #include <time.h> #include <scrnsave.h> #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(&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 < 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 < 4; i++) sapt[i] = apt[i]; // Zufallszahlen for(i = 0; i < 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; }Eine andere Version läuft übrigens mit richtiger Geschwindigkeit.
-
Woran liegt das?
Ein Bildschirmschoner läuft vom Betriebssystem wahrscheinlich einfach mit niedriger Priorität
-
Heißt also man kann nichts machen?
Aber es laufen doch nicht alle so langsam.Thx
-
[cpp] case WM_CREATE: cxClient = GetSystemMetrics(SM_CXSCREEN); cyClient = GetSystemMetrics(SM_CYSCREEN); for(i = 0; i < 4; i++) { apt[i].x = rand() % cxClient; apt[i].y = rand() % cyClient; } [b]SetTimer(hwnd, TIMER, [u]1[/u], NULL);[/b] break; [/cpp]is das so gewollt, das dein timer-proc 1000mal pro sekunde aufgerufen wird? reicht da nich auch 100mal? oder 10mal?