Click here to Skip to main content
Click here to Skip to main content
Go to top

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

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)

Share

About the Author

kingmax_007
Web Developer
India India
me a VC++ programmer

Comments and Discussions

 
QuestionHow to set the Text for Dynamically created CStatic object. PinmemberMember 437038521-Jul-08 0:08 
QuestionDoes not work using Create PinmemberAmitCohen22229-Apr-08 22:10 
QuestionBlack magic involved? Pinmembermykel13-Sep-07 21:59 
AnswerRe: Black magic involved? Pinmemberkingmax_00714-Sep-07 1:20 

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 | Mobile
Web01 | 2.8.140905.1 | Last Updated 13 Sep 2007
Article Copyright 2007 by kingmax_007
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid