So this was something I was curious to do myself and found google was little help with all the mixed threads and Tutorials on ToolTips or C++ CToolTipCtrl class.
Most tutorials created there own class to draw a tooltip, but it can be done with our CToolTipCtrl Class with minimal code.
This is very simple to do but not there's not really any good tutorials for non MFC ToolTips.
So First off you want to create a pointer to use the Class in yourapp.h
inside your class add this line here
Most tutorials created there own class to draw a tooltip, but it can be done with our CToolTipCtrl Class with minimal code.
This is very simple to do but not there's not really any good tutorials for non MFC ToolTips.
So First off you want to create a pointer to use the Class in yourapp.h
inside your class add this line here
Code:
CToolTipCtrl *pToolTip;
your class should look like this with your class name in place of CDxtDlg ofc!
Code:
class CDxtDlg : public CDialog { // Construction public: CDxtDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data enum { IDD = IDD_DXT_DIALOG }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support CBitmap Background; CStatusBar m_bar; CToolTipCtrl *pToolTip; ///here is our new line of code to use our tooltip // Implementation protected: HICON m_hIcon; // Generated message map functions virtual BOOL OnInitDialog(); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg BOOL PreTranslateMessage(MSG* pMsg); // add this line here for the next step DECLARE_MESSAGE_MAP()
Now we can go back to our main.cpp page to use the pToolTip class
paste this function in your app somewhere
paste this function in your app somewhere
Code:
//transfer the mssg to the ToolTip - this is a must to show ToolTip with any Dialog Item
// be sure you defined this function within your class in the step above!
BOOL CDxtDlg::PreTranslateMessage(MSG* pMsg) //rename the class ( CDxtDlg ) to your class ofc.
{
if (pToolTip != NULL )
pToolTip->RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
now find your OnInitDialog() and create your ToolTips in here, after CDialog::OnInitDialog()
Code:
BOOL CDxtDlg::OnInitDialog() { CDialog::OnInitDialog(); //create our ToolTip w/ ballon style pToolTip = new CToolTipCtrl; // be sure to initialize a new class first!!! pToolTip->Create( this, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON ); //create the ToolTips with Ballon Style //add our ToolTips to DlgItems pToolTip->AddTool( GetDlgItem(IDC_EDIT1), "Username Here!" ); //Add the tool to a control, and text to display pToolTip->AddTool( GetDlgItem(IDC_EDIT2), "Password Here!" ); //Add the tool to a control, and text to display pToolTip->AddTool( GetDlgItem(IDC_COMBO1), "Select Your Game Here!" ); //Add the tool to a control, and text to display pToolTip->Activate(TRUE); //activate the ToolTips
If you did everything right you will see your ToolTips like mine

0 Kommentare:
Kommentar veröffentlichen