Click here to Skip to main content
15,069,133 members
Articles / Desktop Programming / WTL
Posted 12 Mar 2001


43 bookmarked

Owner Drawn WTL Controls

Rate me:
Please Sign up or sign in to vote.
4.42/5 (6 votes)
30 Apr 2001CPOL
The code in this demo package contains a colored label, a colored button with menu support, and a colored tab control for WTL.
  • Download source files - 28 Kb
  • Download demo project - 136 Kb
  • Sample Image - OwnerDrawn.gif


    The code submitted contains 3 main owner drawn controls that work with WTL. Along with a sample of a property sheet that can be embedded in a dialog and an add-in class that makes it easy to add tool tips to all of the controls in a dialog. They are all pretty straightforward to use and the demo program details how to work with them.

    Text Button Class

    There is a Text Button class that allows you to specify custom colors for and attach a menu to it. When you attach a menu to it a small arrow will be drawn at the end of it.
    Make sure that you include REFLECT_NOTIFICATIONS in any owners message map or the button will not be able to process the proper messages.
    One problem I have with the control is when it is transparent. Transparent controls by nature need the owner to paint the background behind them. I have not found a way to have the parent do this.

    In order to use the button you need to make the following calls

    Btn.SetColors(crText, crBack);
    Btn.SetBorderColors(crDark, crDkShadow, crLight);

    Color Label Class

    There is a color label class that allows labels to change the foreground color and will draw it transparently. You can also set the Font Name and Point Size along with Bold, Italic, Underline, and PointSize of the label.

    In order to use the label you need to make the following calls

    m_Label1.SetBold(true,		false);	
    m_Label1.SetTextColor(crText,	false);	
    m_Label1.SetBackColor(crBack,	false);	
    m_Label1.SetText("Label 1",	false);

    Owner Drawn Tab Control

    There is a also an owner drawn tab control that will allow colors to be set for the background, the selected tab, the unselected tab, and the text. You can also set a font, point size, and if it is bold.

    In order to use the Tab you need to make the following calls

    m_Tab.SetColors(crDark, crLight, crBack, crText, true);

    Property Sheet Class that can be embedded in a dialog

    This class shows has a property sheet can be embedded in a dialog. To create the sheet I do the following in the dialog that I want it in

    HWND hWndPlaceHolder = GetDlgItem(IDC_PROP_SHEET_HOLDER);
    ::ShowWindow(hWndPlaceHolder, FALSE);
    CRect rc;
    ::GetWindowRect(hWndPlaceHolder, &rc);		
    m_Sheet.Create(m_hWnd, 0, rc);

    Tool Tip Dialog

    This is an add-in class that will load a resource string for each child window in the dialog. The string that is loaded will be the same as the Control ID of the child window. The only call necessary is m_TipDlg.SetOwner(m_hWnd); in the dialog that you want tool tips in. Then make sure that the stringtable has items added that match the control id of the child windows
    One thing to note. Static text controls, check boxes, and radio buttons must all have the notify style set from the dialog editor.

    <p>I hope you find these classes helpful.</p>


    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


    About the Author

    Web Developer
    United States United States
    No Biography provided

    Comments and Discussions

    GeneralGreat! Pin
    Fernando A. Gomez F.18-Feb-08 15:32
    MemberFernando A. Gomez F.18-Feb-08 15:32 
    Questionhow to change the tabcolor of propertysheet dyanamically Pin
    Member 194612721-Jun-05 21:57
    MemberMember 194612721-Jun-05 21:57 
    QuestionHow can I Owner Drawn trackbar controls? Pin
    funyoung21-Dec-03 22:02
    Memberfunyoung21-Dec-03 22:02 
    Questionwhy inherit from CDialogImpl? Pin
    31-May-01 20:17
    suss31-May-01 20:17 
    GeneralMissing File from Code Pin
    hamid yaseen20-Mar-01 18:27
    Memberhamid yaseen20-Mar-01 18:27 
    GeneralRe: Missing File from Code Pin
    21-Mar-01 1:43
    suss21-Mar-01 1:43 
    GeneralRe: Missing File from Code Pin
    6-Dec-01 15:48
    suss6-Dec-01 15:48 
    GeneralRe: Missing File from Code Pin
    kamal_upreti6-Jan-03 1:09
    Memberkamal_upreti6-Jan-03 1:09 
    GeneralRe: Missing File from Code Pin
    kamal_upreti1-Jun-03 19:32
    Memberkamal_upreti1-Jun-03 19:32 
    GeneralRe: Missing File from Code Pin
    Bilal Ahmad1-Dec-03 22:34
    MemberBilal Ahmad1-Dec-03 22:34 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.