Click here to Skip to main content
13,202,873 members (57,590 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 13 Sep 2007

Static Control with ToolTip

, 13 Sep 2007
Rate this:
Please Sign up or sign in to vote.
The Tool Tip shows the Text of Static Control when the Text is clipped in Static Control.
Screenshot - StaticCtrlWithToolTip.jpg


Show the text of the static control on Tool Tip when the text cannot fit in the static control window.


This code can be used to display the static windows whose text data can be set during run time.

Using the code

Make a CToolTipStatic class object and the tool tip will be displayed automatically.

Class used:

<pre lang="C++">//class CToolTipStatic : public CStatic
//    CToolTipStatic();
//    //{{AFX_VIRTUAL(CToolTipStatic)
//    public:
//    virtual void PreSubclassWindow();
//    virtual BOOL PreTranslateMessage(MSG* pMsg);
//    //}}AFX_VIRTUAL
//    virtual ~CToolTipStatic();

//    //{{AFX_MSG(CToolTipStatic)
//    afx_msg void OnPaint();
//    //}}AFX_MSG
//    //Internal functions
//    BOOL _SetText();        //Used when the window is active to set the text.
//    //Functions
//    BOOL SetText(LPCTSTR pszText);                         // Set the Text
//    BOOL GetText(CString& strText);                        // Get the Text
//    BOOL SetFGColor(BYTE btRed, BYTE btGreen, BYTE btBlue);            //Set Text's Foreground color
//    BOOL GetFGColor(BYTE& btRed, BYTE& btGreen, BYTE& btBlue);         //Get Text's Foreground color
//    BOOL SetBGColor(BYTE btRed, BYTE btGreen, BYTE btBlue);            //Set Text's Background color
//    BOOL GetBGColor(BYTE& btRed, BYTE& btGreen, BYTE& btBlue);         //Get Text's Background color
//    //--- ToolTip Functions ---//
//    BOOL SetToolTipFGColor(BYTE btRed, BYTE btGreen, BYTE btBlue);        //Set ToolTip's Foreground color
//    BOOL GetToolTipFGColor(BYTE& btRed, BYTE& btGreen, BYTE& btBlue);     //Get ToolTip's Foreground color
//    BOOL SetToolTipBGColor(BYTE btRed, BYTE btGreen, BYTE btBlue);        //Set ToolTip's Background color
//    BOOL GetToolTipBGColor(BYTE& btRed, BYTE& btGreen, BYTE& btBlue);     //Get ToolTip's Background color
//    CString        m_strText;        // Dialogtext
//    COLORREF    m_clrFont;        // Text's Foreground color
//    COLORREF    m_clrBckGnd;        // Text's Background color
//    CToolTipCtrl    m_ToolTip;        // ToolTip object
//    COLORREF    m_clrTTFont;        // ToolTip's Foreground color
//    COLORREF    m_clrTTBckGnd;        // ToolTip's Background color
//    BOOL        m_bToolTipCreated;    // Indicates Tool Tip is created.
//    CFont        m_font;            // Static control's font
//    BOOL        m_bFontInit;        // Indicates m_font is created

Points of Interest

This is my first contribution to all VC++ programmers. In case of any improvement or suggestion please feel free and reply.


I kingmax_007 (Sandesh Rane) am programming in VC++ since 2004. In case of any bugs please report. I will solve it as soon as possible.


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


About the Author

Web Developer
India India
me a VC++ programmer

You may also be interested in...


Comments and Discussions

QuestionHow to set the Text for Dynamically created CStatic object. Pin
Member 437038521-Jul-08 0:08
memberMember 437038521-Jul-08 0:08 
QuestionDoes not work using Create Pin
AmitCohen22229-Apr-08 22:10
memberAmitCohen22229-Apr-08 22:10 
When I try to create dynamically using Create function I get an error...
What is wrong ?
Confused | :confused:
QuestionBlack magic involved? Pin
mykel13-Sep-07 21:59
membermykel13-Sep-07 21:59 
AnswerRe: Black magic involved? Pin
kingmax_00714-Sep-07 1:20
memberkingmax_00714-Sep-07 1:20 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171020.1 | Last Updated 13 Sep 2007
Article Copyright 2007 by kingmax_007
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid