     VI 

      

    22.    
    23.   Delphi 
    24.    
    25.  DLL:  
    26.  DLL:   
    27.    
    28.    Web- 
    29.    Open Tools API 
    30.  Delphi  C++ 
    31.    Windows API 
    32.    

515

       

     22 

      

        DOS       
,         
. Microsoft Windows     ,   
      .   
  Windows GDI,     (Graphic 
Device Interface). GDI    ,   , 
  (),  (brush)   (font),     
   .   Delphi  VCL   
   ,    GDI-.  
      ,     
 ,    Windows "  ". 

       TCanvas   

     TCanvas  Delphi   ,     
GDI-    ,     
   .     Delphi   
GDI ,       
  TPrinter        GDI. 
     TCanvas      Delphi.  
,    .        
     ,   ,  
 ,     . 
        TCanvas    . 

        TCanvas   

       TCanvas      
 . 

        TBrush 

         . 
        TFont 
           Windows (  
    ),    ,   
 . 

        TImage, TPicture  TBitmap 

        ,    
  . 

     Windows:   

        : , , 
   . 

516


    Handle 

    Handle      Windows ( DC  Device 
context), .. ,    [ .    
 ,   .     
 |   Windows GDI,     
  TCanvas      DC . 
  ,    Handle   . 
 ^7|,     (  ). 

    I	If GetDeviceCaps(Canvas.Handle,   BITSPIXEL)    * 
    I	GetDeviceCaps(Canvas.Handle,   NUMPLANES)   >   1   then 
    l	ThisIsAColorDevice  =  True; 

    |	    Canvas. Handle    
     GDI   - , 
    TCanvas.    
^yijKjw^Wj^nd^gws_PolyP?l^gon (). PolyPolygon     
       . 
   PolyPolygon ()    
   .        
    .   λ,  
   ,     .    
   λ,    .   λ 
   ;       , 
           
,     . 

        PolyPolygon ()    . 

    procedure   DrawPolyPolygon(Canvas:   TCanvas); var 
    PtArray   :   array[0..9]   of  TPOINT; PtCounts   :   array[0..1]   of  
integer; begin 
    PtArray[0] = Point(0, 0) PtArray[1] = Point(0, 40) PtArray[2] = Point(40, 
40) PtArray[3] = Point(40, 0) PtArray[4] = Point(0, 0) PtCounts[0] := 5; 
PtArray[5] = Point (10, 10) PtArray[6] = Point(10, 30) PtArray[7] = Point(30, 
30) PtArray[8] = Point (30, 10) PtArray[9] = Point(10, 10) PtCounts[1] := 5; Windows.PolyPolygon(Canvas.Handle, 
    PtArray, 
    PtCounts 
    abend; 
    procedure TForml.ButtonlClick(Sender:   Tobject); begin 
    DrawPolyPolygon(Forml.Canvas); end; 

           ,    
DrawPolyPolygon (),       
,    ,    .  
  Windows PolyPolygon  ,      
  .     Windows 
PolyPolygon (),   ,  ,   
   ,  <'/. 

     

     Canyas_. Pen ,       
.      , ,    
.        : 

    Pen.Width   :=   10; 


     22.    517 

        ,   10 .  
  ,   Delphi  ,   
 .       ,   
  ,    .   
    ,   ,  * 
    ,   . 
  ,        
      . 
     Canvas . Color  ,    
.          
 .  ,      
  ,   ,      
 psInsideFrame    . 
          : 

    Pen.Color	:=	clRed; 
    Pen.Color	:=	cllnactiveCaption; 
    Pen.Color	:=	TColor(RGB(133,24,83)); 

           .  Delphi 
        
   Windows;  ,   
      Windows (Control Panel).  
      ,  
     ,      
 .     RGB-. RGB-   
,   .       0  
255,      16 777 216   . 
      ,   .  
        ^ 
      psInsideFrame   , 
_  (     ,     
,          
).      ,    
,   Windows GetNearestColor (). GetNearestColor () 
  HDC  RGB,      RGB   
.       . 

    var Acolor : TColorRef; begin 
    Acolor := GetNearestColor(Forml.Canvas.Handle, 
    RGB(133, 64, 22)); 
    Shapel.Pen.Color   :=  TColor(Acolor); end; 

          Windows GDI. 
        , 
    RGB- (GetRValue (), GetGValue(). GetBValue 
())        RGB   
.  ,  Delphi    ,  
 ColorToRgb (), "*  RGB   
  Delphi. 
         ,    
  psInsideFrame.    ,   
 . ^/     
psSolid;       .  psClear   
NULL_PEN  Windows (      ).   
  ,      ,     
   .        
,   . 

    	 

    psDash	    
    psDot	     
    psDashDot	       
    psDashDotDot	  ,   "    " 

     "  "      
. ,      ,     
     .      , 
     . 
         psInsideFrame.   
    ,   6" 
         Adobe PostScript. 

    518	 VI.   

      Mode ,    
__  ,    Windows ROP (Raster 
Operations    ).   16   
ROP,     . 

    	    

    pmBlack	   
    pmWhite	   
    pmNop	  
    pmNot	     
    	,    Color 
    pmNotCopy	   
    pmMergePenNot	       
    pmMaskPenNot	 ,        
    pmMergeNotPen	       
    pmMaskNotPen	 ,         
    pmMerge	      
    pmNotMerge	 pmMerge 
    pmMask	 ,      
    pmMaskNot	 pmMask 
    pmXor	   ,  ,     
    pmNotXor	 pmXor 

         ROP.  ,  
  .    " ", 
   .    
 (pmNot)   ,       
,   ,       . 
       , _   , 
   6y^eTjpHCOBaTb , ^   ,  
  . ,   r^gc^jerjOjjipjBOfiaeT 
1, ,     ^,     
 ,         .	.,.. 

    var 
    StartPt : TPoint; EndPt   : TPoint; Capture : bool; procedure 
TForml.FormMouseDown(Sender: Tobject; 
    Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin 
    StartPt.X := X; StartPt.Y := Y; EndPt := StartPt; 
SetCapture(Forml.Handle); Capture := True; with Canvas do begin Pen.Mode := 
pmNot; Pen.Color := clBlack; Brush.Style := bsClear; end; end; 
    procedure TForml.FormMouseMove(Sender: Tobject; 
    Shift: TShiftState; 
    X, Y: Integer); begin if (Capture) and ((EndPt.X <> X) or (EndPt.Y <> Y)) then 


     22.    519 


    begin 
    Canvas.Ellipse(StartPt.X,   StartPt.Y,   EndPt.X,   EndPt.Y); 
Canvas.Ellipse(StartPt.X,   StartPt.Y,   X,   Y); EndPt.X   :=  X; EndPt.Y   
:=  Y; end; end; 
    procedure TForml.FormMouseUp(Sender:   Tobject; 
    Button:   TMouseButton; Shift:   TShiftState; X,   Y:   Integer); begin 
    ReleaseCapture; Capture   :=  False; with  Canvas   do begin 
    Ellipse(StartPt.X,   StartPt.Y,   EndPt.X,   EndPt.Y); Pen.Mode   := 
pmCopy; Pen.Color   :=  clBlue; Brush.Style   := bsSolid; Ellipse(StartPt.X,   
StartPt.Y,   X,   Y); end; end; 

      :     ,  
    ,         
StartPt    EndPt.      
  ,    ,    
pmNot,      ,   .  
        :      
,   ,   ,       
.     ,    
   EndPt.  ,      
 ,          . 

        

          
Delphi,   ThisPen : = That Pen.     , 
  ,         
 Assign (),   : 

    ThisPen.Assign(ThatPen); 


       

             
  .     " ", 
 Handle       ,  
   Windows. , , "" 
,    Win32.    , 
       
 ,     Windows,  
    Delphi .   
        ,  
   .       
,        Windows-  
        Handle  . 
           . 

    procedure  TForml.ButtonlClick(Sender:   Tobject); var 
    Ib   :   TLogBrush; begin 
    with  Forml.Canvas  do begin 
    {      .   } 
    Pen.Width   :=   10; 
    Pen.Color   :=  clRed; 
    MoveTo(50,   50); 
    LineTo(150,   50); 
    LineTodOO,   150); 


    520	 VI.   


    LineTo(50, 50); 
    {    . } 
    Ib.lbStyle := BS_SOLID; 
    Ib.lbColor := RGB(255, 0, 0); 
    Ib.lbHatch := 0; 
    Pen.Handle := ExtCreatePen(PSJ3EOMETRIC or 
    PS_INSIDEFRAME or 
    PS_ENDCAP_SQUARE or 
    PS_JOIN_MITER, 10, Ib, 0, nil) ; 
    BeginPath(Handle); MoveTo(200, 50); LineTo(300, 50); LineTo(250, 150); 
LineTo(200, 50); CloseFigure (Handle) ; EndPath'fHandle) ; StrokePath(Handle); 
       . } Pen.Width := I Pen.Color := 
clBlack; end; end; 

             (  
    10,    ).  
    ,      
  ,      .    
,   ,   Windows 
]^ .     
    .     
 , -,      
.        
   .    Win32 ExtCreatePen (), 
         () 
  Pen. Handle.   ,     
 PS_ENDCAP_SQUARE  PS_JOIN_MITER.   ,   
       . 
       ,   
 (sandwich).     32-  
Windows, , ,    ,   
  16-  Windows.     
, ,   - ,  
     Windows BeginPath (),    ,  
 Windows EndPath ().     ,  
  ,  .        
  ,    Windows CloseFigure (). 
    ,         
  Windows 95,      Delphi    
     32- .   
  ,      Windows 
BeginPath (). 
            . 

    TBrush 

    Delphi- TBrush      Windows   
    ,     
.    , ,   . 
   NULL_BRUSH Windows   "  
,  _   .   
   ,  " " .  
,         
.   ,    ,    
   ,    Color : 

    Brush.Color := clRed; 
     Brush.Color := TColor(RGB(255, 0, 0)); 


     22.   	521 

          : 
    Brush.Style   :=  bsBDiagonal;     . 
    	 
    bsHorisontal	   
    bsVertical	   
    bsFDiagonal	      45   
    bsBDiagonal	      45   
    bsCross	     
    bsDiagCross	    45 
    ,     ;  , 
,   ,   ,  .    
,*?^_        
    ,   " ' 
    procedure  TForml.FormPaint   (Sender:   Tobject); begin 
    with  Canvas  do begin 
    Brush.Style   := bsHorisontal; 
    Brush.Color   :=   clRed; 
    SetBkColor(Handle,   RGB(0,    0,   255)); 
    SetBkMode(Handle,   OPAQUE); 
    Rectangle(0, 0, Forml.Width, Forml.Height); end; end; 
            
.    ,      ( GDI 
  ).     . 
           8x8 , 
, ,        
 ,  (    ). 
   ,        
  Bitmap. LoadFromFile (). 
    procedure  TForml.FormPaint    (Sender:   Tobject); var 
    Bitmap:   TBitmap; begin 
    Bitmap   := TBitmap.Create; try 
    Bitmap.LoadFromFile('c:\Borland\Delphi2.0\Images\'+ 
    'Icons\Earthl6.bmp'); Forml.Canvas.Brush.Bitmap   := Bitmap; 
    Forml.Canvas.FillRect(Rect(0,   0,   Forml.Width,   Forml.Height)); finally 
    Forml.Canvas.Brush.Bitmap   :=  nil; Bitmap.Free; end; end; 
              
  .   Canvas . Brush. Bitmap  Bitmap, 
   .  ,     
Bitmap  nil      .  
 ,   Delphi     
. ,        
     .  ,     
   8x8   ,    
,   ,   . 
     ,      GDI- Windows  
     ~" 
Canvas7Bru*sh.'Handle.	-"~~ " 

    procedure  TForml.ButtonlClick(Sender:   Tobject); begin 
    with Forml.Canvas  do begin 


    522	 VI.   


    Forml.Canvas.Brush.Handle := 
    CreateHatchBrush(HS_BDIAGONAL,RGB(255, 0, 0)); Rectangle(0, 0, 
Forml.Width, Forml.Height); end; end; 

       ,     ,   
,        Windows  
 . 
    ,         
.      ,    
 , ^HKU^oJ^iijdows SetBrushOrgEx ()   
 . ,  
ycTaH(3^Ka?jj?TOBO_ft,TO4j<Hj^cJHj^^iaicTH 1^}^__...  
 ,    *     
 Canvas . Brush. Handle. 
           . 

    procedure  TForml.ButtonlClick(Sender:   Tobject); var 
    org   :   TPoint; begin 
    with  Forml.Canvas  do begin 
    Forml.Canvas.Brush.Handle   := 
    CreateHatchBrush(HS_BDIAGONAL,RGB(255,    0,    0)); Rectangle(0,    0,    
Forml.Width  div  2,   Forml.Height); SetBru>-ah,Q?aExjHandle,   0,   6,   
Org) ; 'ForruTcanvas.Brush.Handle   := 
    CreateHatchBrush(HS_BDIAGONAL,RGB(255,    0,    0)); Rectangle(Forml.Width 
 div  2,    0,   Forml.Width,    Forml.Height); end; end; 

          ,  
  .      ,  
   ,        
.         , ^ 
  .  ,   Wi_ndows^5_uia6^oH    
      ,  .  ,  
Windows NT          
    . 

    TFont 

        , ,     
    ,   Delphi   TFont 
    .     TFont 
          
TCanvas.        ,    
   TFontDialog  . 
         TFontDialog   
   . 

    procedure TForml.ButtonlClick(Sender:   TObject); begin 
    FontDialogl.Font.Assign(Buttonl.Font); 
    if  FontDialogl.Execute  then 
    Buttonl.Font.Assign(FontDialogl.Font) ; end; 

        Font   FontDialog   , 
. ;  ,     FontDialog  
  .        
   ,    Cancel,   Button. Font  
 ,   FontDialog. 
    TFontDialog    ,    . 22.1. 
    ,   device  TFontDialog,   
fdWysiwyg, ,     FontDialog: , 
 _ ,  .   ,      
      Delphi.   ,  
      ,    
 Windows ChooseFont,       Delphi. 
,    , ,    , 
  f dTrueTypeOnly   ,   , 
   TrueType. 

     22.   	523 


    	 

    f dAniOnly	        ANSI 
    f dApplyButton	     Apply (). 
   ,    OnApply 
    f dEf f ects	     ;  , 
    ,      
    f dFixedPitchOnly	       
    fdForceFontExist	       
  
    fdLimitSize	        
 MinFontSize   MaxFontSize 
    f dNoFaceSel	       
     
    f dNoOEMFonts	       
    f dScalabelOnly	       
    fdNoSimulations	       
    f dNoSizeSel	  ,    ,  
    
    f dNoStyleSel	  ,    ,  
   
    fdNoVectorFonts	  f dNoOEMFonts 
    f dShowHelp	     Help 
    f dTrueTypeOnly	      TrueType 
    f dWysiwyg	     ,    
,    
      Windows GetRasterizerCaps (),   ,  
,   TrueType    . 

    procedure TForml.ButtonlClick(Sender:   Tobject); var 
    rs   :   TRasterizerStatus; begin 
    if GetRasterizerCaps(rs,   sizeof(rs))   then 
    if   ((rs.wFlags   and  TT_AVAILABLE  =  TT_AVAILABLE)   and 
    (rs.wFlags   and  TT_ENABLED  =  TT_ENABLED))    then 
ShowMessage('TrueType  is  available  on  this  system1); end; 

               
 ,    Screen. Fonts  Printer. Fonts, 
  .   : 

    ListBoxl.Item  :=  Screen.Fonts; 

     ,      ,  
     .     
.   1/72 ,     "" 
.  ""   ,      
    .     
,      ""'.     
 "",          
    , ,     "". 
,            
,        .     
 . 
    -       
  ,     
. Delphi       : Font. Size  
Font. Height.         Font. 
Size,     

    524	 VI.   

    ,     .      
Font. Height,     .      
 ,       .  
        . 
 ,        
  (Height)   (Size).      
    Abs (). 
      ,    Height    
,    . 

    Font.SizelnPoints   :=   72; 
    Font.Height   :=  -Round((GetDeviceCaps(Forml.Canvas.Handle, 
    LOGPIXELSY)    /   72)    *   Font.SizelnPoints); 

      ,        
    (        
).         . 

    Font.Color 

        . , ,    , 
     ,       
 ,    .        
(opaque)   .   ,    
   (transparent) . 
             TCanvas. 

    with   Forml.Canvas   do  begin; 
    SetBkColor(Handle,   RGB(0,255,0)); 
    SetBkMode(Handle,   OPAQUE); 
    TextCort(50,   50,    'Hello'); end;         "" 
    Font. Name 
     Name     : 
    Font.Name   :=   'Arial'; 
    Font.Style 

          ,   
(bold),  (italic),    .    
    ,      
 GDI,   GDI    .    
 ,    . 

    Font.Style   :=   [fsBold,   fsltalic,   fsUnderlined,   fsStrikeout]; 

 ,     . 

    Font. Pitch 

           . 
          ,     
  .      
  Courier,   '    
 Times.    . 

    	 

    fpDefault	 Pitch    
    f pFixed	 .        
    f pVariable	 .       

     -,       , GDI 
  . 

     22.   	525 


    Font.Charset 

        Delphi 3.0   .   
   Charset  ^^?_ Windows  
  : 

    Font.Charset   := ANSI  CHARSET; 


     
      ,       ,   
,   ,     . 

    Font. Handle 

              . 
     ,   ,   
 Windows GDI        
 TFonts . Handle  .     
TLogFont    Windows CreateFontlnderect (). ** 
             , 
   TLogFont,   Windows GetObject (),  
   ,       
.  ,        
VCL     .     TFont, 
       ,  , 
        . 
            45. 

    procedure  TForml.ButtonlClick(Sender:   Tobject); var 
    If   :   TLogFont; 
    tf : TFont; begin 
    tf := TFont.Create; 
    tf.Assign(Buttonl.Font); 
    GetObject(tf.Handle, sizeof(lf), @lf); 
    If .IfEscapement := 450; 
    If.IfOrientation := 450; 
    tf.Handle := CreateFontlnderect(If); "Buttonl.ParentFont := false; 
    Buttonl.Font.Assign(tf); 
    tf.Free; end; 

       TFont         
.  _   .   . 
   Windows GetObject (),   " 
   TFont.     Escapement  
Orientation    ,     45  
    1/10 . 
      ,    ,  
GDI- Windows CreateFontlnderect ().    
  Windows,       TFont. 
     ParentFont  False,    
 CBoficTBO_Font     .   
TFont    Font   . ,  TupffljTf, 
   ,   "",     
 .    TrueType,    
  . 
      ,      
 .     Delphi   
LogFont,      .   , 
    Windows    ,   
 ,          
 ,   .     
,        ,  . 

    526	 VI.   


         

        ,     
 ,         
 .  Delphi        
 : Canvas .TextWidth  Canvas . TextHeight.    
 Windows GetTex-tExtentPoint (). 
          ,   
Windows GetTextMetrics ().       
   ,   (TrueType, Device, Vector  .)  
   ,  ;.. 
       ^. ,,    
 ,      ,     
      Windows GetCharWidth () 
,ji_HejBbi3bmaTb   TextWidth. ,     
        ,  
  ,   .     , 
        
  Windows ExtTextOut ().  ,    , 
   ,    o?H?cjjjmHbi?;t-j<oojp^HaTb]Kj^ 
              
   .        
       .     
     ,    
   . 

    type  TIntArray =  array[0..0]   of  integer; 
    procedure  TForml.ButtonlClick(Sender   :   TObject); var 
    tm	:   TTextMetric; widths             :   Array[0... 255]   of  integer; 
PNpyjW. irH-h.q   ;   *TTn.tArray; i                        :   integer!'|v, 
begin                                                  \ 
    if  GetTextMetrics(Forml.Canvas.Handle,   tm)   then  begin 
GetCharWidth(Forml.Canvas.Handle,0,255,widths); for   i   :=  
ord(tm.tmFirstXhar)   to  ord(tm.tmLastChar)   do 
    Memol. Lines. Add (   Int't.oStr (i)   +   '    '   +  intToStr (widths 
[i] )); end; if  Length(Editl.Text)   >   0   then\begin 
    GetMem(PNewWidths,   sizeof(integer)    *   length(Editl.Text)); for  i   
:=  0  to   (length(Editl.Text)   - 1)   do 
    PNewWidths'4 [i]    := Widths [&rd (pchar (Editl. Text) [i] )]   +  10; Windows.ExtTextOut(Forml.Canvas.Handle,100,200,0,nil, 
    pchar(Editl.Text),length(Editl.Text), @PNewWidths'N [0] ) ; 
    FreeMem(PNewWidths,   sizeof(integer)   *   length(Editl.Text)); end; end; 

            TIntArray,  
      .    
,         
           ,  
   ,,     .  
""   ,     
 "          
  ,        . 
       ,   . 
    1.	   .&^   . 
    2.	     . 
    3.	       . 
        ,    : 

    MylntegerArray*[2] := 10; 


     22.   	527 

        ,       
       ,    
 .          
,     : 

    i   :=  2; 
    MyIntegerArrayA[i] := 10; 

          ,   
   ,    ,  
;          
     .     
,         .  
,         ,  
        . , 
  Pascal     Delphi    ... 
           TTextMetrics, 
      ,   
      ,   
   ,      i. 
        GetTextMetrics ()    
    GetChar-Width ()      
. ,    , ,  , 
.     ,     , 
  ,  ,    
 .  GetCharWidth ()    
      ,  
 .       
TTextMetrics,  tm. tmFirstChar  tm. tmLastChar,     
         . 
    ,       Windows ExtTextOut 
()           
      (,  ,   
     ). 
        , -, ,   
   .      - ,  
          ( 
    ).      
 ,      , 
 10       .  
   Windows ExtTextOut (),     
Canvas . Handle,       ,  , 
  ,     .  ,  
 ,     . 
    .  ,      
  ,       
  ,   Windows       
   ,     
.     . 

    DrawText () GetKerningPairs() GetTextAlign() SetTextAlign() 
GetTextCharacterExtra() SetTextCharacterExtra () SetTextJustification() TabbedTextOut() 

          Win32   Delphi 
    ,       
  .    SetTextAlign () 
        . , ,    
         
           
,   Windows DrawText (). 

    procedure TForml.ButtonlClick(Sender : TObject); var 
    r : TRect; begin 
    if length(Editl.Text) = 0 then exit; 
    r.Top := 50; 
    r.Left := 50; 
    r.Right := 150; 
    r.Bottom := 150; 


    528	 VI.   


    DrawText(Forml.Canvas.Handle, pChar(Editl.Text), length(Editl.Text), r, 
    DT_WordBreak  or   DT_Left); end; 

       ,     ,  
       Windows DrawText ().  
  ,  ,    
         
DrawText (), ,       ,   
        ,    
       . 
       DrawText ()    
          Windows. 
      DT_CALCRECT.    ,  
 ,    ^    
   (      
   ). 

    Tlmage 

           ,    
  Delphi    .  ,  
Delphi     ,       
  ! 
    ,    Delphi,        
     ,    
 Microsoft.        ,  
  ,    Delphi     
LoadFromFile   SaveToFile (). 
        Tlmage    
  ,      . 

    begin 
    Imagel.Picture.LoadFromFile(':\somepath\some.bmp'); 
    Imagel.Canvas.Ellipse(0,   0,   50,   50); 
    Imagel.Picture.SaveToFile(':\somepath\some.bmp'); end; 

     Image    .   
  Canvas.  AutoSize     
 ,  Stretch     
   .  Center    
 .      Tlmage  , 
,  Picture. 

    TPicture 

     TPicture    , , 
      .   
  :           
Clipboard. -        
!          ,  
   . 
            ^_\1??1. 

    uses Clipbrd; 
    procedure TForml.ButtonlClick(Sender: TObject); 
    begin 
    Clipboard.Assign   (Imagel.Picture); end; 
            . 
    procedure  TForml.ButtonlClick(Sender:   Tobject); begin 
    Imagel.Picture.Assign(Clipboard); end; 


     22.   	529 

     ,    TPicture Graphic   
  Draw()   Scretch-Draw ()      
  . 

    procedure TForml.ButtonlClick(Sender:   Tobject); begin 
    Forml.Canvas.Draw(300,   100,   Imagel.Picture.Graphic); end; 
    TBitmap 

      TBitmap     Windows,     
 (, ,  ).    TPicture, TBitmap 
            
.          
TPicture    TBitmap.     
   .      
         
 ,   ,      
       . 
            
Resource Workshop  Borland,      Borland 
RAD,        Borland Resource 
Command Line Compiler (BRCC32),   Delphi. Resource Workshop   
  ,   ,   
  16-,   32-     ,  
RC-,  , DLL, , , , , 
    .     RAD   
16- ,     Resource Workshop 4.5 
   ,     . 
           BRCC32, 
   Delphi.      Delphi \Bin. 
          ASCII- TEST.RC,  
  : 

    MYBITMAP BITMAP  "c:\download\some.bmp" 

       ,      
,      test. bmp,    MYBITMAP. 
            SOME.BMP. 
    , ,  RC-,      
   -   (     
 ): 

    :\borland\delphi\bin\brcc32.  :\download\test. 

       ,        
TEST.RES,      ,     : 

    {$R  TEST.RES} 

        ,  -,    ,  
        {$R * . DFM}, 
   implementation .  ,  
,       ,     
  . 
       ,    LoadFromResource () 
 TBitmap  . 

    procedure TForml.ButtonlClick(Sender:   Tobject); begin 
    Imagel.Picture.Bitmap.LoadFromResourceName(hlnstance,    'MYBITMAP'); end; 

        !    ,   hlnstance 
  LoadFromResourceName ().    ,  
 ,    .   
   ,     
(DLL).       , 
       (   
  DLL).   DLL,   , 
  MORICONS. DLL,    Windows.  DLL  
,    , ,     
  . 
      TBitmap     .   
, ,  Create. 

    530	 VI.   

              
" ".      Canvas,    
 SaveToDisk(}. , ,  TPaintBox.    
 TPaintBox   ,      
  ,    ,     
.       , 
      PaintBox   
     .     Paintbox,  
  "'' .      
  ,        . 

    procedure  TForml.PaintBoxlMouseMove(Sender:   Tobject; 
    Shift   :   TShiftState; X,   Y   :   Integer); begin 
    if  ssLeft   in  Shift  then 
    PaintBoxl.Canvas.Pixels[x,y]    :=  clBlack; end; 
    procedure  TForml.ButtonlClick(Sender   :   TObject); 
    Bitmap	: TBitmap ; 
    r	: TRect ; 
    begin 
    r.Left	:= 0; 
    r .Top	:= 0; 
    r .Right	:= PaintBoxl. Width; 
    r. Bottom := PaintBoxl . Height; 
    Bitmap	:= TBitmap. Create; 
    Bitmap.	Width  := r. Right; 
    Bitmap.Height   :=   r.Bottom; Bitmap.Canvas.CopyRect(r,   
PaintBoxl.Canvas,   r) Bitmap.SaveToFile(':\download\paintbox.bmp'); 
Bitmap.Free; end; 

           MouseMove  
PaintBox,          
.     ,    
  PaintBox',   " ",  
     CopyRect,     
PaintBox _ Bitmap. , ,       Bitmap. 

         DIB 

     Delphi 3       TBitmap  
    .      
Delphi,  -    (DDB  
device-depended bitmaps),  Delphi 3  - 
   (DIB  device-mSepended bitmaps).  
  DIB- ,      Bitmap. 
DibMemory.      DIB      
  ,        . 
(.        256- 
.       ,    
     ,  ,   .). 

    Type TByteArray = Array[0...0] of byte; 
    procedure TForml.ButtonlClick(Sender: TObject); var 
    p :  TByteArray; i : integer; begin 
    Imagel.Picture.LoadFromFile(':\DOWNLOAD\TEST.BMP'); 
    p := Imagel.Picture.Bitmap.DibMemory; 
    for i := 0 to (Imagel.Picture.Bitmap.Width  1) 
    do pA[i] := 0; end; 


     22.   	531 

          ,    
 ByteArray      i.    
        DibMemory.  
     DIB        DIB. 

    DIB  DDB 

      ,    Delphi     
  -   .  
Delphi 3      ,  DDB  
-   .    Delphi 3 
 DIB,      ,   Bitmap. 
HandleType  bmDIB,  bmDDB.  ,    
       . 

     

          Windows 95  ,  
      .  ,    
  TImageList.       
 Windows  ROP-,  TImageList     
.     Canvas.Brush   
  . 

     

    , Windows GDI       ( 
  !).  (region)    
  ,    ,   ,     
 ,   ( )  .  16-  
Windows     ,    Windows 
GDI,        .  
  Windows 95    ,   Windows NT , 
 ,    .     Delphi   
 ,     ,   
 ,  Windows GDI      
    GDI. 

    procedure TForml.PaintBoxlMouseMove(Sender:   TObject); var 
    MyRgn     :   hRgn; OldRgn   :   hRgn; begin 
    MyRgn   :=  CreateEllipticRgn(0,   0,   100,   100); Old.Rgn   :=  
SelectObject(Forml.Canvas.Handle,   MyRgn); PatBlt(Forml.Canvas.Handle,0,0, 
Forml.Width, Forml.Height, blackness); 
    SelectObject(Forml.Canvas.Handle,   OldRgn); DeleteObject(MyRgn); end; 

          :     
 ,   ,      
 ,     (     , 
  ).         
 .       
,        .  
   ,  ,  
  ,  ,    .   
       ,  . 
        ,      ,  
 ,     "  
,          
:       ,    
  (    ). 

     

      Windows      Windows GDI,   
      Clipboard,      . 
        GDI, 
   ,   .    
   '.    Windows   
"     ,    
 ,     . 

    532	 VI.   

    	       . 
    	        . 
    *	         . 
     TMetaf ile  Windows Metafile.   , 
   ,   Windows: Standart, Aldus  
Enhanced.     Windows.     
:       ,     
,      ,   ,   
        
. Aldus-    ,    
22- ,  ,    
   .     , 
   Aldus,   ,     
Delphi,   ,    .  
,     (EMF),    
    ,    
  ,   Windows NT.  , 
     , .J.Windows NT,   Windows 95! 
    Windows 95 ,     
 ,   Windows NT.   , ! 
     Delphi      .     
  Image  ,         
,    ,    Image. 
LoadFromFile (). 
        TMetaf ile      
 TBitmap.     TMetaf ile,   
     Metaf ileCanvas.  , 
  Metaf ileCanvas       ,  
        
     . 

    procedure TForml.ButtonlClick(Sender:   Tobject); var 
    MyMeta	:   TMetafile   ; 
    MyMetaCanvas   :   TMetafileCanvas   ; begin 
    MyMeta	:=  TMetafile.Create; 
    MyMeta.Width     :=   100; 
    MyMeta.Height   :=   100; 
    MyMetaCanvas     :=  TMetafileCanvas.Create(MyMeta,   0); 
    MyMetaCanvas.Ellipse(0,   0,    100,   100); 
    MyMetaCanvas.Free; 
    Forml.Canvas.Draw(0,    0,   MyMeta); 
    MyMeta.Free; end; 

        TMetafile  TMetaf ileCanvas. ,   
,       _?,   
  .         
 ,           .  
    . 

      

            Windows MM_TEXT. 
            
    ( ),    
  ,       . 
     Windows    . 

    	 
    _	     (  
   ) 
    MM_LOMETRIC	   0.1  (   
  ) 
    MM_HIMETRIC	   0.01  (   
  ) 
    MM_LOENGLISH	    0.01  
(     ) 


     22.   	533 


    MM_HIENGLISH	    0.001  
(     ) 
    MM_TWIPS	    1/20  (1/1440 ) 
(     ) 
    MM_ISOTROPIC	       
 . 
     SetWindowExtEx  SetViewportExtEx,    
   .     ,    
,   GDI   . (  
         .) 
    MM_ANISOTROPIC	      
  . 
     SetWindowExtEx  SetViewportExtEx,    
,    . (   
        .) 
            (  
 0, 0)      .  , 
        ,     
,         
,     . 
       ,      
    .  ,   
   ,   ,  
 ,           
   .       
,  ,    .   
 . 

    	 

    SetMapMode	   
    ^SetWindowOrgEx	   (   
 , ) 
    SetWindowExtEx	  .     
,    .     
MM_ISOTROPIC  MM_ANISOTROPIC 
    SetViewportExtEx	  .     
,     .    
 MM_ISOTROPIC  MM_ANISOTROPIC 
       SetMapMode ()    ,  
     .  SetWindowOrgEx () 
       ,  ( 
), ,  ,     .  
  MM_LOENGLISH,      
     . - ,     
   ,  (, ,     
 )       ( 
   ...).  SetWindowExtEx ()  SetViewportExtEx () 
 ,  ,      
     MM_ISOTROPIC  MM_ANISOTROPIC. ,  
   ,   ^_^    
   .  ,    
Set-WindowExtfExl j,    ,   SetViewportExtEx 
(),   .       
   ,     . 
         MM_LOENGLISH  
    . 

    procedure TForml.ButtonlClick(Sender:   Tobject); var 
    OldMapMode   :   integer; 
    OldOrigin     :   TPoint   ; begin 
    OldMapMode   := SetMapMode(Forml.Canvas.Handle, 
    MM_LOENGLISH); 
    SetWindowOrgEx(Forml.Canvas.Handle, 0,   100,   @01dOrigin); 
    Forml.Canvas.Ellipse(0,   0,   100,   100); 


    534	 VI.   


    SetWindowOrgEx(Forml.Canvas.Handle, 
    OldOrigin.x, 
    OldOrigin.y, 
    nil); 
    SetMapMode(Forml.Canvas.Handle,   OldMapMode); end; 

     ,        
  ,       .  
 ,      100  ,    
      . 
         MM_ANISOTROPIC  
 .     ,     
    ,  -     
     ,     
   ,     ,  
      , 

    procedure  TForml.Button2Click(Sender:   Tobject); var 
    OldMapMode	:   integer; OldOrigin                    :   TSize; 
OldWindowExtent      :   TSize; OldViwPortExtent   :   TSize; begin 
    OldMapMode   :=  SetMapMode(Forml.Canvas.Handle, 
    MM_ANISOTROPIC); 
    SetWindowExtEx(Forml.Canvas.Handle, 100,   100, 
    SOldWindowExtent); 
    SetViewportExtEx(Forml.Canvas.Handle, 200, 100, 
    @01dViewPortExtent); SetWindowOrgEx(Forml.Canvas.Handle, 0,   -100, @01dOrigin); 
    Forml.Canvas.Ellipse (0,   0,    100,    100); 
SetWindowOrgEx(Forml.Canvas.Handle, OldOrigin.ex, OldOrigin.cy, nil) ; 
    SetViewportExtEx(Forml.Canvas.Handle, OldViwPortExtent.ex, 
OldViwPortExtent.cy, nil) ; 
    SetWindowExtEx(Forml.Canvas.Handle, OldWindowExtent.ex, 
OldWindowExtent.cy, nil) ; 
    SetMapMode(Forml.Canvas.Handle,   OldMapMode); end; 

            ,     
 ,      MM_ANISOTROPIC   
  . -,      ,  
 ,      ,   . 
    ,          
      ,    
Windows,  DPtoLP ()  LPtoDP ().       
     . 

     (threads) 

      ,     Delphi   
.  TCanvas        Lock  
Unlock.  Lock     ,   Unlock 
 . ,   TBitmap     
     Assign.     ,  
      ,    
  . 

     22.   	535 


     

     Delphi   ,   
   Delphi ,    .  
        
,     GDI     .  
 23, "  Delphi",       , 
      ,      
     . 

    536	 VI.   

