Click here to Skip to main content
Licence CPOL
First Posted 12 Mar 2001
Views 77,761
Bookmarked 32 times

Owner Drawn WTL Controls

By | 30 Apr 2001 | Article
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.

    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)

    About the Author

    JacksonBrown1960

    Web Developer

    United States United States

    Member



    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    GeneralGreat! PinmemberFernando A. Gomez F.15:32 18 Feb '08  
    Questionhow to change the tabcolor of propertysheet dyanamically Pinmemberritesh sharma21:57 21 Jun '05  
    QuestionHow can I Owner Drawn trackbar controls? Pinmemberfunyoung22:02 21 Dec '03  
    Questionwhy inherit from CDialogImpl? Pinmemberwilley20:17 31 May '01  
    GeneralMissing File from Code Pinmemberhamid yaseen18:27 20 Mar '01  
    GeneralRe: Missing File from Code PinmemberDave J1:43 21 Mar '01  
    GeneralRe: Missing File from Code PinmemberBryan Ressler15:48 6 Dec '01  
    GeneralRe: Missing File from Code Pinmemberkamal_upreti1:09 6 Jan '03  
    GeneralRe: Missing File from Code Pinmemberkamal_upreti19:32 1 Jun '03  
    GeneralRe: Missing File from Code PinmemberBilal Ahmad22:34 1 Dec '03  

    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.

    Permalink | Advertise | Privacy | Mobile
    Web02 | 2.5.120528.1 | Last Updated 1 May 2001
    Article Copyright 2001 by JacksonBrown1960
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid