CToolTipCtrl in modeless dialog ???
-
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
-
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
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
-
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
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); }
-
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
Hi, thank you for your reply. Unfortunatelly it doesn't work. I think it is because the dialog resource is within a DLL.
-
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); }
Hi, thank you! This works ! Even if the dialog resource is within a DLL. Thank you very much !
-
Hi, thank you! This works ! Even if the dialog resource is within a DLL. Thank you very much !
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
-
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
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
-
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); }
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!