Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CToolTipCtrl in modeless dialog ???

CToolTipCtrl in modeless dialog ???

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    madmax0001
    wrote on last edited by
    #1

    Hi, I have a problem while using a CToolTipCtrl in a modeless dialog. I have created the tooltip the standard way: BOOL CMyDlg::OnInitDialog() { m_pTip = new CToolTipCtrl(); m_pTip->Create(this, TTS_ALWAYSTIP); m_pTip->SetMaxTipWidth(250); m_pTip->AddTool(GetDlgItem(IDC_SOMETHING), "Something"); m_pTip->Activate(TRUE); } BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if(m_pTip != NULL) m_pTip->RelayEvent(&msg); } If I create the dialog modeless the tooltip isn't shown. If I create the dialog modal it works fine! Can someone help me please? mADmAX0001

    D H M 3 Replies Last reply
    0
    • M madmax0001

      Hi, I have a problem while using a CToolTipCtrl in a modeless dialog. I have created the tooltip the standard way: BOOL CMyDlg::OnInitDialog() { m_pTip = new CToolTipCtrl(); m_pTip->Create(this, TTS_ALWAYSTIP); m_pTip->SetMaxTipWidth(250); m_pTip->AddTool(GetDlgItem(IDC_SOMETHING), "Something"); m_pTip->Activate(TRUE); } BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if(m_pTip != NULL) m_pTip->RelayEvent(&msg); } If I create the dialog modeless the tooltip isn't shown. If I create the dialog modal it works fine! Can someone help me please? mADmAX0001

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      madmax0001 wrote:

      Can someone help me please?

      Does this help?


      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

      "There is no death, only a change of worlds." - Native American Proverb

      M 1 Reply Last reply
      0
      • M madmax0001

        Hi, I have a problem while using a CToolTipCtrl in a modeless dialog. I have created the tooltip the standard way: BOOL CMyDlg::OnInitDialog() { m_pTip = new CToolTipCtrl(); m_pTip->Create(this, TTS_ALWAYSTIP); m_pTip->SetMaxTipWidth(250); m_pTip->AddTool(GetDlgItem(IDC_SOMETHING), "Something"); m_pTip->Activate(TRUE); } BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if(m_pTip != NULL) m_pTip->RelayEvent(&msg); } If I create the dialog modeless the tooltip isn't shown. If I create the dialog modal it works fine! Can someone help me please? mADmAX0001

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Hi madmax0001, maybe it is some helpful to you ////h File///////////////// void SetToolTip(LPCTSTR lpszText); CToolTipCtrl m_tooltip; ////h File///////////////// BOOL CAnswerView::OnInitDialog() { m_tooltip.Create(this); SetToolTip("Hello"); } void CAnswerView::SetToolTip(LPCTSTR lpszText) { TOOLINFO ti; ti.cbSize = sizeof(TOOLINFO); ti.lpszText = (LPTSTR)lpszText; ti.hinst = AfxGetInstanceHandle(); ti.hwnd = m_Button.m_hWnd;//GetDlgItem(IDC_BUTTON1)->m_hWnd; ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; ti.uId = (UINT) m_Button.m_hWnd;//GetDlgItem(IDC_BUTTON1)->m_hWnd; m_tooltip.SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ti); }

        M A 2 Replies Last reply
        0
        • D David Crow

          madmax0001 wrote:

          Can someone help me please?

          Does this help?


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "There is no death, only a change of worlds." - Native American Proverb

          M Offline
          M Offline
          madmax0001
          wrote on last edited by
          #4

          Hi, thank you for your reply. Unfortunatelly it doesn't work. I think it is because the dialog resource is within a DLL.

          1 Reply Last reply
          0
          • H Hamid Taebi

            Hi madmax0001, maybe it is some helpful to you ////h File///////////////// void SetToolTip(LPCTSTR lpszText); CToolTipCtrl m_tooltip; ////h File///////////////// BOOL CAnswerView::OnInitDialog() { m_tooltip.Create(this); SetToolTip("Hello"); } void CAnswerView::SetToolTip(LPCTSTR lpszText) { TOOLINFO ti; ti.cbSize = sizeof(TOOLINFO); ti.lpszText = (LPTSTR)lpszText; ti.hinst = AfxGetInstanceHandle(); ti.hwnd = m_Button.m_hWnd;//GetDlgItem(IDC_BUTTON1)->m_hWnd; ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; ti.uId = (UINT) m_Button.m_hWnd;//GetDlgItem(IDC_BUTTON1)->m_hWnd; m_tooltip.SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ti); }

            M Offline
            M Offline
            madmax0001
            wrote on last edited by
            #5

            Hi, thank you! This works ! Even if the dialog resource is within a DLL. Thank you very much !

            M 1 Reply Last reply
            0
            • M madmax0001

              Hi, thank you! This works ! Even if the dialog resource is within a DLL. Thank you very much !

              M Offline
              M Offline
              madmax0001
              wrote on last edited by
              #6

              Hi, me again... I have done several tests in the meantime and unfortunatelly there is still a small problem with the tooltip. To setup the tooltips for the modeless dialog in my dll I use this function: ////////////////////////////////////////// void CMyDialog::SetToolTip(CWnd* pWnd, LPCTSTR lpszText) { if((pWnd != NULL) && (m_pTip != NULL)){ TOOLINFO ti; ti.cbSize = sizeof(TOOLINFO); ti.lpszText = (LPTSTR)lpszText; ti.hinst = AfxGetInstanceHandle(); ti.hwnd = pWnd->m_hWnd; ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; ti.uId = (UINT)pWnd->m_hWnd; m_pTip->SendMessage(TTM_ADDTOOL, 0, (LPARAM)&ti); } } ////////////////////////////////////////// This works without (!) any call to CMyDialog::PreTranslateMessage(MSG* pMsg). But I need this call, because there is an MFC bug with tooltips for disabled controls and I used in my modal dialogs this code: ////////////////////////////////////////// BOOL CMyDialog::PreTranslateMessage(MSG* pMsg) { TRACE("PreTranslateMessage\n"); if(m_pTip != NULL){ // The following code is a workaround for a MFC tooltip bug which // prevents the popup of a tooltip for a disabled control in a modal dialog. // Transate the message based on TTM_WINDOWFROMPOINT MSG msg = *pMsg; msg.hwnd = (HWND)m_pTip->SendMessage(TTM_WINDOWFROMPOINT, 0, (LPARAM)&msg.pt); CPoint pt = pMsg->pt; if((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST)) ::ScreenToClient(msg.hwnd, &pt); msg.lParam = MAKELONG(pt.x, pt.y); // Let the ToolTip process this message. m_pTip->RelayEvent(&msg); } // if return CDialog::PreTranslateMessage(pMsg); } ////////////////////////////////////////// Then I tried to use the message hook which was neccessary to use accellerators in CMyDialog: ////////////////////////////////////////// // Hook procedure for WH_GETMESSAGE hook type. LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam) // If this is a keystrokes message, translate it in controls' // PreTranslateMessage(). LPMSG lpMsg = (LPMSG)lParam; if((nCode >= 0) && (PM_REMOVE == wParam) && (lpMsg->message >= WM_KEYFIRST && lpMsg->message <= WM_KEYLAST) && (AfxGetApp()->PreTranslateMessage((LPMSG)lParam)) == TRUE){ // The value returned from this hookproc is ignored, and it cannot // be used to tell Windows the message has been handled. To avoid // further processing, convert the message to WM_NULL before // returning. lpMsg->message = WM_NULL; lpMsg->lPar

              1 Reply Last reply
              0
              • M madmax0001

                Hi, I have a problem while using a CToolTipCtrl in a modeless dialog. I have created the tooltip the standard way: BOOL CMyDlg::OnInitDialog() { m_pTip = new CToolTipCtrl(); m_pTip->Create(this, TTS_ALWAYSTIP); m_pTip->SetMaxTipWidth(250); m_pTip->AddTool(GetDlgItem(IDC_SOMETHING), "Something"); m_pTip->Activate(TRUE); } BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) { if(m_pTip != NULL) m_pTip->RelayEvent(&msg); } If I create the dialog modeless the tooltip isn't shown. If I create the dialog modal it works fine! Can someone help me please? mADmAX0001

                M Offline
                M Offline
                madmax0001
                wrote on last edited by
                #7

                Hi, me again... I have done several tests in the meantime and unfortunatelly there is still a small problem with the tooltip. To setup the tooltips for the modeless dialog in my dll I use this function: ////////////////////////////////////////// void CMyDialog::SetToolTip(CWnd* pWnd, LPCTSTR lpszText) { if((pWnd != NULL) && (m_pTip != NULL)){ TOOLINFO ti; ti.cbSize = sizeof(TOOLINFO); ti.lpszText = (LPTSTR)lpszText; ti.hinst = AfxGetInstanceHandle(); ti.hwnd = pWnd->m_hWnd; ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; ti.uId = (UINT)pWnd->m_hWnd; m_pTip->SendMessage(TTM_ADDTOOL, 0, (LPARAM)&ti); } } ////////////////////////////////////////// This works without (!) any call to CMyDialog::PreTranslateMessage(MSG* pMsg). But I need this call, because there is an MFC bug with tooltips for disabled controls and I used in my modal dialogs this code: ////////////////////////////////////////// BOOL CMyDialog::PreTranslateMessage(MSG* pMsg) { TRACE("PreTranslateMessage\n"); if(m_pTip != NULL){ // The following code is a workaround for a MFC tooltip bug which // prevents the popup of a tooltip for a disabled control in a modal dialog. // Transate the message based on TTM_WINDOWFROMPOINT MSG msg = *pMsg; msg.hwnd = (HWND)m_pTip->SendMessage(TTM_WINDOWFROMPOINT, 0, (LPARAM)&msg.pt); CPoint pt = pMsg->pt; if((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST)) ::ScreenToClient(msg.hwnd, &pt); msg.lParam = MAKELONG(pt.x, pt.y); // Let the ToolTip process this message. m_pTip->RelayEvent(&msg); } // if return CDialog::PreTranslateMessage(pMsg); } ////////////////////////////////////////// Then I tried to use the message hook which was neccessary to use accellerators in CMyDialog: ////////////////////////////////////////// // Hook procedure for WH_GETMESSAGE hook type. LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam) // If this is a keystrokes message, translate it in controls' // PreTranslateMessage(). LPMSG lpMsg = (LPMSG)lParam; if((nCode >= 0) && (PM_REMOVE == wParam) && (lpMsg->message >= WM_KEYFIRST && lpMsg->message <= WM_KEYLAST) && (AfxGetApp()->PreTranslateMessage((LPMSG)lParam)) == TRUE){ // The value returned from this hookproc is ignored, and it cannot // be used to tell Windows the message has been handled. To avoid // further processing, convert the message to WM_NULL before // returning. lpMsg->message = WM_NULL; lpMsg->lPar

                1 Reply Last reply
                0
                • H Hamid Taebi

                  Hi madmax0001, maybe it is some helpful to you ////h File///////////////// void SetToolTip(LPCTSTR lpszText); CToolTipCtrl m_tooltip; ////h File///////////////// BOOL CAnswerView::OnInitDialog() { m_tooltip.Create(this); SetToolTip("Hello"); } void CAnswerView::SetToolTip(LPCTSTR lpszText) { TOOLINFO ti; ti.cbSize = sizeof(TOOLINFO); ti.lpszText = (LPTSTR)lpszText; ti.hinst = AfxGetInstanceHandle(); ti.hwnd = m_Button.m_hWnd;//GetDlgItem(IDC_BUTTON1)->m_hWnd; ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND; ti.uId = (UINT) m_Button.m_hWnd;//GetDlgItem(IDC_BUTTON1)->m_hWnd; m_tooltip.SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ti); }

                  A Offline
                  A Offline
                  Albertino
                  wrote on last edited by
                  #8

                  I had the same issue. And now, thanks to your suggestion it works. I switched from:

                  				m\_toolTip.AddTool(this,ttwtext.c\_str(),cr,1);
                  

                  To

                  				TOOLINFO ti;
                  
                  				ti.cbSize = sizeof(TOOLINFO);
                  				ti.lpszText = (LPTSTR)last\_ttwtext.c\_str();
                  				ti.hinst = AfxGetInstanceHandle();
                  				ti.hwnd = this->GetSafeHwnd();
                  				ti.uFlags = TTF\_SUBCLASS | TTF\_IDISHWND;
                  				ti.uId = (UINT) this->GetSafeHwnd();
                  
                  				m\_toolTip.SendMessage(TTM\_ADDTOOL, 0, (LPARAM) &ti);
                  

                  Thanks!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups