Files
Claude 2f22c4304a Add the screen saver library, ShellAbout and sockets on the classic Mac OS
scrnsave.h with libscrnsave.a and libscrnsavw.a: the SDK's WinMain for
screen savers (/s, /p, /c), DefScreenSaverProc and the library's
strings. tests/sstest.cpp runs a screen saver on Linux, macOS and the
classic Mac OS simulators. ShellAbout shows the shell's about box in a
message box.

The classic Mac OS build now has Winsock, WinInet, CAsyncSocket and the
internet classes, over mac-sdk's sockets. Two fixes let the Winsock
event thread run beside the program there: the Toolbox event loop
yields to other threads before each event, and the event thread waits a
little when a socket is ready but its event is posted already, instead
of polling it again at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRTDFNgD4oK9xbDsEGn
2026-11-25 17:17:46 +00:00

73 lines
2.5 KiB
C++

// sstest.cpp - a screen saver over scrnsave.h, run with /s: the library's
// WinMain makes the window over the whole screen, a timer draws, and a
// key press (sent by the test) closes it through DefScreenSaverProc.
// Linked with libscrnsave.a (libscrnsavw.a for UNICODE).
#include <windows.h>
#include <scrnsave.h>
#include <stdio.h>
#include <string.h>
static int g_failures = 0;
static int g_ticks = 0;
#define CHECK(cond) \
do { \
if (!(cond)) { \
printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
g_failures++; \
} \
} while (0)
// Draws a few lines, and after three ticks presses a key, which must
// close the screen saver.
LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_CREATE: {
CHECK(!fChildPreview);
CHECK(hMainInstance != NULL);
CHECK(lstrcmp(szName, TEXT("Test Saver")) == 0);
SetTimer(hwnd, 1, 20, NULL);
return 0;
}
case WM_TIMER: {
RECT r;
GetClientRect(hwnd, &r);
if (g_ticks == 0) {
CHECK(hwnd == hMainWindow);
CHECK(r.right == GetSystemMetrics(SM_CXSCREEN) && r.bottom == GetSystemMetrics(SM_CYSCREEN));
}
HDC dc = GetDC(hwnd);
HPEN pen = CreatePen(PS_SOLID, 1, RGB(255, 255, 0));
HGDIOBJ old = SelectObject(dc, pen);
MoveToEx(dc, 0, g_ticks * 10, NULL);
LineTo(dc, r.right, r.bottom - g_ticks * 10);
SelectObject(dc, old);
DeleteObject(pen);
ReleaseDC(hwnd, dc);
if (++g_ticks == 3) PostMessage(hwnd, WM_KEYDOWN, VK_SPACE, 0);
CHECK(g_ticks <= 4);
return 0;
}
case WM_DESTROY:
KillTimer(hwnd, 1);
CHECK(g_ticks >= 3);
printf("%s: %d failure(s)\n", g_failures ? "FAIL" : "PASS", g_failures);
fflush(stdout);
PostQuitMessage(g_failures ? 1 : 0);
return 0;
}
return DefScreenSaverProc(hwnd, msg, wp, lp);
}
// The configuration dialog: OK closes it.
BOOL WINAPI ScreenSaverConfigureDialog(HWND dlg, UINT msg, WPARAM wp, LPARAM) {
if (msg == WM_INITDIALOG) return TRUE;
if (msg == WM_COMMAND && (LOWORD(wp) == IDOK || LOWORD(wp) == IDCANCEL)) {
EndDialog(dlg, LOWORD(wp));
return TRUE;
}
return FALSE;
}
// No classes for the configuration dialog.
BOOL WINAPI RegisterDialogClasses(HANDLE) { return TRUE; }