Static Control with ToolTip






2.95/5 (10 votes)
The Tool Tip shows the Text of Static Control when the Text is clipped in Static Control.

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:
"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.