Click here to Skip to main content
15,868,141 members
Articles / Desktop Programming / WTL
Article

Owner Drawn WTL Controls

Rate me:
Please Sign up or sign in to vote.
4.56/5 (7 votes)
30 Apr 2001CPOL 103.4K   3.4K   43   10
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

    Introduction

    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.SubclassWindow(GetDlgItem(IDC_BUTTON1));
    Btn.SetColors(crText, crBack);
    Btn.SetBorderColors(crDark, crDkShadow, crLight);
    Btn.SetMenuID(IDR_BTN_MENU);

    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.SubclassWindow(GetDlgItem(IDC_TEXT_1));
    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.SubclassWindow(GetDlgItem(IDC_TAB1));
    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);		
    		
    ScreenToClient(&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.

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

    License

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


    Written By
    Web Developer
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    GeneralGreat! Pin
    Fernando A. Gomez F.18-Feb-08 15:32
    Fernando A. Gomez F.18-Feb-08 15:32 
    Questionhow to change the tabcolor of propertysheet dyanamically Pin
    Member 194612721-Jun-05 21:57
    Member 194612721-Jun-05 21:57 
    QuestionHow can I Owner Drawn trackbar controls? Pin
    funyoung21-Dec-03 22:02
    funyoung21-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
    hamid 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
    kamal_upreti6-Jan-03 1:09 
    GeneralRe: Missing File from Code Pin
    kamal_upreti1-Jun-03 19:32
    kamal_upreti1-Jun-03 19:32 
    GeneralRe: Missing File from Code Pin
    Bilal Ahmad1-Dec-03 22:34
    Bilal Ahmad1-Dec-03 22:34 
    Here is a rich source for Wtl

    http://www.gnomedia.com/cw/wtl/wtldocs/files.html



    Regards
    Bilal

    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.