Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / MFC
Article

Static Control with ToolTip

Rate me:
Please Sign up or sign in to vote.
2.95/5 (10 votes)
13 Sep 2007CPOL 41.3K   2.1K   13   4
The Tool Tip shows the Text of Static Control when the Text is clipped in Static Control.
Screenshot - StaticCtrlWithToolTip.jpg

Introduction

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

Background

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
//{
//public:
//    CToolTipStatic();
//
//public:
//    //{{AFX_VIRTUAL(CToolTipStatic)
//    public:
//    virtual void PreSubclassWindow();
//    virtual BOOL PreTranslateMessage(MSG* pMsg);
//    //}}AFX_VIRTUAL
//
//public:
//    virtual ~CToolTipStatic();

//protected:
//    //{{AFX_MSG(CToolTipStatic)
//    afx_msg void OnPaint();
//    //}}AFX_MSG
//
//    DECLARE_MESSAGE_MAP()
//
//protected:
//    //Internal functions
//    BOOL _SetText();        //Used when the window is active to set the text.
//
//public:
//    //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
//
//protected:
//    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.

History

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.

License

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


Written By
Web Developer
India India
me a VC++ programmer

Comments and Discussions

 
QuestionHow to set the Text for Dynamically created CStatic object. Pin
Member 437038521-Jul-08 0:08
Member 437038521-Jul-08 0:08 
QuestionDoes not work using Create Pin
AmitCohen22229-Apr-08 22:10
AmitCohen22229-Apr-08 22:10 
QuestionBlack magic involved? Pin
sps-itsec4613-Sep-07 21:59
sps-itsec4613-Sep-07 21:59 
AnswerRe: Black magic involved? Pin
kingmax_00714-Sep-07 1:20
kingmax_00714-Sep-07 1:20 
I have attached the Demo project with this article. Please refer it.
It is working fine.

kingmax_007@yahoo.com

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.