home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-pascal / macintoshp-1.2-demos.sit.hqx / chap09pascal_demo / GDevicePascal.p next >
Text File  |  1996-12-24  |  4KB  |  153 lines

  1. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  2. // GDevicePascal.p
  3. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  4. // 
  5. // This program opens a small window, gets a handle to the GDevice record for the main
  6. // device and displays some information obtained from that record.
  7. //
  8. // The program will run only on Macintoshes with Color QuickDraw.
  9. //
  10. // The program utilizes an 'ALRT' resource, a 'DITL' resource, and a 'WIND' resource.
  11. //
  12. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  13.  
  14. program GDevicePascal(input,  output);
  15.  
  16. { ………………………………………………………………………………………………………………… include the following Universal Interfaces }
  17.  
  18. uses
  19.  
  20.     Windows, Fonts, Menus, TextEdit, Quickdraw, Dialogs, QuickdrawText, Processes, Types, 
  21.     Events, TextUtils, ToolUtils, Devices, GestaltEqu, LowMem, Segload;
  22.  
  23. { ………………………………………………………………………………………………………………………………………………… define the following constants }
  24.  
  25. const
  26.  
  27. rAlert = 128;
  28. rWindow = 128;
  29.  
  30. { ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
  31.  
  32. var
  33.  
  34.     theErr, ignored : OSErr;
  35.     response : longint;
  36.     myWindowPtr : WindowPtr;
  37.     deviceHdl : GDHandle;
  38.     deviceType,  bytesPerRow : integer;
  39.     theRect : Rect;
  40.     theString : string;
  41.     pixMapHdl : PixMapHandle;
  42.  
  43. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ start of main program }
  44.  
  45. begin
  46.  
  47.     { …………………………………………………………………………………………………………………………………………………………………… initialize managers }
  48.  
  49.     InitGraf(@qd.thePort);
  50.     InitFonts;
  51.     InitWindows;
  52.     InitMenus;
  53.     TEInit;
  54.     InitDialogs(nil);
  55.     InitCursor;
  56.     
  57.     { …………………………………………………………………………………………………………………………………………………… check for Color QuickDraw }
  58.     
  59.     theErr := Gestalt(gestaltQuickdrawVersion, response);
  60.     if (response < gestalt8BitQD) then
  61.         begin
  62.         ParamText('This program will run only on Macintoshes with Color QuickDraw', 
  63.                         '', '', '');
  64.         ignored := StopAlert(rAlert, nil);
  65.         ExitToShell;
  66.         end;
  67.  
  68.     { …………………………………………………………………………………………………………………………………………………………………………………… open a window }
  69.  
  70.     myWindowPtr := GetNewWindow(128, nil, WindowPtr(-1));
  71.     if (myWindowPtr = nil) then
  72.         ExitToShell;
  73.  
  74.     SetPort(myWindowPtr);
  75.     TextSize(10);
  76.  
  77.     { ………………………………………………………………………………………………… get handle to GDevice record for main device }
  78.  
  79.     deviceHdl := LMGetMainDevice;
  80.  
  81.     { …………………………………………………………………………………………… print some information from the GDevice record }
  82.  
  83.     MoveTo(10, 20);
  84.     deviceType := deviceHdl^^.gdType;
  85.     case (deviceType) of
  86.  
  87.         0:    begin
  88.             DrawString('Indexed device with variable CLUT.');
  89.             end;
  90.  
  91.         1:    begin
  92.             DrawString('Indexed device with fixed CLUT.');
  93.             end;
  94.  
  95.         2:    begin
  96.             DrawString('Direct device.');
  97.             end;
  98.         
  99.         end;
  100.             {of case statement}
  101.  
  102.     MoveTo(10, 40);
  103.     theRect := deviceHdl^^.gdRect;
  104.     DrawString('Boundary rectangle top = ');;
  105.     NumToString(longint(theRect.top), theString);
  106.     DrawString(theString);
  107.  
  108.     MoveTo(10, 55);
  109.     DrawString('Boundary rectangle left = ');;
  110.     NumToString(longint(theRect.left), theString);
  111.     DrawString(theString);
  112.  
  113.     MoveTo(10, 70);
  114.     DrawString('Boundary rectangle bottom = ');;
  115.     NumToString(longint(theRect.bottom), theString);
  116.     DrawString(theString);
  117.  
  118.     MoveTo(10, 85);
  119.     DrawString('Boundary rectangle right = ');;
  120.     NumToString(longint(theRect.right), theString);
  121.     DrawString(theString);
  122.  
  123.     MoveTo(10, 105);
  124.     pixMapHdl := deviceHdl^^.gdPMap;
  125.     DrawString('Pixel depth := ');
  126.     NumToString(longint(pixMapHdl^^.pixelSize), theString);
  127.     DrawString(theString);
  128.  
  129.     MoveTo(10, 120);
  130.     bytesPerRow := BAnd(pixMapHdl^^.rowBytes, $7FFF);
  131.     DrawString('Bytes per row := ');
  132.     NumToString(longint(bytesPerRow), theString);
  133.     DrawString(theString);
  134.  
  135.     MoveTo(10, 135);
  136.     DrawString('Total pixel image bytes = ');
  137.     NumToString(longint(bytesPerRow) * theRect.bottom, theString);
  138.     DrawString(theString);
  139.  
  140.     MoveTo(10, 155);
  141.     if (pixMapHdl^^.hRes = $00480000) then
  142.         DrawString('Resolution = 72 dpi');
  143.  
  144.     MoveTo(10, 175);
  145.     if (BitTst(@deviceHdl^^.gdFlags, screenActive))
  146.         then     DrawString('Device is the current device')
  147.         else     DrawString('Device is not the current device');
  148.  
  149.     while not (Button) do ;
  150.  
  151. end.
  152.     
  153. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }