Here is the source code to SampleDepth.p:
Program DepthSample(input,output);
Uses
Toolbox, DepthLib;
Const
kMillions = 2;
kThousands = 3;
k256 = 4;
k16 = 5;
k4 = 6;
k2 = 7;
kColor = 8;
kGray = 9;
Procedure SetRadioItem(dlog: DialogPtr; itemNum: integer; on: boolean);
Var
iType: integer;
iHandle: Handle;
iRect: Rect;
begin
GetDialogItem(dlog,itemNum,iType,iHandle,iRect);
if on then
SetControlValue(ControlHandle(iHandle),1)
else
SetControlValue(ControlHandle(iHandle),0);
end;
Procedure DisableDItem(dlog: DialogPtr; itemNum: integer);
Var
iType: integer;
iHandle: handle;
iRect: rect;
begin
GetDialogItem(dlog,itemNum,iType,iHandle,iRect);
HiliteControl(ControlHandle(iHandle),255);
end;
Procedure SampleWindow;
Var
d: DialogPtr;
g: GrafPtr;
hit: integer;
depthItem: integer;
modeItem: integer;
Procedure ChangeDepth(newItem: integer;
dlg: dialogPtr;
depth: integer);
begin
SetRadioItem(dlg,depthItem,FALSE);
depthItem := newItem;
SetRadioItem(dlg,depthItem,TRUE);
SetScreenDepth(GetMainDevice,depth);
end;
Procedure ChangeMode(newItem: integer;
dlg: dialogPtr;
mode: integer);
begin
SetRadioItem(dlg,modeItem,FALSE);
modeItem := newItem;
SetRadioItem(dlg,modeItem,TRUE);
SetScreenMode(GetMainDevice,mode);
end;
begin
d := GetNewDialog(128, nil, WindowPtr(-1));
if d = NIL then
exit(SampleWindow);
GetPort(g);
SetPort(d);
{-------------------------------------------------------------------}
{ find the maximum depth of main monitor, and disable radio items. }
{ The C version had a strange bug... it showed my current depth as }
{ 256, but only enabled a depth of 2. To ensure that depths are }
{ enabled properly, I examine each depth individually. }
{-------------------------------------------------------------------}
if not SupportsDepth(GetMainDevice, k2Colors) then
DisableDItem(d, k2);
if not SupportsDepth(GetMainDevice, k4Colors) then
DisableDItem(d, k4);
if not SupportsDepth(GetMainDevice, k16Colors) then
DisableDItem(d, k16);
if not SupportsDepth(GetMainDevice, k256Colors) then
DisableDItem(d, k256);
if not SupportsDepth(GetMainDevice, kThousandsColors) then
DisableDItem(d, kThousands);
if not SupportsDepth(GetMainDevice, kMillionsColors) then
DisableDItem(d, kMillions);
{-----------------------------------------}
{ get the current depth and set the }
{ appropriate radio item. }
{-----------------------------------------}
case GetScreenDepth(GetMainDevice) of
k2Colors: depthItem := k2;
k4Colors: depthItem := k4;
k16Colors: depthItem := k16;
k256Colors: depthItem := k256;
kThousandsColors: depthItem := kThousands;
kMillionsColors: depthItem := kMillions;
{CASE} end;
SetRadioItem(d,depthItem,TRUE);
{-----------------------------------------}
{ figure out which modes are supported }
{ and disable radio items }
{-----------------------------------------}
if not SupportsMode(GetMainDevice,kColorMode) then
DisableDItem(d,kColor);
if not SupportsMode(GetMainDevice,kGrayMode) then
DisableDItem(d,kGray);
{-----------------------------------------}
{ get current mode and set appropriate }
{ radio item }
{-----------------------------------------}
case GetScreenMode(GetMainDevice) of
kGrayMode: modeItem := kGray;
kColorMode: modeItem := kColor;
{CASE} end;
SetRadioItem(d,modeItem,TRUE);
ShowWindow(d);
repeat
ModalDialog(NIL, hit);
case hit of
k2: ChangeDepth(k2,d,k2Colors);
k4: ChangeDepth(k4,d,k4Colors);
k16: ChangeDepth(k16,d,k16Colors);
k256: ChangeDepth(k256,d,k256Colors);
kThousands: ChangeDepth(kThousands,d,kThousandsColors);
kMillions: ChangeDepth(kMillions,d,kMillionsColors);
kGray: ChangeMode(kGray,d,kGrayMode);
kColor: ChangeMode(kColor,d,kColorMode);
otherwise;
{CASE} end;
until hit = 1;
SetPort(g);
DisposeDialog(d);
end;
{---------------}
{ Main Program }
{---------------}
begin
InitToolbox;
FlushEvents(everyEvent, 0);
SampleWindow;
end.