Download Source Code

CText Class Reference

Encapsulates Windows GDI text drawing functions. More...

#include <Text.h>

List of all members.

Public Member Functions

BOOL ChooseFont (HWND hWnd)
 Displays the Windows font chooser dialog box.
BOOL DrawMonoSpacedText (HDC hDC, LPCTSTR pText, LPRECT pRect)
 Draws any font as monospaced.
long CalcTextWidth (HDC hDC, long *pWidth=NULL)
 Calculates the width of the specified text.
long CalcTextHeight (HDC hDC, long *pHeight=NULL)
 Calculates the height of the specified text.
BOOL CalcRect (HDC hDC, LPCTSTR pText, LPRECT pRect)
 Calculates the size of a text string.
BOOL GetFont (LPLOGFONT pFont)
 Gets a copy of the current font information.
BOOL SetFont (LPLOGFONT pFont)
 Sets the font.
void Default ()
 Sets default text attributes.
BOOL DrawText (HDC hDC, LPCTSTR pText, LPRECT pRect)
 Draws the specified text into a Device Context.
void Destroy ()
 Releases all resources allocated for this class.
BOOL SetFont (DWORD dwSize, LPCTSTR pFont)
 Sets a font by font name and size.
 CText ()
 Constructor.
virtual ~CText ()
 Destructor.
void SetXMargin (long x)
 Sets the horizontal text margin.
void SetYMargin (long y)
 Sets vertical text margin.
void SetMargins (long x, long y)
 Sets the text margins.
void SetEscapement (int v=0)
 Sets the text rotation.
void SetWeight (int w=FW_NORMAL)
 Sets the text weight.
void SetItalic (BOOL b=FALSE)
 Enables / disables italic text.
void SetUnderline (BOOL b=FALSE)
 Enables / disables underlined text.
void SetStrikeOut (BOOL b=FALSE)
 Enables / disables striked out text.
void SetColor (COLORREF col=MAXDWORD)
 Sets the text color.
COLORREF GetColor ()
 Returns current text color.
void SetFlags (DWORD f=DT_CENTER|DT_VCENTER|DT_WORDBREAK|DT_NOCLIP|DT_SINGLELINE)
 Sets the text flags.
DWORD GetFlags ()
 Returns current text flags.
void CalcTextBox (HDC hDC)
 Calculates the size of a single text character.
BOOL SetMonoSpacedText (HDC hDC)
 Sets up for drawing mono-spaced font for any font type.
void SetMonoSpacedTextMetrics (long w, long h)
 Sets the width and height of a mono-spaced character.
void SetMonoSpacedTabs (DWORD t)
 Size of a mono spaced tab character.
DWORD GetMonoTextWidth ()
 Returns the mono-spaced width of a single character.
DWORD GetMonoTextHeight ()
 Returns the mono-spaced height of a single character.
 operator LPLOGFONT ()
 Returns a pointer to the LOGFONT structure for the current font.
 operator HFONT ()
 Returns the HFONT handle of the current font.
BOOL IsFont ()
 Returns non-zero if a font is loaded.
LPLOGFONT GetLogFont ()
 Returns a pointer to the LOGFONT structure for the current font.

Static Public Member Functions

static DWORD WriteBuffer (LPSTR out, DWORD op, DWORD om, LPCTSTR buf, DWORD size)
 Provides generic buffer writing.
static DWORD HtmlText (LPSTR out, DWORD odw, LPCTSTR buf, DWORD size, BOOL bHyperLinks)
 Adds HTML escape sequences to text.
static BOOL ChooseFont (LPLOGFONT pFont, HWND hWnd=NULL, BOOL bInit=FALSE, COLORREF *pRGB=NULL)
 Displays Windows font chooser dialog box.


Detailed Description

Encapsulates Windows GDI text drawing functions.

Use this class to draw text into DC objects


Member Function Documentation

BOOL CText::CalcRect HDC  hDC,
LPCTSTR  pText,
LPRECT  pRect
 

Calculates the size of a text string.

Parameters:
[in] hDC - DC handle that would receive text
[in] pText - Text string
[in] pRect - Receives the calculated size of the text
Returns:
Non-zero if success
See also:

void CText::CalcTextBox HDC  hDC  )  [inline]
 

Calculates the size of a single text character.

Parameters:
[in] hDC - DC handle where text would be drawn

long CText::CalcTextHeight HDC  hDC,
long *  pHeight = NULL
 

Calculates the height of the specified text.

Parameters:
[in] hDC - Handle to DC that would receive text
[in] pHeight - Pointer that receives the text height
Returns:
Height of text in pixels
See also:

long CText::CalcTextWidth HDC  hDC,
long *  pWidth = NULL
 

Calculates the width of the specified text.

Parameters:
[in] hDC - Handle to DC that would receive text
[out] pWidth - Pointer that receives the text width
Returns:
Width of text in pixels
See also:

BOOL CText::ChooseFont LPLOGFONT  pFont,
HWND  hWnd = NULL,
BOOL  bInit = FALSE,
COLORREF *  pRGB = NULL
[static]
 

Displays Windows font chooser dialog box.

Parameters:
[in] pFont - Pointer to LOGFONT structure
[in] hWnd - Handle to parent window
[in] bInit - True if pFont contains initial font info
[in] pRGB - Pointer to variable that receives font color
Returns:
Non-zero if success
See also:

BOOL CText::ChooseFont HWND  hWnd  ) 
 

Displays the Windows font chooser dialog box.

Parameters:
[in] hWnd - Parent window handle
Returns:
Non-zero if new font was choosen
See also:

BOOL CText::DrawMonoSpacedText HDC  hDC,
LPCTSTR  pText,
LPRECT  pRect
 

Draws any font as monospaced.

Parameters:
[in] hDC - DC handle for drawing
[in] pText - Text string
[in] pRect - Position of text
Returns:
Non-zero if success
See also:

BOOL CText::DrawText HDC  hDC,
LPCTSTR  pText,
LPRECT  pRect
 

Draws the specified text into a Device Context.

Parameters:
[in] hDC - DC handle that receives text
[in] pText - Text to draw into hDC
[in] pRect - Position for text
Returns:
Non-zero if success
See also:

BOOL CText::GetFont LPLOGFONT  pFont  ) 
 

Gets a copy of the current font information.

Parameters:
[in] pFont - Receives font data
Returns:
Non-zero if succcess
See also:

DWORD CText::HtmlText LPSTR  out,
DWORD  odw,
LPCTSTR  buf,
DWORD  size,
BOOL  bHyperLinks
[static]
 

Adds HTML escape sequences to text.

Parameters:
[in] out - Buffer receiving data
[in] odw - Size of buffer in out
[in] buf - Data to write
[in] size - Number of bytes in buf
[in] bHyperLinks - Set to non-zero to resolve hyperlinks
Returns:
odw + number of bytes written to out
See also:

void CText::SetColor COLORREF  col = MAXDWORD  )  [inline]
 

Sets the text color.

Parameters:
[in] col - New color for text

void CText::SetEscapement int  v = 0  )  [inline]
 

Sets the text rotation.

Parameters:
[in] v - New escapement value
This is basically the rotation angle in degrees

void CText::SetFlags DWORD  f = DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_NOCLIP | DT_SINGLELINE  )  [inline]
 

Sets the text flags.

Parameters:
[in] f - Text flags

BOOL CText::SetFont DWORD  dwSize,
LPCTSTR  pFont
 

Sets a font by font name and size.

Parameters:
[in] dwSize - Point size for font
[in] pFont - Name of the font
Returns:
Non-zero if success
See also:

BOOL CText::SetFont LPLOGFONT  pFont  ) 
 

Sets the font.

Parameters:
[in] pFont - Pointer to LOGFONT structure describing font
Returns:
Non-zero if success
See also:

void CText::SetItalic BOOL  b = FALSE  )  [inline]
 

Enables / disables italic text.

Parameters:
[in] b - Non-zero for italic text, zero for normal text

void CText::SetMargins long  x,
long  y
[inline]
 

Sets the text margins.

Parameters:
[in] x - Horizontal text margin
[in] y - Vertical text margin

void CText::SetMonoSpacedTabs DWORD  t  )  [inline]
 

Size of a mono spaced tab character.

Parameters:
[in] t - Size of a tab character

BOOL CText::SetMonoSpacedText HDC  hDC  )  [inline]
 

Sets up for drawing mono-spaced font for any font type.

Parameters:
[in] hDC - DC handle that will receive text
Returns:
Non-zero if success
See also:

void CText::SetMonoSpacedTextMetrics long  w,
long  h
[inline]
 

Sets the width and height of a mono-spaced character.

Parameters:
[in] w - Horizontal size of a single character
[in] h - Vertical size of a single character

void CText::SetStrikeOut BOOL  b = FALSE  )  [inline]
 

Enables / disables striked out text.

Parameters:
[in] b - Non-zero for striked out text, zero for normal text

void CText::SetUnderline BOOL  b = FALSE  )  [inline]
 

Enables / disables underlined text.

Parameters:
[in] b - Non-zero for underlined text, zero for normal text

void CText::SetWeight int  w = FW_NORMAL  )  [inline]
 

Sets the text weight.

Parameters:
[in] w - Font weight

void CText::SetXMargin long  x  )  [inline]
 

Sets the horizontal text margin.

Parameters:
[in] x - Horizontal text margin

void CText::SetYMargin long  y  )  [inline]
 

Sets vertical text margin.

Parameters:
[in] y - Vertical text margin

DWORD CText::WriteBuffer LPSTR  out,
DWORD  op,
DWORD  om,
LPCTSTR  buf,
DWORD  size
[static]
 

Provides generic buffer writing.

Parameters:
[in] out - Buffer receiving data
[in] op - Starting offset in out
[in] om - Size of buffer in out
[in] buf - Data to write
[in] size - Number of bytes in buf
Returns:
op + number of bytes written to out
See also:


The documentation for this class was generated from the following files:
  • inc/Text.h
  • Text.cpp
Copyright Robert Umbehant
This documentation is covered by the LGPL