Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot Display a tooltip for a CNiNumEdit

Solved!
Go to solution

I have a two member variables:

 

CEdit m_meterIdEdit;

NI::CNiNumEdit m_bcf;

 

In my

BOOL CFlowMeter::OnInitDialog()
{
    CPropertyPage::OnInitDialog();
    TRACE("CFlowMeter OnInitDialog was Performed\n");

    // Set up the tooltip
    m_pToolTipCtrl = new CToolTipCtrl;
    if ( !m_pToolTipCtrl->Create(this) )
    {
        TRACE("Unable to create Tooltip\n");
        return TRUE;
    }

    if (!m_pToolTipCtrl->AddTool(&m_meterIdEdit,"Limited to 13 characters which cannot include the following: [\\]^_`{|}~"))
    {
        TRACE("Unable to add Meter 1 ID to the tooltip\n");
    }
    m_bcf.EnableToolTips(TRUE);
    if (!m_pToolTipCtrl->AddTool(&m_bcf,"The Field Calibration is dependent on the following:  Flow Units, Temperature, and Pressure Reference Conditions."))
    {
        TRACE("Unable to add Meter 1 BCF to the tooltip\n");
    }
    m_pToolTipCtrl->Activate(TRUE);
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

The tooltip for the CEdit variable works but the tooltip for the CNiNumEdit does not.

 

I created another method to check the muse move over the m_bcf control.

 

void CFlowMeter::MouseMoveM1BiasCfCwnumedit(short Button, short Shift, long x, long y)
{
    // TODO: Add your message handler code here
    TRACE("Mouse Over BCF (%d,%d)\n",x,y);

    CPoint point(x,y);

    TOOLINFO ti = { 0 };
    ti.cbSize = sizeof(TOOLINFO);
    ti.uFlags = TTF_SUBCLASS;
    //ti.hwnd = hwndParent;
    //ti.hwnd = this->m_hWnd;
    ti.hwnd = m_bcf.m_hWnd;
    //ti.hinst = g_hInst;
    ti.hinst = NULL;
    char Text[200];
    sprintf_s(Text, 200,"%d, %d", x, y);
    ti.lpszText = Text;
    //ti.lpszText = TEXT("This is your tooltip text."); //Text;
    //::GetClientRect(this->m_hWnd, &ti.rect );
    //ti.rect.left = 40;
    //ti.rect.top = 16;
    ::GetClientRect(m_bcf.m_hWnd, &ti.rect);

    m_bcf.OnToolHitTest(point, &ti);
}


OnToolHitTest returns 100.  the m_bcf ID is 1031.  

 

Why won't the text display like the windows built in Edit control.

 

0 Kudos
Message 1 of 11
(10,085 Views)

I have tried another method assuming the CNiNumEdit is not a child of CFrameWnd.  I have created a child of CNiNumEdit and added methods to handle the TTN_NEETTEXT notifications from the tool tip controls.

 

in the .h

 

 

class CMyNiNumEdit : public NI::CNiNumEdit
{
    DECLARE_DYNAMIC(CMyNiNumEdit)
public:
    CMyNiNumEdit();
    virtual ~CMyNiNumEdit();
    DECLARE_EVENTSINK_MAP()
    afx_msg BOOL OnToolTipText(UINT nID, NMHDR* pNMHDR, LRESULT* pResult);
    DECLARE_MESSAGE_MAP()

protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
};

 

in the .cpp

 

IMPLEMENT_DYNAMIC( CMyNiNumEdit, NI::CNiNumEdit )

BEGIN_MESSAGE_MAP(CMyNiNumEdit, NI::CNiNumEdit)
    ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
    ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
END_MESSAGE_MAP()

BEGIN_EVENTSINK_MAP(CMyNiNumEdit, NI::CNiNumEdit)
END_EVENTSINK_MAP()

CMyNiNumEdit::CMyNiNumEdit(){}

CMyNiNumEdit::~CMyNiNumEdit(){}

void CMyNiNumEdit::DoDataExchange(CDataExchange* pDX)
{
    NI::CNiNumEdit::DoDataExchange(pDX);
}

BOOL CMyNiNumEdit::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
{
     ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);

     // if there is a top level routing frame then let it handle the message
     //if (GetRoutingFrame() != NULL) return FALSE;

     // to be thorough we will need to handle UNICODE versions of the message also !!
     TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
     TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
     TCHAR szFullText[512];
     CString strTipText;
     UINT nID = pNMHDR->idFrom;

     if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
         pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
     {
          // idFrom is actually the HWND of the tool
          //nID = ::GetDlgCtrlID((HWND)nID);
         // Work-around for CNiControls returning nID = 0 with
        // ::GetDlgCtrlID((HWND)nID)
        CWnd* cwnd = this->FromHandle((HWND)nID);
        nID = cwnd->GetDlgCtrlID();
     }

     if (nID != 0) // will be zero on a separator
     {
          AfxLoadString(nID, szFullText);
          strTipText=szFullText;

#ifndef _UNICODE
          if (pNMHDR->code == TTN_NEEDTEXTA)
          {
               lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText));
          }
          else
          {
               _mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
          }
#else
          if (pNMHDR->code == TTN_NEEDTEXTA)
          {
               _wcstombsz(pTTTA->szText, strTipText,sizeof(pTTTA->szText));
          }
          else
          {
               lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
          }
#endif

          *pResult = 0;

          // bring the tooltip window above other popup windows
          ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,SWP_NOACTIVATE|
               SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
          return TRUE;
     }
     return FALSE;
}

 

 

Now a tooltip window appears, but the text is incorrect.  I am unable to correctly retreive the nID from the unit.  Even with the offered solution found in the forums.  See

 

          // idFrom is actually the HWND of the tool
          //nID = ::GetDlgCtrlID((HWND)nID);
         // Work-around for CNiControls returning nID = 0 with
        // ::GetDlgCtrlID((HWND)nID)
        CWnd* cwnd = this->FromHandle((HWND)nID);
        nID = cwnd->GetDlgCtrlID();

 

Thank you for your time,

 

Scott

 

0 Kudos
Message 2 of 11
(10,060 Views)
Hey, what version of Visual Studio and Measurement studio? There is a known bug with .NET 1.1: Tooltips Not Appearing on Measurement Studio Numeric Edit .NET Controls
Richard S -- National Instruments -- (former) Applications Engineer -- Data Acquisition with TestStand
0 Kudos
Message 3 of 11
(10,058 Views)

Richard,

 

I have VS2005 and MS 8.5.

 

I believe VS2005 uses .NET 2 not 1.1.

 

Scott

 

0 Kudos
Message 4 of 11
(10,053 Views)
That is correct, VS2005 uses .NET 2. Can you post a simple zipped project with a CNiNumEdit and some other item with a tooltip?
Richard S -- National Instruments -- (former) Applications Engineer -- Data Acquisition with TestStand
0 Kudos
Message 5 of 11
(9,981 Views)
Here is a stripped version of my program.  After building, run the program and you will see the Wizard option in the menu bar. Choose it.  A PropertySheet will be displayed with a PropertyPage that has data on it.  I can display the tooltips for VS 2005 native tools like the CEdit for Meter Identification, but cannot display them for the CNiNumEdit class unless I create a child class  with the proper handlers.  Even then I cannot display the proper tool tip.  See CMyNiNumEdit and the Field Cal Correction Factor on the PropertyPage.  See any of the other CNiNumEdit fields for tooltips not being displayed.
0 Kudos
Message 6 of 11
(9,973 Views)

Have you tried replacing

 

 CWnd* cwnd = this->FromHandle((HWND)nID);
        nID = cwnd->GetDlgCtrlID();

 

With this  code?

 

 nID = this->GetDlgCtrlID();

Richard S -- National Instruments -- (former) Applications Engineer -- Data Acquisition with TestStand
Message 7 of 11
(9,936 Views)

That worked but now I am limited to 80 characters.  How do I increase that to be dynamic or set the limit higher?

 

Thank you for your help.

 

0 Kudos
Message 8 of 11
(9,932 Views)
Also why do I have to create a child class to get this to work?  Why is this functionality not already included in the class?
0 Kudos
Message 9 of 11
(9,930 Views)
Solution
Accepted by topic author schindler

I figured out how to adjust the length and the tooltip autopop time.  Here are the changes required.  They are all located in the following method except for a new member data     TCHAR ToolTipText[512];
I have changed the color of the modified code.

 

BOOL CMyNiNumEdit::OnToolTipText(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
{
     ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);

     // if there is a top level routing frame then let it handle the message
     //if (GetRoutingFrame() != NULL) return FALSE;

     // to be thorough we will need to handle UNICODE versions of the message also !!
     TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
     TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
     //TCHAR szFullText[512];
     //CString strTipText;
     UINT nID = pNMHDR->idFrom;

     if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
         pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
     {
        // idFrom is actually the HWND of the tool
        //nID = ::GetDlgCtrlID((HWND)nID);
        // Work-around for CNiControls returning nID = 0 with
        // ::GetDlgCtrlID((HWND)nID)
        //CWnd* cwnd = this->FromHandle((HWND)nID);
        //nID = cwnd->GetDlgCtrlID();
        //Suggested by NI on the forum NI Discussion Forums : Most Active Software Boards :
        // Measurement Studio for VC++  : Cannot Display a tooltip for a CNiNumEdit
        nID = this->GetDlgCtrlID();
     }

     if (nID != 0) // will be zero on a separator
     {
          //AfxLoadString(nID, szFullText);
          AfxLoadString(nID, ToolTipText);
          //strTipText=szFullText;

#ifndef _UNICODE
          if (pNMHDR->code == TTN_NEEDTEXTA)
          {
               //lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText));
               pTTTA->lpszText = ToolTipText;
          }
          else
          {
               //_mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
               // Convert from char * to wchar_t *
               size_t convertedChars = 0;
               wchar_t wcstring[512];
               mbstowcs_s(&convertedChars, wcstring, 512, ToolTipText,_TRUNCATE);
               pTTTW->lpszText = wcstring;
          }
#else
          if (pNMHDR->code == TTN_NEEDTEXTA)
          {
               //_wcstombsz(pTTTA->szText, strTipText,sizeof(pTTTA->szText));
               pTTTA->lpszText = ToolTipText;
          }
          else
          {
               //lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
               // Convert from char * to wchar_t *
               size_t convertedChars = 0;
               wchar_t wcstring[512];
               mbstowcs_s(&convertedChars, wcstring, 512, ToolTipText,_TRUNCATE);
               pTTTW->lpszText = wcstring;
          }
#endif

          *pResult = ::SendMessage(pNMHDR->hwndFrom, (UINT)TTM_SETDELAYTIME, (WPARAM)(DWORD)TTDT_AUTOPOP, (LPARAM)MAKELONG(15000,0));

          // bring the tooltip window above other popup windows
          ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,SWP_NOACTIVATE|
               SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
          return TRUE;
     }
     return FALSE;
}

 

0 Kudos
Message 10 of 11
(9,892 Views)