Click here to Skip to main content
11,496,146 members (515 online)
Click here to Skip to main content

Norm Almond CLabel Class Port to ATL/WTL

, 24 Jan 2001 64.4K 1.6K 24
A fully stocked owner drawn CStatic class for WTL
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
<!-- Download Links -->
  • Download source files - 7 Kb
  • Download demo project - 28 Kb
  • <!-- Article image -->

    Sample Image - ATLLabel.jpg

    Introduction

    Now you can use Norm Almond's excellent CLabel class in your ATL/WTL projects. The Class is still called CLabeland it retains a majority of the original code. Just follow these simple instructions.

    1. Create a WTL Project
    2. Design the dialog and add the Static Controls
    3. Add the ATLLabel.h header file to your project
    4. Any static controls that need enhancing, give each control a unique ID within the dialog editor.
    5. Assign a CLabel to each static control.
    6. Subclass each member controls (CLabel) to each ID using the SubclassWindow method.
    7. In OnInitDialog uses the CLabelmethods to change the appearance of the control.
      CLabel m_ctlGradient;
      m_ctlGradient.SubclassWindow(GetDlgItem(IDC_GRADIENT));
      m_ctlGradient.SetBkColor(RGB(255,255,255),RGB(0,0,255), CLabel::Gradient);
    

    See Norm Almond's original CLabel article for more details. http://www.codeproject.com/staticctrl/clabel.asp

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    Share

    About the Author

    Rashid Thadha
    Web Developer
    United Kingdom United Kingdom
    Was made redundant in early 2003 after 10 years in computer programming, since then started my own business (selling computer books on the net)
    www.pricecutbook.co.uk


    Comments and Discussions

     
    QuestionMissing include? Pin
    ChrisRibe27-Apr-06 10:10
    memberChrisRibe27-Apr-06 10:10 
    AnswerRe: Missing include? Pin
    ChrisRibe27-Apr-06 10:41
    memberChrisRibe27-Apr-06 10:41 
    QuestionForgets boldness on SetWindowText? Pin
    peterchen7-May-05 5:14
    memberpeterchen7-May-05 5:14 
    GeneralThank You! Pin
    Agump21-Nov-04 23:09
    memberAgump21-Nov-04 23:09 
    GeneralGreat job... one small suggestion Pin
    partnerinflight21-Dec-01 8:44
    memberpartnerinflight21-Dec-01 8:44 
    Rashid:

    Great job on the port! You've saved me a LOT of time! Smile | :)

    One suggestion. This Label control will not work correctly if you create it, rather than Subclassing it in a dialog. (I happen to need to create it from scratch in a CWindow.)

    Anyway, I've modified your code somewhat to enable that functionality, here are the relevant parts:


    First of all, I think you need this in the very front of the class:

    DECLARE_WND_SUPERCLASS("WTLStatic", CStatic::GetWndClassName())


    Second, I modified your message map as follows:


    BEGIN_MSG_MAP_EX(CLabel)
    MESSAGE_HANDLER(WM_PAINT, OnPaint)
    MESSAGE_HANDLER(WM_TIMER, OnTimer)
    MESSAGE_HANDLER(WM_SYSCOLORCHANGE, OnSysColorChange)
    MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
    MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
    MSG_WM_CREATE(OnCreate)
    MSG_WM_ERASEBKGND(OnEraseBkgnd)
    END_MSG_MAP()

    This uses the WTL message crackers (note the last two messages). The corresponding functions are:


    //=======================================================================
    // Function name : OnCreate
    // Description : Called when this label is created, rather than subclassed
    // Return type : LRESULT
    // Argument : CREATESTRUCT. Not used.
    //=======================================================================
    LRESULT OnCreate(LPCREATESTRUCT)
    {
    this->Init();
    SetMsgHandled(FALSE);
    return 0;
    }

    //=======================================================================
    // Function name : OnEraseBkgnd
    // Description : Called when the system tried to erase background. Not doing anything here
    // eliminates flicker when resizing or moving
    // Return type : LRESULT
    // Argument : HDC to use. Not used.
    //=======================================================================
    LRESULT OnEraseBkgnd(HDC)
    {
    return 0; // do nothing here!
    }

    Sorry for the poor formatting, I think this message box isn't very conducive to entering code. Smile | :)

    Finally, the Init function has to be modified as follows:


    if((lstrcmpi(lpszBuffer, CStatic::GetWndClassName()) == 0) ||
    (lstrcmpi(lpszBuffer, "WTLStatic") == 0))

    notice the addition of this WTLStatic check, instead of only the static.

    Oh, and the font handling has to be changed a bit, like this:

    if(font.m_hFont != NULL)
    {
    font.GetLogFont(&m_lf);
    m_hFont = ::CreateFontIndirect(&m_lf);
    }
    else
    {
    font.CreatePointFont(100, "Tahoma");
    font.GetLogFont(&m_lf);
    m_hFont = font.m_hFont;
    }

    I used Tahoma as default here, because I was too lazy to remember how to get the default system font. Substitute whatever in there....

    Anyway, hope this helps someone who's in the same pickle as I was.

    Thanks again for the good work!
    -- Eugene


    ----------------------------------------
    ----I said my name wasn't important
    ---------------------------SlartiBartFast
    GeneralThanks Pin
    Norm Almond17-Mar-01 4:36
    memberNorm Almond17-Mar-01 4:36 
    GeneralSuggestion: Can it Port to SmartPhone ATL/WTL Pin
    fox28016-Feb-03 17:27
    memberfox28016-Feb-03 17:27 

    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
    Web01 | 2.8.150520.1 | Last Updated 25 Jan 2001
    Article Copyright 2001 by Rashid Thadha
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid