02-20-2009 05:07 PM
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.
Solved! Go to Solution.
02-23-2009 10:18 AM
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
02-23-2009 10:50 AM
02-23-2009 11:18 AM
Richard,
I have VS2005 and MS 8.5.
I believe VS2005 uses .NET 2 not 1.1.
Scott
03-02-2009 03:07 PM
03-03-2009 10:38 AM
03-05-2009 02:48 PM
Have you tried replacing
CWnd* cwnd = this->FromHandle((HWND)nID);
nID = cwnd->GetDlgCtrlID();
With this code?
nID = this->GetDlgCtrlID();
03-05-2009 03:03 PM
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.
03-05-2009 03:04 PM
03-06-2009 11:49 AM
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;
}