Click here to Skip to main content
11,414,670 members (67,520 online)
Click here to Skip to main content

Owner Drawn WTL Controls

, 30 Apr 2001 CPOL
Rate this:
Please Sign up or sign in to vote.
The code in this demo package contains a colored label, a colored button with menu support, and a colored tab control for WTL.
<!-- Download Links -->
  • Download source files - 28 Kb
  • Download demo project - 136 Kb
  • <!-- Article image -->

    Sample Image - OwnerDrawn.gif

    <!-- Main HTML starts here -->

    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.

    I hope you find these classes helpful.

    License

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

    Share

    About the Author

    JacksonBrown1960
    Web Developer
    United States United States
    No Biography provided

    Comments and Discussions

     
    GeneralGreat! Pin
    Fernando A. Gomez F.18-Feb-08 16:32
    memberFernando A. Gomez F.18-Feb-08 16:32 
    Questionhow to change the tabcolor of propertysheet dyanamically Pin
    ritesh sharma21-Jun-05 22:57
    memberritesh sharma21-Jun-05 22:57 
    QuestionHow can I Owner Drawn trackbar controls? Pin
    funyoung21-Dec-03 23:02
    memberfunyoung21-Dec-03 23:02 
    Questionwhy inherit from CDialogImpl? Pin
    willey31-May-01 21:17
    memberwilley31-May-01 21:17 
    GeneralMissing File from Code Pin
    hamid yaseen20-Mar-01 19:27
    memberhamid yaseen20-Mar-01 19:27 
    GeneralRe: Missing File from Code Pin
    Dave J21-Mar-01 2:43
    memberDave J21-Mar-01 2:43 
    GeneralRe: Missing File from Code Pin
    Bryan Ressler6-Dec-01 16:48
    memberBryan Ressler6-Dec-01 16:48 
    GeneralRe: Missing File from Code Pin
    kamal_upreti6-Jan-03 2:09
    memberkamal_upreti6-Jan-03 2:09 
    GeneralRe: Missing File from Code Pin
    kamal_upreti1-Jun-03 20:32
    memberkamal_upreti1-Jun-03 20:32 
    GeneralRe: Missing File from Code Pin
    Bilal Ahmad1-Dec-03 23:34
    memberBilal Ahmad1-Dec-03 23:34 

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

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

    | Advertise | Privacy | Terms of Use | Mobile
    Web04 | 2.8.150427.4 | Last Updated 1 May 2001
    Article Copyright 2001 by JacksonBrown1960
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid