Changing graphics mode

Boolean SetScreenColorDepth(int depth)
{
    UInt16 reqDepth=depth;
    Err err = WinScreenMode(winScreenModeSet,NULL,NULL,&reqDepth,NULL);
    return !err;
}

Boolean RestoreScreenColorDepth(void)
{
    Err err = WinScreenMode(winScreenModeSetToDefaults,NULL,NULL,NULL,NULL);
    return !err;
}

You must set color depth before any window is created. Check error codes for unsupported modes.

Displaying an alert window

resource – .h file:

#define CustomAlert 1000

resource – .rcp file:

ALERT ID CustomAlert
BEGIN
  TITLE "custom alert"
  MESSAGE "^1\n^2\n^3"
  BUTTONS "OK"
END

code:

Char alertMsg[64];
StrPrintF(alertMsg, "Your value is %d", yourValue);
FrmCustomAlert(CustomAlert, alertMsg, "", "");

do NOT pass NULL value as param in FrmCustomAlert – always use ””.

Double buffering

This is an example, how to do and use double buffering (offscreen window) to create smooth animations

WinHandle displayWindow;
WinHandle offscreenWindow;

void CreateOffScreen() {
    Err err;
    offscreenWindow = WinCreateOffscreenWindow(160,160, screenFormat, &err);
}

void PaintOffScreen() {
    WinSetDrawWindow(offscreenWindow);
    // draw there
}

void Show() {
    RectangleType bounds;

    WinSetDrawWindow(displayWindow);
    WinGetBounds(displayWindow, &bounds);
    WinCopyRectangle (offscreenWindow, 0, &bounds, 0, 0, 0);
}