WTL Controls
Back to the WTL Controls Home Page.
BIS WTL Controls Library

This library provides a set of enhanced user interface controls for use with the WTL application framework. There is nothing particularly innovative or revolutionary - examples of owner-drawn controls for MFC or SDK-style windows programs, for instance, have been around forever. WTL-centric versions have been harder to find. So to fill that void in my own work (and I'm a big WTL fan), I put this collection together. Custom UI appearances are implemented via a number of techniques: the simplest are CStatic descendants, overriding the WM_PAINT handler; several exploit WM_CTLCOLOR messages; and three exploit classic owner-drawn methodology.

These are listed below:

   • CBevel    A CStatic descendant which creates a single or two-tone beveled line, oriented horizontally or vertically.
   • CColorBlob    A CStatic descendant providing customizable background color and edge style, but no text.
   • CComboBoxPlus    A CComboBox descendant providing customizable background and text colors for both the edit and list box portions of the control.
   • CEditPlus    A CEdit descendant, providing custom focused and non-focused colors via WM_CTLCOLOR.
   • CHyperlinkImage    A CStatic descendant providing a context menu with a single entry, allowing the launch of the default browser to a pre-defined URL.
   • CODComboBox    An owner-drawn combo box featuring textual content with customizable per-item colors and fonts.
   • CODStatic    An owner-drawn CStatic descendant, providing custom background and text colors and edge styles.
   • CStaticPlus    A very simple CStatic enhancement, providing custom text and background colors via WM_CTLCOLORSTATIC.
   • CStatusBarPlus    A CMultiPaneStatusBarCtrl descendant with a child CProgressBarCtrl that can be embedded in a user-selected pane. Default configuration creates a status bar with three panes, with the second owner-drawn, and the progress bar embedded in the third.
   • CToolTipPlus    A CToolTipCtrl descendant providing a couple added member functions making it easier and more convenient to use.

Also included is an assortment of 10 utility functions and a small set of named color constants that I have found useful. Some of these utility functions were gathered from various sources (MSDN, primarily), and some I wrote myself. These utility functions are summarized below:

   • CString Double_To_String (double number, int precision)    Convert a double to a CString, with a given number of significant digits.
   • CString Int_To_String (int value, int max_digits)    Converts a multi-digit integer into a CString with _itot_s, then strips any leading zeros.
   • double Sgn (double value)    Returns 0.0 is the input was 0.0, -1.0 if the input was less than zero and +1.0 if the input was greater than zero.
   
   • BOOL FilePresent(LPCTSTR FullFileName)    Tests for the presence of a file using SearchPath.
   • void GetLastErrorString ()    Shows a Message Box containing human-friendly information about the last failed system API call.
   
   • BOOL OutlineRect (HDC HDestDC, const RECT& RDest)    This wraps the GDI Rectangle function. A transparent brush is used as fill, leaving the outline, drawn with the pen currently selected in the device context.
   • int GetCharHeight (HDC dc)    This wraps GetTextMetrics and returns the height in pixels of a character cell in the supplied device context, using the font currently selected into the context.
   • int GetTextLineCount (HDC dc, CString text, int width, BOOL IsEditControl = FALSE)    This function determines how many lines of text the GDI DrawText API will need to draw a given string, in a user-supplied device context, wrapping at a specified width.
   • int GetTextLength (CString, HFONT font)    The GDI function GetTextExtentPoint32 is used to measure the length of a string, in pixels, in a screen-compatible DC, with the supplied font.
   • void DlgComboInit (int nDlgID, HWND DlgHwnd)    There is a bug in ATL (through VS2017, anyway) that prevents combo boxes from loading strings defined at design time through the combo box's property pages. They will show up when the dialog is tested inside the IDE, but not at run time. Call this function from within the dialog's InitDialog handler and it will do the trick.