Skip to content

Latest commit

 

History

History
1908 lines (957 loc) · 38.2 KB

PyCDC.md

File metadata and controls

1908 lines (957 loc) · 38.2 KB

PyCDC

PyCDC Object

A Device Context. Encapsulates an MFC CDC

class.

Methods

  • AbortDoc

    Aborts a print job 

  • Arc

    Draws an arc. 

  • BeginPath

    Opens a path bracket in the device context 

  • BitBlt

    Copies a bitmap 

  • Chord

    Draws a chord. 

  • CreateCompatibleDC

    Creates a memory DC compatible with this DC. 

  • CreatePrinterDC

    Creates a device context for a specific printer 

  • DeleteDC

    Deletes all resources associated with a device context. 

  • DPtoLP

    Convert from device points to logical points. 

  • Draw3dRect

    Draws a three-dimensional rectangle. 

  • DrawFocusRect

    Draws a rectangle in the style used to indicate the rectangle has focus 

  • DrawFrameControl

    Draws a frame control of the specified type and style. 

  • DrawIcon

    Draws an icon on the DC. 

  • DrawText

    Formats text in the given rectangle 

  • Ellipse

    Draws an Ellipse. 

  • EndDoc

    Finishes spooling the document and starts printing it 

  • EndPage

    Finishes a page on a printer DC 

  • EndPath

    Closes a path bracket and selects the path defined by the bracket into the specified device context 

  • ExtTextOut

    Writes text to the DC. 

  • FillPath

    Closes any open figures in the current path and fills the path's interior by using the current brush and polygon-filling mode. 

  • FillRect

    Fills a given rectangle with the specified brush 

  • FillSolidRect

    Fills the given rectangle with the specified solid color. 

  • FrameRect

    Draws a border around the rectangle specified by rect 

  • GetBrushOrg

    Retrieves the origin (in device units) of the brush currently selected for the device context. 

  • GetClipBox

    Retrives the current clipping region. 

  • GetCurrentPosition

    Retrieves the current position (in logical coordinates). 

  • GetDeviceCaps

    Retrieves current device capabilities. 

  • GetHandleAttrib

    Retrieves the handle of the attribute device context. 

  • GetHandleOutput

    Retrieves the handle of the output device context. 

  • GetMapMode

    Gets the mapping mode for the device context. 

  • GetNearestColor

    Returns the closest color a device can map. 

  • GetPixel

    Returns the value of a pixel at a location 

  • GetSafeHdc

    Returns the underlying windows handle for the DC object. 

  • GetTextExtent

    Calculates the size of the string. 

  • GetTextExtentPoint

    Alias for GetTextExtent - Calculates the size of the string. 

  • GetTextFace

    Retrieves the name of the current font. 

  • GetTextMetrics

    Retrieves the metrics for the current font. 

  • GetViewportExt

    Gets the viewport extent of the device context 

  • GetViewportOrg

    Gets the viewport origin of the device context 

  • GetWindowExt

    Gets the window extent of the device context 

  • GetWindowOrg

    Retrieves the x- and y-coordinates of the origin of the window associated with the device context. 

  • IntersectClipRect

    Creates a new clipping region by forming the intersection of the current region and the rectangle specified 

  • IsPrinting

    Returns 1 if the DC is currently printing, else 0 

  • LineTo

    Draws a line to a specified point. 

  • LPtoDP

    Convert from logical points to device points 

  • MoveTo

    Moves the current position to a specifed point. 

  • OffsetWindowOrg

    Modifies the coordinates of the window origin relative to the coordinates of the current window origin. 

  • OffsetViewportOrg

    Modifies the coordinates of the viewport origin relative to the coordinates of the current viewport origin 

  • PatBlt

    Creates a bit pattern on the device. 

  • Pie

    Draws a pie shape with specific starting and ending points in a rectangle 

  • PolyBezier

    Draws one or more Bezier splines. 

  • Polygon

    Draws an Polygon. 

  • Polyline

    Draws a Polyline. 

  • RealizePalette

    Maps palette entries in the current logical palette to the system palette. 

  • Rectangle

    Draws a rectangle using the current pen. The interior of the rectangle is filled using the current brush. 

  • RectVisible

    Determines if a rectangle is currently visisble in the viewport. 

  • RestoreDC

    Restores a saved DC. 

  • SaveDC

    Saves a DC. 

  • ScaleWindowExt

    Modifies the window extents relative to the current values. 

  • ScaleViewportExt

    Modifies the viewport extents relative to the current values. 

  • SelectClipRgn

    Selects the given region as the current clipping region for the device context 

  • SelectObject

    Selects an object into the DC. 

  • SelectObject

    Selects the logical palette. 

  • SetBkColor

    Sets the background color. 

  • SetBkMode

    Sets the background mode. 

  • SetBrushOrg

    Specifies the origin that GDI will assign to the next brush that the application selects into the device context. 

  • SetGraphicsMode

    Sets the graphics mode for the specified device context 

  • SetMapMode

    Sets the device mapping mode. 

  • SetPixel

    Set a pixel to a color 

  • SetPolyFillMode

    Sets the polygon-filling mode. 

  • SetROP2

    Sets the current drawing mode. 

  • SetTextAlign

    Sets the text alignment. 

  • SetTextColor

    Sets the text foreground color. 

  • SetWindowExt

    Sets the extents of the window. 

  • SetWindowOrg

    Sets the window origin of the device context 

  • SetViewportExt

    Sets the extents of the window's viewport. 

  • SetViewportOrg

    Sets the viewport origin of the device context 

  • SetWorldTransform

    sets a two-dimensional linear transformation between world space and page space for the specified device context. 

  • StartDoc

    Starts spooling a document to a printer DC 

  • StartPage

    Starts a new page on a printer DC 

  • StretchBlt

    Copies a bitmap from the source device context to this device context. 

  • StrokeAndFillPath

    Closes any open figures in a path, strokes the outline of the path by using the current pen, and fills its interior by using the current brush. The device context must contain a closed path. 

  • StrokePath

    Renders the specified path by using the current pen. 

  • TextOut

    Writes text to the DC. 

PyCDC.AbortDoc

AbortDoc() Aborts a print job

PyCDC.Arc

Arc(rect, pointStart, pointEnd) Draws an eliptical arc.

Parameters

  • rect : (left, top, right, bottom)

    Specifies the ellipse's bounding rectangle

  • pointStart : (x,y)

    Specifies the x- and y-coordinates

of the point that defines the arc's starting point (in logical units).

This point does not have to lie exactly on the arc.

  • pointEnd : (x,y)

    Specifies the x- and y-coordinates

of the point that defines the arc's ending point (in logical units).

This point does not have to lie exactly on the arc.

Comments

The arc drawn by using the function is a segment of the ellipse defined by the specified bounding rectangle.

The actual starting point of the arc is the point at which a ray drawn

from the center of the bounding rectangle through the specified starting

point intersects the ellipse. The actual ending point of the arc is the

point at which a ray drawn from the center of the bounding rectangle through

the specified ending point intersects the ellipse. The arc is drawn in a

counterclockwise direction. Since an arc is not a closed figure, it is

not filled. Both the width and height of the rectangle must be greater

than 2 units and less than 32,767 units.

MFC References

  • CDC::Arc

Return Value

Always none. If the function fails, an exception is raised.

PyCDC.BeginPath

BeginPath() Opens a path bracket in the device context

PyCDC.BitBlt

BitBlt(destPos, size, dc, srcPos, rop) Copies a bitmap from the source device context to this device context.

Parameters

  • destPos : (x,y)-ints

    The logical x,y coordinates of the upper-left corner of the destination rectangle.

  • size : (width, height)-ints

    Specifies the width and height (in logical units) of the destination rectangle and source bitmap.

  • dc : PyCDC

    Specifies the PyCDC object from which the bitmap will be copied. It must be None if rop specifies a raster operation that does not include a source.

  • srcPos : (xSrc, ySrc)-ints

    Specifies the logical x,y coordinates of the upper-left corner of the source bitmap.

  • rop : int

    Specifies the raster operation to be performed. See the win32 api documentation for details.

MFC References

  • CDC::BitBlt

PyCDC.Chord

Chord(rect, pointStart, pointEnd) Draws a chord.

Parameters

  • rect : (left, top, right, bottom)

    Specifies the ellipse's bounding rectangle

  • pointStart : (x,y)

    Specifies the x- and y-coordinates

of the point that defines the arc's starting point (in logical units).

This point does not have to lie exactly on the arc.

  • pointEnd : (x,y)

    Specifies the x- and y-coordinates

of the point that defines the arc's ending point (in logical units).

This point does not have to lie exactly on the arc.

Comments

Draws a chord (a closed figure bounded by the intersection

of an ellipse and a line segment). The rect parameter specify the

upper-left and lower-right corners, respectively, of a rectangle

bounding the ellipse that is part of the chord.

The pointStart and pointEnd parameters specify

the endpoints of a line that intersects the ellipse.

The chord is drawn by using the selected pen and filled

by using the selected brush.

MFC References

  • CDC::Chord

Return Value

Always none. If the function fails, an exception is raised.

PyCDC.CreateCompatibleDC

CreateCompatibleDC(dcFrom) Creates a memory device context that is compatible with this DC.

Parameters

  • dcFrom=None : PyCDC

    The source DC, or None to make a screen compatible DC.

Comments

Note that unlike the MFC version, this function

calls the global CreateCompatibleDC function and returns

a new PyCDC object.

MFC References

  • CDC::CreateCompatibleDC

PyCDC.CreatePrinterDC

CreatePrinterDC(printerName) Creates a device context for a specific printer

Parameters

  • printerName=None : string

    The printer name, or None for the default printer

MFC References

  • CDC::CreateDC

PyCDC.DPtoLP

(x,y) = DPtoLP(point) Converts device units into logical units.

Parameters

  • point : (x,y)

    The point to convert

Alternative Parameters

  • x

    The x coordinate to convert.

  • y

    The y coordinate to convert.

MFC References

  • CDC::DPtoLP

To Do

Should really handle list of (x,y) points

Return Value

The converted coordinates.

PyCDC.DeleteDC

DeleteDC() Deletes all resources associated with a device context.

Comments

In general, do not call this function; the destructor will do it for you.

An application should not call DeleteDC if objects have been selected into the device context. Objects must first be selected out of the device context before it it is deleted.

An application must not delete a device context whose handle was obtained by calling CWnd::GetDC. Instead, it must call CWnd::ReleaseDC to free the device context.

The DeleteDC function is generally used to delete device contexts created with CreateDC, CreateIC, or CreateCompatibleDC.

PyCDC.Draw3dRect

Draw3dRect(rect, colorTopLeft, colorBotRight) Draws a three-dimensional rectangle.

Parameters

  • rect : (left, top, right, bottom

    Specifies the bounding rectangle, in logical units.

  • colorTopLeft : int

    Specifies the color of the top and left sides of the three-dimensional rectangle.

  • colorBotRight : int

    Specifies the color of the bottom and right sides of the three-dimensional rectangle.

MFC References

  • CDC::Draw3dRect

PyCDC.DrawFocusRect

DrawFocusRect(rect) Draws a rectangle in the style used to

indicate the rectangle has focus

Parameters

  • rect : (left, top, right, bottom)

    The coordinates of the

rectangle

MFC References

  • CDC::DrawFocusRect

PyCDC.DrawFrameControl

DrawFrameControl(rect, typ, state) Draws a frame control of the specified type and style.

Parameters

  • rect : (left, top, right, bottom)

    Specifies the bounding rectangle, in logical units.

  • typ : int

  • state : int

MFC References

  • CDC::DrawFrameControl

PyCDC.DrawIcon

DrawIcon(point, hIcon) Draws an icon on the DC.

Parameters

  • point : (x,y)

    The point coordinate to draw to.

  • hIcon : PyHANDLE

    The handle of the icon to draw.

MFC References

  • CDC::DrawIcon

PyCDC.DrawText

s,rc,forat = DrawText(s, tuple

, format

) Formats text in the given rectangle

Parameters

  • s : string

    The desired output string

  • tuple : (int, int, int, int)

    The bounding rectangle in the form:

(left, top, right, bottom) expressed in logical units (depending on

selected coordinate system - see PyCDC::SetMapMode)

  • format : int

    Specifies one or more bit-or'd format values, such as

DT_BOTTOM, DT_CENTERDT_RIGHT, DT_VCENTER. For a complete list, see

the Microsoft Win32 API documentation.

Example

Example

import win32ui&ltnl&gt

import win32con&ltnl&gt

INCH = 1440 # twips - 1440 per inch allows fine res&ltnl&gt

def drawtext_test():&ltnl&gt

 dc = win32ui\.CreateDC\(\)&ltnl&gt

 dc\.CreatePrinterDC\(\)                \# ties to default printer&ltnl&gt

 dc\.StartDoc\('My Python Document'\)&ltnl&gt

 dc\.StartPage\(\)&ltnl&gt

&ltnl&gt

 \# note: upper left is 0,0 with x increasing to the right,&ltnl&gt

 \#       and y decreasing \(negative\) moving down&ltnl&gt

 dc\.SetMapMode\(win32con\.MM\_TWIPS\)&ltnl&gt

&ltnl&gt

 \# Centers "TEST" about an inch down on page&ltnl&gt

 dc\.DrawText\('TEST', \(0,INCH\*-1,INCH\*8,INCH\*-2\), win32con\.DT\_CENTER \)&ltnl&gt

 dc\.EndPage\(\)&ltnl&gt

 dc\.EndDoc\(\)&ltnl&gt

 del dc&ltnl&gt

Return Value

Height of text in pixels

The return value is the height of the text, in logical units.

If DT_VCENTER or DT_BOTTOM is specified, the return value is the

offset from rect.top to the bottom of the drawn text.

If the function fails, the return value is zero (no Python exception is thrown)

PyCDC.Ellipse

Ellipse(rect) Draws an Ellipse.

Parameters

  • rect : (left, top, right, bottom)

    Specifies the ellipse's bounding rectangle

Comments

The center of the ellipse is the center of the bounding rectangle

specified by rect. The ellipse is drawn with the current pen, and its

interior is filled with the current brush.

MFC References

  • CDC::Ellipse

Return Value

Always none. If the function fails, an exception is raised.

PyCDC.EndDoc

EndDoc() Finishes spooling the document and starts printing it

PyCDC.EndPage

EndPage() Finishes a page on a printer DC

PyCDC.EndPath

EndPath() Closes a path bracket and selects the path defined by the bracket into the specified device context

PyCDC.ExtTextOut

ExtTextOut(int, int, int, rect, string, tuple) Writes text to the DC.

Parameters

  • int : x

    The x coordinate to write the text to.

  • int : y

    The y coordinate to write the text to.

  • int : nOptions

    Specifies the rectangle type. This parameter can be one, both, or neither of ETO_CLIPPED and ETO_OPAQUE

  • rect : (left, top, right, bottom)

    Specifies the text's bounding rectangle. (Can be None.)

  • string : text

    The text to write.

  • tuple : (width1, width2, ...)

    Optional array of values that indicate distance between origins of character cells.

MFC References

  • CDC::ExtTextOut

Return Value

Always none. If the function fails, an exception is raised.

PyCDC.FillPath

FillPath() Closes any open figures in the current path and fills the path's interior by using the current brush and polygon-filling mode. After its interior is filled, the path is discarded from the device context.

PyCDC.FillRect

FillRect(rect, brush) Fills a given rectangle with the specified brush

Parameters

  • rect : (left, top, right, bottom

    Specifies the bounding rectangle, in logical units.

  • brush : PyCBrush

    Specifies the brush to use.

MFC References

  • CDC::FillRect

PyCDC.FillSolidRect

FillSolidRect(rect, color) Fills the given rectangle with the specified solid color.

Parameters

  • rect : (left, top, right, bottom

    Specifies the bounding rectangle, in logical units.

  • color : int

    Specifies the color to use.

MFC References

  • CDC::FillSolidRect

PyCDC.FrameRect

FrameRect(rect, brush) Draws a border around the rectangle specified by rect

Parameters

  • rect : (left, top, right, bottom

    Specifies the bounding rectangle, in logical units.

  • brush : PyCBrush

    Specifies the brush to use.

MFC References

  • CDC::FrameRect

PyCDC.GetBrushOrg

(int,int) = GetBrushOrg() Retrieves the origin (in device units) of the brush currently selected for the device context.

MFC References

  • CDC::GetBrushOrg

PyCDC.GetClipBox

(left, top, right, bottom) = GetClipBox() Retrieves the dimensions of the smallest bounding rectangle around the current clipping boundary.

MFC References

  • CDC::GetClipBox

Return Value

A tuple of integers specifying the rectangle.

PyCDC.GetCurrentPosition

(x, y) = GetCurrentPosition() Retrieves the current position (in logical coordinates).

PyCDC.GetDeviceCaps

int = GetDeviceCaps(index) Retrieves a capability of the device context.

Parameters

  • index : int

    The information requested. See the win32api documentation for details.

MFC References

  • CDC::GetDeviceCaps

Return Value

The value of the requested capability

PyCDC.GetHandleAttrib

int = GetHandleAttrib() Retrieves the handle of the attribute device context.

PyCDC.GetHandleOutput

int = GetHandleOutput() Retrieves the handle of the output device context.

PyCDC.GetMapMode

int = GetMapMode() Gets the mapping mode for the device context.

MFC References

  • CDC::GetMapMode

PyCDC.GetNearestColor

int = GetNearestColor(color) Returns the closest color a device can map.

Parameters

  • color : int

    Specifies the color to be matched.

PyCDC.GetPixel

GetPixel(x, y) Gets a pixel at a local in a device context

Parameters

  • x : int

    Horizontal coordinate.

  • y : int

    Vertical coordinate.

PyCDC.GetSafeHdc

int = GetSafeHdc() Returns the HDC of this DC object.

MFC References

  • CDC::GetSafeHdc

PyCDC.GetTextExtent

(x,y) = GetTextExtent(text) Calculates the width and height of a line of text using the current font to determine the dimensions.

Parameters

  • text : string

    The text to calculate for.

MFC References

  • CFC::GetTextExtent

Return Value

A tuple of integers with the size of the string, in logical units.

PyCDC.GetTextExtentPoint

(x,y) = GetTextExtentPoint(text) An alias for PyCDC::GetTextExtent.

GetTextExtentPoint is the preferred win32api name, but GetTextExtent is the MFC name.

Calculates the width and height of a line of text using the current font to determine the dimensions.

Parameters

  • text : string

    The text to calculate for.

Return Value

A tuple of integers with the size of the string, in logical units.

PyCDC.GetTextFace

string = GetTextFace() Returns typeface name of the current font.

MFC References

  • CDC::GetTextFace

PyCDC.GetTextMetrics

dict = GetTextMetrics() Retrieves the metrics for the current font in this device context.

MFC References

  • CDC::GetTextMetrics

Return Value

A dictionary of integers, keyed by the following strings:

tmHeight

tmAscent

tmDescent

tmInternalLeading

tmExternalLeading

tmAveCharWidth

tmMaxCharWidth

tmWeight

tmItalic

tmUnderlined

tmStruckOut

tmFirstChar

tmLastChar

tmDefaultChar

tmBreakChar

tmPitchAndFamily

tmCharSet

tmOverhang

tmDigitizedAspectX

tmDigitizedAspectY

PyCDC.GetViewportExt

x, y = GetViewportExt() Gets the viewport extent of the device context

PyCDC.GetViewportOrg

x, y = GetViewportOrg() Gets the viewport origin of the device context

PyCDC.GetWindowExt

x, y = GetWindowExt() Gets the window extent of the device context

PyCDC.GetWindowOrg

x, y = GetWindowOrg() Retrieves the x- and y-coordinates of the origin of the window associated with the device context.

PyCDC.IntersectClipRect

IntersectClipRect(rect) Creates a new clipping region by forming the intersection of the current region and the rectangle specified

Parameters

  • rect : (left, top, right, bottom)

    Specifies the bounding rectangle, in logical units.

MFC References

  • CDC::IntersectClipRect

Return Value

region type as integer

PyCDC.IsPrinting

int = IsPrinting() Returns 1 if the DC is currently printing, else 0

PyCDC.LPtoDP

(x,y) = LPtoDP(point) Converts logical units into device units.

Parameters

  • point : (x,y)

    The point coordinate to convert.

Alternative Parameters

  • x

    The x coordinate to convert.

  • y

    The y coordinate to convert.

MFC References

  • CDC::LPtoDP

Return Value

The converted coordinates.

PyCDC.LineTo

LineTo(point) Draws a line to a specified point, using the currently selected pen.

Parameters

  • point : (x,y)

    The point coordinate to draw to.

Alternative Parameters

  • x

    The x coordinate to draw to.

  • y

    The y coordinate to draw to.

MFC References

  • CDC::LineTo

PyCDC.MoveTo

(x,y) = MoveTo(point) Moves the current position to a specified point.

Parameters

  • point : (x,y)

    The point coordinate to move to.

Alternative Parameters

  • x

    The x coordinate to move to.

  • y

    The y coordinate to move to.

MFC References

  • CDC::MoveTo

Return Value

The previous position.

PyCDC.OffsetViewportOrg

x, y = OffsetViewportOrg(x,y) Modifies the coordinates of the viewport origin relative to the coordinates of the current viewport origin

Parameters

  • x,y : int, int

    The new origin offset.

Return Value

The previous viewport origin as a tuple (x,y)

PyCDC.OffsetWindowOrg

x, y = OffsetWindowOrg(x,y) Modifies the coordinates of the window origin relative to the coordinates of the current window origin.

Parameters

  • x,y : int, int

    The new origin offset.

Return Value

The previous origin as a tuple (x,y)

PyCDC.PatBlt

PatBlt(destPos, size, rop) Creates a bit pattern on the device.

Parameters

  • destPos : (x,y)-ints

    The logical x,y coordinates of the upper-left corner of the destination rectangle.

  • size : (width, height)-ints

    Specifies the width and height (in logical units) of the destination rectangle and source bitmap.

  • rop : int

    Specifies the raster operation to be performed. See the win32 api documentation for details.

MFC References

  • CDC::BitBlt

PyCDC.Pie

Pie(x1, y1, x2, y2, x3, y3, x4, y4) Draws a pie slice in a device context

Parameters

  • x1 : int

    X coordinate of upper left corner

  • y1 : int

    Y coordinate of upper left corner

  • x2 : int

    X coordinate of lower right corner

  • y2 : int

    Y coordinate of lower right corner

  • x3 : int

    X coordinate of starting point of arc

  • y3 : int

    Y coordinate of starting point of arc

  • x4 : int

    X coordinate of ending point of arc

  • y4 : int

    Y coordinate of ending point of arc

PyCDC.PolyBezier

PolyBezier() Draws one or more Bezier splines.

PyCDC.Polygon

Polygon() Draws an Polygon.

PyCDC.Polyline

Polyline(points) Draws a Polyline.

Parameters

  • points : [(x, y), ...]

    A sequence of points

PyCDC.RealizePalette

int = RealizePalette() Maps palette entries in the current logical palette to the system palette.

Return Value

Indicates how many entries in the logical palette were mapped to different entries

in the system palette. This represents the number of entries that this function

remapped to accommodate changes in the system palette since the logical palette

was last realized.

PyCDC.RectVisible

int = RectVisible(rect) Determines whether any part of the given rectangle lies within the clipping region of the display context.

Parameters

  • rect : (left, top, right, bottom)

    The coordinates of the reactangle to be checked.

MFC References

  • CDC::RectVisible

Return Value

Non zero if any part of the rectangle lies within the clipping region, else zero.

PyCDC.Rectangle

rc = Rectangle() Draws a rectangle using the current pen. The interior of the rectangle is filled using the current brush.

PyCDC.RestoreDC

RestoreDC(saved) Restores the state of the device context.

Parameters

  • saved : int

    The id of a previously saved device context. See PyCDC::SaveDC

MFC References

  • CDC::RestoreDC

PyCDC.SaveDC

int = SaveDC() Saves the current state of the device context. Windows manages a stack of state information.

The saved device context can later be restored by using CDC::RestoreDC

MFC References

  • CDC::SaveDC

Return Value

An integer identifying the context, which can be used by PyCDC::RestoreDC.

An exception is raised if this function fails.

PyCDC.ScaleViewportExt

x, y = ScaleViewportExt() Modifies the viewport extents relative to the current values.

PyCDC.ScaleWindowExt

x, y = ScaleWindowExt() Modifies the window extents relative to the current values.

PyCDC.SelectClipRgn

obRgn = SelectClipRgn() Selects the given region as the current clipping region for the device context

Return Value

The return value specifies the region's complexity (integer)

PyCDC.SelectObject

object = SelectObject(ob) Selects an object into the device context.

Currently, only PyCFont, PyCBitMap, PyCBrush and PyCPen

objects are supported.

Parameters

  • ob : object

    The object to select.

MFC References

  • CDC::SelectObject

Return Value

The previously selected object. This will be the same type as the object parameter.

PyCDC.SelectPalette

int = SelectPalette(hPalette, forceBackground

) Sets the logical palette.

Parameters

  • hPalette : int

    The handle to the palette

  • forceBackground : int

    Specifies whether the logical palette is forced to be a background palette.

MFC References

  • CDC::SelectePalette

Return Value

The previous palette handle.

PyCDC.SetBkColor

int = SetBkColor(color) Sets the current background color to the specified color.

Parameters

  • color : int

    A windows color specification. See the win32api documentation for details.

Comments

If the background mode is OPAQUE, the system uses the background color

to fill the gaps in styled lines, the gaps between hatched lines in brushes, and

the background in character cells.

The system also uses the background color when converting bitmaps between color and

monochrome device contexts.

MFC References

  • CDC::SetBkColor

Return Value

The return value is the previous background color.

PyCDC.SetBkMode

int = SetBkMode(mode) Sets the current background mode to the specified mode.

Parameters

  • mode : int

    A background mode. May be either TRANSPARENT or OPAQUE.

Comments

Specifies the mode to be set. This parameter can be either OPAQUE or TRANSPARENT

MFC References

  • CDC::SetBkMode

Return Value

The return value is the previous background mode.

PyCDC.SetBrushOrg

(int, int) = SetBrushOrg(point) Specifies the origin that GDI will assign to the next brush that the application selects into the device context.

Parameters

  • point : (x,y)

    The new origin in device units.

MFC References

  • CDC::SetBrushOrg

Return Value

The previous origin in device units.

PyCDC.SetGraphicsMode

int = SetGraphicsMode(mode) Sets the graphics mode for the specified device context

Parameters

  • mode : int

    The new mode.

PyCDC.SetMapMode

int = SetMapMode(newMode) Sets the mapping mode for the device context.

Parameters

  • newMode : int

    The new mode. Can be one of

MM_ANISOTROPIC, MM_HIENGLISH, MM_HIMETRIC, MM_ISOTROPIC, MM_LOENGLISH, MM_LOMETRIC, MM_TEXT, MM_TWIPS

MFC References

  • CDC::SetMapMode

Return Value

The previous mapping mode.

PyCDC.SetPixel

SetPixel(x, y, color) Sets a pixel in a device context

Parameters

  • x : int

    Horizontal coordinate.

  • y : int

    Vertical coordinate.

  • color : int

    The brush color.

PyCDC.SetPolyFillMode

(int) = SetPolyFillMode(point) Sets the polygon-filling mode.

Parameters

  • point : (x,y)

    The new origin in device units.

MFC References

  • CDC::SetPolyFillMode

Return Value

The previous PolyFillMode as integer

The previous PolyFillMode.

PyCDC.SetROP2

dict = SetROP2(mode) Sets the current drawing mode.

Parameters

  • mode : int

    The new drawing mode.

MFC References

  • CDC::SetROP2

PyCDC.SetTextAlign

int = SetTextAlign(newFlags) Sets the text-alignment flags.

Parameters

  • newFlags : int

    The new alignment flags. Can be a combination of (TA_CENTER, TA_LEFT, TA_RIGHT), (TA_BASELINE, TA_BOTTOM, TA_TOP) and (TA_NOUPDATECP, TA_UPDATECP)

The default is TA_LEFT|TA_TOP|TA_NOUPDATECP

MFC References

  • CDC::SetTextAlign

Return Value

The old alignment flags.

PyCDC.SetTextColor

int = SetTextColor(color) Sets the text color to the specified color.

Parameters

  • color : int

    A windows color specification. See the win32api documentation for details.

Comments

This text color is used when writing text to this device context and also when converting bitmaps between color and monochrome device contexts.

If the device cannot represent the specified color, the system sets the text color to the nearest physical color.

The background color for a character is specified by the SetBkColor and SetBkMode member functions.

MFC References

  • CDC::SetTextColor

Return Value

The return value is the previous text color.

PyCDC.SetViewportExt

(x,y) = SetViewportExt(size) Sets the x,y extents of the viewport of the device context.

Parameters

  • size : (x,y)

    The new size.

MFC References

  • CDC::SetViewportExt

Return Value

The previous extents of the viewport (in logical units).

PyCDC.SetViewportOrg

x, y = SetViewportOrg(x,y) Sets the viewport origin of the device context

Parameters

  • x,y : int, int

    The new origin.

PyCDC.SetWindowExt

(x,y) = SetWindowExt(size) Sets the x,y extents of the window associated with the device context.

Parameters

  • size : (x,y)

    The new size.

MFC References

  • CDC::SetWindowExt

Return Value

The previous extents of the window (in logical units).

PyCDC.SetWindowOrg

x, y = SetWindowOrg(x,y) Sets the window origin of the device context

Parameters

  • x,y : int, int

    The new origin.

PyCDC.SetWorldTransform

int = SetWorldTransform() sets a two-dimensional linear transformation between world space and page space for the specified device context. This transformation can be used to scale, rotate, shear, or translate graphics output.

PyCDC.StartDoc

StartDoc(docName, outputFile) Starts spooling a document to a printer DC

Parameters

  • docName : string

    The document name

  • outputFile : string

    The output file name. Use this to spool to a file. Omit to send to the printer.

PyCDC.StartPage

StartPage() Starts a new page on a printer DC

PyCDC.StretchBlt

StretchBlt(destPos, size, dc, srcPos, size, rop) Copies a bitmap from the source device context to this device context.

Parameters

  • destPos : (x,y)-ints

    The logical x,y coordinates of the upper-left corner of the destination rectangle.

  • size : (width, height)-ints

    Specifies the width and height (in logical units) of the destination rectangle and source bitmap.

  • dc : PyCDC

    Specifies the PyCDC object from which the bitmap will be copied. It must be None if rop specifies a raster operation that does not include a source.

  • srcPos : (xSrc, ySrc)-ints

    Specifies the logical x,y coordinates of the upper-left corner of the source bitmap.

  • size : (widthsrc, heightsrc)-ints

    Specifies the width and height (in logical units) of the destination rectangle and source bitmap.

  • rop : int

    Specifies the raster operation to be performed. See the win32 api documentation for details.

MFC References

  • CDC::StretchBlt

PyCDC.StrokeAndFillPath

StrokeAndFillPath() Closes any open figures in a path, strokes the outline of the path by using the current pen, and fills its interior by using the current brush. The device context must contain a closed path.

PyCDC.StrokePath

StrokePath() Renders the specified path by using the current pen.

PyCDC.TextOut

TextOut(int, int, string) Outputs text to the display context, using the currently selected font.

Parameters

  • int : x

    The x coordinate to write the text to.

  • int : y

    The y coordinate to write the text to.

  • string : text

    The text to write.

MFC References

  • CDC::TextOut

Return Value

Always none. If the function fails, an exception is raised.