• No results found

If the function succeeds, it returns TRUE; otherwise it returns FALSE. To get extended error information, call GetLastError.

Example

Listing 2-4: Converting Coordinates Between Coordinate Systems

25

procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

var

Coords: TPoint; // holds the point being converted begin

{indicate the clicked coordinates relative to the child window}

Label1.Caption := 'Memo Coordinates: '+IntToStr(X)+', '+IntToStr(Y);

{convert these coordinates into screen coordinates}

Coords := Point(X, Y);

Windows.ClientToScreen(Memo1.Handle, Coords);

{display the clicked coordinates relative to the screen}

Label2.Caption := 'Screen Coordinates: '+IntToStr(Coords.X)+', '+

IntToStr(Coords.Y);

{convert the coordinates into window client coordinates}

Windows.ScreenToClient(Form1.Handle, Coords);

{display the clicked coordinates relative to the client area of the window}

Label3.Caption := 'Form Coordinates: '+IntToStr(Coords.X)+', '+

IntToStr(Coords.Y);

end;

CreateCompatibleDC Windows.Pas Syntax

CreateCompatibleDC(

DC: HDC {the handle to a device context}

): HDC; {returns a handle to a memory device context}

Description

This function creates a memory device context that is compatible with the specified device context. This is used with images that will be copied to the screen or to a printer. A bitmap must be selected into the device context returned by this function before the device context can be used with drawing operations. When an application is finished with the memory device context, it should be deleted by calling the DeleteDC function.

Parameters

DC: Specifies a handle to a device context for which the new device context will be compatible.

This must be a device context that supports raster operations. The application can call the GetDeviceCaps function to determine if the device context meets this requirement. If this parameter is set to zero, the function creates a device context compatible with the screen.

Return Value

If the function succeeds, it returns a handle to the new memory device context. If it fails, it returns zero.

Example

26

Listing 2-5: Using Memory Device Contexts for Animation

var

Form1: TForm1;

OffscreenDC: HDC; // an offscreen device context

ANDMaskBitmap, // used for holding the different parts of the ORMaskBitmap, // circle graphic

BackgroundBitmap, OldBitmap: HBITMAP;

BallXCoord: Integer; // the current horizontal coordinates of the circle implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);

var

ScreenDC, // a handle to the screen device context WorkDC: HDC; // a handle to a temporary device context OldBitmap: HBITMAP; // holds the previous bitmap

begin

{retrieve a handle to the device context for the screen}

ScreenDC := GetDC(0);

{create a memory device context}

WorkDC := CreateCompatibleDC(Canvas.Handle);

{restore the previous background to the screen}

BitBlt(ScreenDC, BallXCoord, Form1.Top, 40, 40, OffscreenDC, 0, 0, SRCCOPY);

{increment the horizontal coordinate of the circle}

Inc(BallXCoord);

{wrap the circle around the screen if it has gone beyond the edges}

if BallXCoord>GetSystemMetrics(SM_CXSCREEN) then BallXCoord := -40;

{save the background at the current location of the circle}

BitBlt(OffscreenDC, 0, 0, 40, 40, ScreenDC, BallXCoord, Form1.Top, SRCCOPY);

{select the AND mask of the circle into the memory device context, and copy it to the screen}

OldBitmap := SelectObject(WorkDC, ANDMaskBitmap);

BitBlt(ScreenDC, BallXCoord, Form1.Top, 40, 40, WorkDC, 0, 0, SRCAND);

{select the OR mask of the circle into the memory device context, and copy it to the screen}

SelectObject(WorkDC, ORMaskBitmap);

27

BitBlt(ScreenDC, BallXCoord, Form1.Top, 40, 40, WorkDC, 0, 0, SRCPAINT);

{select the old bitmap back into the memory device context, and delete or release all unneeded objects}

SelectObject(WorkDC, OldBitmap);

ReleaseDC(0, ScreenDC);

DeleteDC(WorkDC);

end;

procedure TForm1.FormCreate(Sender: TObject);

var

TempBrush: HBRUSH; // a handle to a brush begin

{create a memory device context}

OffscreenDC := CreateCompatibleDC(Canvas.Handle);

{a lot of attributes of the device context will change, so save its original

state so we don't have to reselect the original objects back into the device context}

SaveDC(OffscreenDC);

{create the bitmap for the circle's AND mask}

AndMaskBitmap := CreateCompatibleBitmap(Canvas.Handle, 40, 40);

{select the bitmap into the memory device context and draw a black circle on a white background}

SelectObject(OffscreenDC, AndMaskBitmap);

SelectObject(OffscreenDC, GetStockObject(WHITE_BRUSH));

SelectObject(OffscreenDC, GetStockObject(NULL_PEN));

Rectangle(OffscreenDC, 0, 0, 41, 41);

SelectObject(OffscreenDC, GetStockObject(BLACK_BRUSH));

Ellipse(OffscreenDC, 0, 0, 40, 40);

{create the bitmap for the circle's OR mask}

ORMaskBitmap := CreateCompatibleBitmap(Canvas.Handle, 40, 40);

{select the bitmap into the memory device context and draw a hatched circle on a black background}

SelectObject(OffscreenDC, ORMaskBitmap);

SelectObject(OffscreenDC, GetStockObject(BLACK_BRUSH));

Rectangle(OffscreenDC, 0, 0, 41, 41);

TempBrush := CreateHatchBrush(HS_DIAGCROSS, clRed);

SelectObject(OffscreenDC, GetStockObject(BLACK_PEN));

SelectObject(OffscreenDC, TempBrush);

Ellipse(OffscreenDC, 0, 0, 40, 40);

{restore the device context's original settings. this eliminates the need to

28

reselect all of the original objects back into the device context when we are through}

RestoreDC(OffscreenDC, -1);

{delete the brush}

DeleteObject(TempBrush);

{finally create a bitmap to hold the background of the screen. this keeps the animated circle from leaving a trail behind it}

BackgroundBitmap := CreateCompatibleBitmap(Canvas.Handle, 40, 40);

{select the background bitmap into the memory device context}

SelectObject(OffscreenDC, BackgroundBitmap);

{initialize the coordinates of the circle so it will begin off screen to the left}

BallXCoord := -40;

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

{delete all unneeded bitmaps and device contexts}

SelectObject(OffscreenDC, OldBitmap);

DeleteObject(BackgroundBitmap);

DeleteObject(ANDMaskBitmap);

DeleteObject(ORMaskBitmap);

DeleteDC(OffscreenDC);

end;

Figure 2-3: The animated DeleteDC Windows.Pas Syntax

DeleteDC(

DC: HDC {the handle of a device context}

): BOOL; {returns TRUE or FALSE}

Description

The DeleteDC function deletes the specified device context. When an application uses CreateCompatibleDC, it should also call DeleteDC when finished with the handle.

Parameters

DC: The handle to the device context to be deleted.

Example

Please see Listing 2-5 under CreateCompatibleDC.

DPtoLP Windows.Pas Syntax

29 DPtoLP(

DC: HDC; {the handle of a device context}

var Points; {a pointer to an array of TPoint structures}

Count: Integer {the number of entries in the array}

): BOOL; {returns TRUE or FALSE}

Description

The DPtoLP function converts points from device coordinates to logical coordinates. The Points parameter points to an array of TPoint structures containing the coordinates to be translated.

These TPoint structures will receive the translated coordinates when the function returns. The coordinate transformation is performed based on the values set by the SetWindowOrgEx, SetViewportOrgEx, SetWindowExtEx, and SetViewportExtEx functions. The DPtoLP function will fail if any of the points in the TPoint structures specify a value greater in size than 27 bits. It will also fail if any of the transformed points are greater in size than 32 bits. In the event of failure, the values in the entire Points array are undefined.

Figure 2-4: The available display mode information

Parameters

DC: A handle to the device context for which the coordinate transformations will be made.

Points: A pointer to an array of TPoint structures containing the coordinates to be converted.

Count: Specifies the number of entries in the array pointed to by the Points parameter.

Return Value

If the function succeeds, it returns TRUE; otherwise it returns FALSE.

Example

Please see Listing 2-12 under ScaleViewportExtEx.

EnumDisplaySettings Windows.Pas Syntax

EnumDisplaySettings(

lpszDeviceName: PChar; {the display device}

iModeNum: DWORD; {the graphics mode}

var lpDevMode: TDeviceMode {a pointer to a structure to receive device settings}

): BOOL; {returns TRUE or FALSE}

Description

30

The EnumDisplaySettings function retrieves information from the specified display device about the specified graphics mode. To retrieve all display modes available for the specified device, start by setting the iModeNum to zero and incrementing it by one for each subsequent call to the function. This should continue until the function returns FALSE.

Parameters

lpszDeviceName: The name of the device for which information is to be retrieved. If this parameter is set to NIL, the function enumerates display modes for the current display device.

The string pointed to by this parameter must be in the form of \\.\Display1, \\.\Display2, or

\\.\Display3. Under Windows 95, this parameter must always be set to NIL.

iModeNum: The index value for the graphics mode for which information is to be retrieved. This value must be less than the index of the display’s last graphics mode. If the iModeNum parameter is out of range, the function will return an error.

var lpDevMode: A pointer to a TDeviceMode structure that receives information about the specified display mode. Of the members in the TDeviceMode structure, only the dmSize, dmBitsPerPel, dmPelsWidth, dmPelsHeight, dmDisplayFlags, and dmDisplayFrequency members are used by this function. The TDeviceMode structure is defined as:

TDeviceMode = packed record

dmDeviceName: array[0..CCHDEVICENAME - 1]

of AnsiChar; {not used}

dmSpecVersion: Word; {not used}

dmDriverVersion: Word; {not used}

dmSize: Word; {structure size}

dmDriverExtra: Word; {not used}

dmFields: DWORD; {not used}

dmOrientation: SHORT; {not used}

dmPaperSize: SHORT; {not used}

dmPaperLength: SHORT; {not used}

dmPaperWidth: SHORT; {not used}

dmScale: SHORT; {not used}

dmCopies: SHORT; {not used}

dmDefaultSource: SHORT; {not used}

dmPrintQuality: SHORT; {not used}

dmColor: SHORT; {not used}

dmDuplex: SHORT; {not used}

dmYResolution: SHORT; {not used}

dmTTOption: SHORT; {not used}

31

dmCollate: SHORT; {not used}

dmFormName: array[0..CCHFORMNAME - 1]

of AnsiChar; {not used}

dmLogPixels: Word; {not used}

dmBitsPerPel: DWORD; {color depth}

dmPelsWidth: DWORD; {screen width}

dmPelsHeight: DWORD; {screen height}

dmDisplayFlags: DWORD; {display mode}

dmDisplayFrequency: DWORD; {frequency}

dmICMMethod: DWORD; {not used}

dmICMIntent: DWORD; {not used}

dmMediaType: DWORD; {not used}

dmDitherType: DWORD; {not used}

dmICCManufacturer: DWORD; {not used}

dmICCModel: DWORD; {not used}

dmPanningWidth: DWORD; {not used}

dmPanningHeight: DWORD; {not used}

end;

Figure 2-5: Drawing on the device

Please see the ChangeDisplaySettings function for a description of this data structure.

Return Value

If the function succeeds, it returns TRUE; otherwise it returns FALSE.

Example

Listing 2-6: Enumerating All Available Display Modes for the Current Display

procedure TForm1.Button1Click(Sender: TObject);

var

DeviceInfo: TDevMode; // holds device information

DeviceCount: Integer; // tracks the number of display modes begin

{initialize the tracking variable}

DeviceCount := 0;

{enumerate all display modes for the current display device}

while EnumDisplaySettings(NIL, DeviceCount, DeviceInfo) do begin

{display the relevent information for the display mode}

ListBox1.Items.Add('Device '+IntToStr(DeviceCount)+' -');

ListBox1.Items.Add('Pixels/Inch: '+IntToSTr(DeviceInfo.dmLogPixels));

32

ListBox1.Items.Add('Bits/Pixel: '+IntToStr(DeviceInfo.dmBitsPerPel));

ListBox1.Items.Add('Pixel Width: '+IntToStr(DeviceInfo.dmPelsWidth));

ListBox1.Items.Add('Pixel Height: '+IntToStr(DeviceInfo.dmPelsHeight));

{indicate the display mode type}

case DeviceInfo.dmDisplayFlags of

DM_GRAYSCALE: ListBox1.Items.Add('Display Mode: Grayscale');

DM_INTERLACED: ListBox1.Items.Add('Display Mode: Interlaced');

end;

{indicate the refresh rate}

if (DeviceInfo.dmDisplayFrequency=0)or(DeviceInfo.dmDisplayFrequency=1) then

ListBox1.Items.Add('Refresh Rate: Hardware Default') else

ListBox1.Items.Add('Refresh Rate:

'+IntToStr(DeviceInfo.dmDisplayFrequency)+' hrz');

{add a blank line and increment the tracking variable}

ListBox1.Items.Add('');

Inc(DeviceCount);

end;

end;

GetDC Windows.Pas Syntax

GetDC(

hWnd: HWND {the handle of a window}

): HDC; {returns a device context}

Description

The GetDC function retrieves a device context for the client area of the window specified by the hWnd parameter. The device context retrieved will be a common, class, or private device context as determined by the class styles of the specified window. For common device contexts, the GetDC function initializes the device context with default attributes each time it is retrieved.

Class and private device contexts retrieved by this function will retain their last settings. When the device context is no longer needed, it should be released by calling the ReleaseDC function.

Parameters

hWnd: A handle to the window for which a device context is retrieved. If this parameter is set to zero, the function retrieves a device context for the screen.

Return Value

If the function succeeds, it returns a device context for the client area of the specified window. If the function fails, it returns a zero.

Example

Listing 2-7: Retrieving a Common Device Context for a Window

33 procedure TForm1.FormPaint(Sender: TObject);

var

FormDC: HDC; // holds the device context OldFont: HFONT; // holds the original font begin

{retrieve a common device context for the form}

FormDC := GetDC(Form1.Handle);

{select the form's font into the device context}

OldFont := SelectObject(FormDC, Form1.Font.Handle);

{output some text onto the device context}

SetBkMode(FormDC, TRANSPARENT);

TextOut(FormDC, 10, 10, 'Delphi Rocks!', Length('Delphi Rocks!'));

{reselect the original font and release the device context}

SelectObject(FormDC, OldFont);

ReleaseDC(Form1.Handle, FormDC);

end;

GetDCOrgEx Windows.Pas Syntax

GetDCOrgEx(

DC: HDC; {the handle of a device context}

var Origin: TPoint {a pointer to a TPoint structure}

): BOOL; {returns TRUE or FALSE}

Description

The GetDCOrgEx function retrieves final translation origin from the specified device context.

This location is the final offset that Windows will use when translating device coordinates into client coordinates.

Parameters

DC: A handle to the device context whose origin is being retrieved.

Origin: A pointer to a TPoint structure that will receive the origin coordinates. The coordinates are relative to the physical origin of the screen, and is given in device units.

Return Value

If the function succeeds, it returns TRUE; otherwise it returns FALSE.

Example

Please see Listing 2-2 in the introduction.

GetDeviceCaps Windows.Pas Syntax

GetDeviceCaps(

DC: HDC; {the handle of a device context

34

Index: Integer {the capability index}

): Integer; {returns the capability value}

Description

The GetDeviceCaps function gets device information about a particular capability from the specified device context. A wide variety of capabilities can be queried as shown in Table 2-7.

Parameters

DC: The handle of the device context for which the capability is being queried.

Index: A flag indicating the specific capability being queried. This parameter may be set to one value from Table 2-7.

Return Value

If the function succeeds, it returns a value specific to the queried capability. This function does not indicate an error condition.

Example

Listing 2-8: Retrieving Device Capabilities

procedure TForm1.Button1Click(Sender: TObject);

begin

with ListBox1.Items do begin

{display the driver version}

Add('Display Driver Version: '+IntToSTr(GetDeviceCaps(Canvas.Handle, DRIVERVERSION)));

{display the technology}

case GetDeviceCaps(Canvas.Handle, TECHNOLOGY) of DT_PLOTTER: Add('Driver Type: Vector Plotter');

DT_RASDISPLAY:Add('Driver Type: Raster Display');

DT_RASPRINTER:Add('Driver Type: Raster Printer');

DT_RASCAMERA: Add('Driver Type: Raster Camera');

DT_CHARSTREAM:Add('Driver Type: Character Stream');

DT_METAFILE: Add('Driver Type: Metafile');

DT_DISPFILE: Add('Driver Type: Display File');

end;

{display the screen size}

Add('Screen Size: '+IntToStr(GetDeviceCaps(Canvas.Handle, HORZSIZE))+' X '+

IntToStr(GetDeviceCaps(Canvas.Handle, VERTSIZE))+' millimeters');

Add('Screen Resolution: '+IntToStr(GetDeviceCaps(Canvas.Handle, HORZRES))+

' X '+IntToStr(GetDeviceCaps(Canvas.Handle, VERTRES))+' pixels');

{display the pixels per logical inch}

Add('Pixels/Logical Inch - Horizontal: '+IntToStr(GetDeviceCaps(

Canvas.Handle, LOGPIXELSX)));

Add('Pixels/Logical Inch - Vertical: '+IntToStr(GetDeviceCaps(

35 Canvas.Handle, LOGPIXELSY)));

{display the color depth and number of common graphical objects}

Add('Bits/Pixel: '+IntToStr(GetDeviceCaps(Canvas.Handle, BITSPIXEL)));

Add('Brushes: '+IntToStr(GetDeviceCaps(Canvas.Handle, NUMBRUSHES)));

Add('Pens: '+IntToStr(GetDeviceCaps(Canvas.Handle, NUMPENS)));

Add('Fonts: '+IntToStr(GetDeviceCaps(Canvas.Handle, NUMFONTS)));

{display the number of entries in the color table}

if GetDeviceCaps(Canvas.Handle, NUMCOLORS)>-1 then

Add('Entries in color table: '+IntToStr(GetDeviceCaps(

Canvas.Handle, NUMCOLORS)));

{display pixel dimensions}

Add('Pixel Width: '+IntToStr(GetDeviceCaps(Canvas.Handle, ASPECTX)));

Add('Pixel Height: '+IntToStr(GetDeviceCaps(Canvas.Handle, ASPECTY)));

Add('Pixel Diagonal: '+IntToStr(GetDeviceCaps(Canvas.Handle, ASPECTXY)));

{indicate if the device can clip to a rectangle}

if GetDeviceCaps(Canvas.Handle, CLIPCAPS)=1 then Add('Device can clip to a rectangle')

else

Add('Device cannot clip to a rectangle');

{display the palette size, reserved colors, and color depth}

Add('Palette Size: '+IntToStr(GetDeviceCaps(Canvas.Handle, SIZEPALETTE)));

Add('Number of Reserved Colors: '+IntToStr(GetDeviceCaps(

Canvas.Handle, NUMRESERVED)));

Add('Color Resolution: '+IntToStr(Trunc(IntPower(2, GetDeviceCaps(

Canvas.Handle, COLORRES))))+' colors');

{display the raster capabilities}

Add('Raster Capabilities -');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_BANDING)=RC_BANDING then

Add(' Requires Banding');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_BITBLT)=RC_BITBLT then

Add(' Can Transfer Bitmaps');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_BITMAP64)=RC_BITMAP64 then

Add(' Supports Bitmaps > 64K');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_DI_BITMAP)=RC_DI_BITMAP then

Add(' Supports SetDIBits and GetDIBits');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_DIBTODEV)=RC_DIBTODEV then

Add(' Supports SetDIBitsToDevice');

36

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_FLOODFILL)=RC_FLOODFILL then

Add(' Can Perform Floodfills');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_GDI20_OUTPUT)=RC_GDI20_OUTPUT then

Add(' Supports Windows 2.0 Features');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_PALETTE)=RC_PALETTE then

Add(' Palette Based');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_SCALING)=RC_SCALING then

Add(' Supports Scaling');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_STRETCHBLT)=RC_STRETCHBLT then

Add(' Supports StretchBlt');

if (GetDeviceCaps(Canvas.Handle, RASTERCAPS) and RC_STRETCHDIB)=RC_STRETCHDIB then

Add(' Supports StretchDIBits');

{display curve capabilities}

Add('Curve Capabilities -');

if GetDeviceCaps(Canvas.Handle, CURVECAPS)=CC_NONE then Add(' Device Does Not Support Curves')

else begin

if (GetDeviceCaps(Canvas.Handle, CURVECAPS) and CC_CIRCLES)=CC_CIRCLES then

Add(' Supports Circles');

if (GetDeviceCaps(Canvas.Handle, CURVECAPS) and CC_PIE)=CC_PIE then

Add(' Supports Pie Wedges');

if (GetDeviceCaps(Canvas.Handle, CURVECAPS) and CC_CHORD)=CC_CHORD then

Add(' Supports Chords');

if (GetDeviceCaps(Canvas.Handle, CURVECAPS) and CC_ELLIPSES)=CC_ELLIPSES then

Add(' Supports Ellipses');

if (GetDeviceCaps(Canvas.Handle, CURVECAPS) and CC_WIDE)=CC_WIDE then

Add(' Supports Wide Borders');

if (GetDeviceCaps(Canvas.Handle, CURVECAPS) and CC_STYLED)=CC_STYLED then

Add(' Supports Styled Borders');

if (GetDeviceCaps(Canvas.Handle, CURVECAPS) and CC_WIDESTYLED)=CC_WIDESTYLED then

Add(' Supports Wide And Styled Borders');

if (GetDeviceCaps(Canvas.Handle, CURVECAPS) and CC_INTERIORS)=CC_INTERIORS then

Add(' Supports Interiors');

37

if (GetDeviceCaps(Canvas.Handle, CURVECAPS) and CC_ROUNDRECT)=CC_ROUNDRECT then

Add(' Supports Rounded Rectangles');

end;

{display line capabilities}

Add('Line Capabilities -');

if GetDeviceCaps(Canvas.Handle, LINECAPS)=LC_NONE then Add(' Device Does Not Support Lines')

else begin

if (GetDeviceCaps(Canvas.Handle, LINECAPS) and LC_POLYLINE)=LC_POLYLINE then

Add(' Supports Polylines');

if (GetDeviceCaps(Canvas.Handle, LINECAPS) and LC_MARKER)=LC_MARKER then

Add(' Supports Markers');

if (GetDeviceCaps(Canvas.Handle, LINECAPS) and LC_POLYMARKER)=LC_POLYMARKER then

Add(' Supports Multiple Markers');

if (GetDeviceCaps(Canvas.Handle, LINECAPS) and LC_WIDE)=LC_WIDE then

Add(' Supports Wide Lines');

if (GetDeviceCaps(Canvas.Handle, LINECAPS) and LC_STYLED)=LC_STYLED then

Add(' Supports Styled Lines');

if (GetDeviceCaps(Canvas.Handle, LINECAPS) and LC_WIDESTYLED)=LC_WIDESTYLED then

Add(' Supports Wide And Styled Lines');

if (GetDeviceCaps(Canvas.Handle, LINECAPS) and LC_INTERIORS)=LC_INTERIORS then

Add(' Supports Interiors');

end;

{display polygonal capabilities}

Add('Polygonal Capabilities -');

if GetDeviceCaps(Canvas.Handle, POLYGONALCAPS)=PC_NONE then Add(' Device Does Not Support Polygons')

else begin

if (GetDeviceCaps(Canvas.Handle, POLYGONALCAPS) and PC_POLYGON)=PC_POLYGON then

Add(' Supports Alternate Fill Polygons');

if (GetDeviceCaps(Canvas.Handle, POLYGONALCAPS) and PC_RECTANGLE)=PC_RECTANGLE then

Add(' Supports Rectangles');

if (GetDeviceCaps(Canvas.Handle, POLYGONALCAPS) and PC_WINDPOLYGON)=PC_WINDPOLYGON then

Add(' Supports Winding Fill Polygons');

38

if (GetDeviceCaps(Canvas.Handle, POLYGONALCAPS) and PC_SCANLINE)=PC_SCANLINE then

Add(' Supports Single Scanlines');

if (GetDeviceCaps(Canvas.Handle, POLYGONALCAPS) and PC_WIDE)=PC_WIDE then

Add(' Supports Wide Borders');

if (GetDeviceCaps(Canvas.Handle, POLYGONALCAPS) and PC_STYLED)=PC_STYLED then

Add(' Supports Styled Borders');

if (GetDeviceCaps(Canvas.Handle, POLYGONALCAPS) and PC_WIDESTYLED)=PC_WIDESTYLED then

Add(' Supports Wide And Styled Borders');

if (GetDeviceCaps(Canvas.Handle, POLYGONALCAPS) and PC_INTERIORS)=PC_INTERIORS then

Add(' Supports Interiors');

end;

{display text capabilities}

Add('Text Capabilities -');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_OP_CHARACTER)=TC_OP_CHARACTER then

Add(' Capable of Character Output Precision');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_OP_STROKE)=TC_OP_STROKE then

Add(' Capable of Stroke Output Precision');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_CP_STROKE)=TC_CP_STROKE then

Add(' Capable of Stroke Clip Precision');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_CR_90)=TC_CR_90 then

Add(' Supports 90 Degree Character Rotation');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_CR_ANY)=TC_CR_ANY then

Add(' Supports Character Rotation to Any Angle');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_SF_X_YINDEP)=TC_SF_X_YINDEP then

Add(' X And Y Scale Independent');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_SA_DOUBLE)=TC_SA_DOUBLE then

Add(' Supports Doubled Character Scaling');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_SA_INTEGER)=TC_SA_INTEGER then

Add(' Supports Integer Multiples Only When Scaling');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_SA_CONTIN)=TC_SA_CONTIN then

Add(' Supports Any Multiples For Exact Character Scaling');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_EA_DOUBLE)=TC_EA_DOUBLE then

Add(' Supports Double Weight Characters');

39

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_IA_ABLE)=TC_IA_ABLE then

Add(' Supports Italics');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_UA_ABLE)=TC_UA_ABLE then

Add(' Supports Underlines');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_SO_ABLE)=TC_SO_ABLE then

Add(' Supports Strikeouts');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_RA_ABLE)=TC_RA_ABLE then

Add(' Supports Raster Fonts');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_VA_ABLE)=TC_VA_ABLE then

Add(' Supports Vector Fonts');

if (GetDeviceCaps(Canvas.Handle, TEXTCAPS) and TC_SCROLLBLT)=TC_SCROLLBLT then

Add(' Cannot Scroll Using Blts');

end;

end;

Figure 2-6: The device capabilities Table 2-7: GetDeviceCaps Index Values

Value Description

DRIVERVERSION The device driver version.

TECHNOLOGY Device technology type. This flag returns one value from Table 2-8. The DC parameter can refer to an enhanced metafile, in which case the device technology returned is that of the device referenced in the metafile. Use the GetObjectType function to determine whether the device context refers to a device in an enhanced metafile.

HORZSIZE Physical screen width in millimeters.

VERTSIZE Physical screen height in millimeters.

HORZRES Screen width in pixels.

VERTRES Screen height in raster lines.

LOGPIXELSX The number of horizontal pixels per logical inch.

LOGPIXELSY The number of vertical pixels per logical inch.

40

BITSPIXEL The number of adjacent color bits per pixel.

PLANES The number of color planes.

NUMBRUSHES The number of device-specific brushes.

NUMPENS The number of device-specific pens.

NUMFONTS The number of device-specific fonts.

NUMCOLORS The number of entries in the device’s color table, if the device has a color depth of 8 bits per pixel or less. It returns -1 for greater color depths.

ASPECTX Relative width of a device pixel used for line drawing.

ASPECTY Relative height of a device pixel used for line drawing.

ASPECTXY Diagonal width of the device pixel used for line drawing.

CLIPCAPS Clipping capability indicator of the device. If the device can clip to a rectangle, this value is 1; otherwise it is 0.

SIZEPALETTE The number of system palette entries. This result is valid only for Windows 3.0 or later drivers, and only if the device driver sets the RC_PALETTE bit in the RASTERCAPS index.

NUMRESERVED Number of reserved entries in the system palette. This index is valid only for Windows 3.0 or later drivers, and only if the device driver sets the RC_PALETTE bit in the RASTERCAPS index.

COLORRES Device color resolution in bits per pixel. This index is valid only for Windows 3.0 or later drivers, and only if the device driver sets the RC_PALETTE bit in the RASTERCAPS index.

PHYSICALWIDTH Physical width of a printed page for printing devices, in device units. This is generally a larger number than the printable pixel width of the page because of nonprintable margins.

PHYSICALHEIGHT Physical height of a printed page for printing devices, in device units. This is generally a larger number than the printable pixel height of the page because of nonprintable margins.

PHYSICALOFFSETX Left printer margin. This is the distance from the left edge of

PHYSICALOFFSETX Left printer margin. This is the distance from the left edge of

Related documents