我有一个对话框,其中有控件,使用了DDX_TEXT和DDX_INT,交换数据,运行正常。
然后我想加一些冒泡提示,按网上的方法加入代码后,每次打开对话框,就跳出:“请输入一个整数。”
显然冒泡提示与DDX_INT有冲突,请教如何解决。
谢谢!网上冒泡提示代码: 1. 首先在CTestToolTipDlg(继承于CDialog)的.h头文件中定义ToolTip控件提示,如:CToolTipCtrl m_toolTip; 2. 在OnInitDialog()方法中添加如下代码: EnableToolTips(TRUE);
if(!m_toolTip)
{
m_toolTip.Create(this);
m_toolTip.Activate(TRUE);
m_toolTip.AddTool(GetDlgItem(IDOK),_T("这是一个按钮"));
//IDC_BUTTON1是需要进行提示的按钮的ID值,这个函数的原型是
//BOOL AddTool( CWnd* pWnd, LPCTSTR lpszText = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT_PTR nIDTool = 0 );
m_toolTip.SetTipTextColor(RGB(0,0,255)); //提示文字颜色,非必需
m_toolTip.SetDelayTime(150); //出现提示前的延迟时间,非必需
} 3. 为CTestToolTipDlg添加PreTranslateMessage消息,并且添加代码如下: BOOL CTestToolTipDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
m_toolTip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
} 如果你需要鼠标左键从该按钮上按下、移动、弹起时都显示,可做如下修改: BOOL CTestToolTipDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if((pMsg->message== WM_LBUTTONDOWN ||
pMsg->message== WM_LBUTTONUP ||
pMsg->message== WM_MOUSEMOVE)
&& pMsg->hwnd == GetDlgItem(IDOK)->GetSafeHwnd())
{
MSG tempMsg;
tempMsg=*pMsg;
tempMsg.message=WM_MOUSEMOVE;
m_toolTip.RelayEvent(&tempMsg);
}
return CDialog::PreTranslateMessage(pMsg);
}
然后我想加一些冒泡提示,按网上的方法加入代码后,每次打开对话框,就跳出:“请输入一个整数。”
显然冒泡提示与DDX_INT有冲突,请教如何解决。
谢谢!网上冒泡提示代码: 1. 首先在CTestToolTipDlg(继承于CDialog)的.h头文件中定义ToolTip控件提示,如:CToolTipCtrl m_toolTip; 2. 在OnInitDialog()方法中添加如下代码: EnableToolTips(TRUE);
if(!m_toolTip)
{
m_toolTip.Create(this);
m_toolTip.Activate(TRUE);
m_toolTip.AddTool(GetDlgItem(IDOK),_T("这是一个按钮"));
//IDC_BUTTON1是需要进行提示的按钮的ID值,这个函数的原型是
//BOOL AddTool( CWnd* pWnd, LPCTSTR lpszText = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT_PTR nIDTool = 0 );
m_toolTip.SetTipTextColor(RGB(0,0,255)); //提示文字颜色,非必需
m_toolTip.SetDelayTime(150); //出现提示前的延迟时间,非必需
} 3. 为CTestToolTipDlg添加PreTranslateMessage消息,并且添加代码如下: BOOL CTestToolTipDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
m_toolTip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
} 如果你需要鼠标左键从该按钮上按下、移动、弹起时都显示,可做如下修改: BOOL CTestToolTipDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if((pMsg->message== WM_LBUTTONDOWN ||
pMsg->message== WM_LBUTTONUP ||
pMsg->message== WM_MOUSEMOVE)
&& pMsg->hwnd == GetDlgItem(IDOK)->GetSafeHwnd())
{
MSG tempMsg;
tempMsg=*pMsg;
tempMsg.message=WM_MOUSEMOVE;
m_toolTip.RelayEvent(&tempMsg);
}
return CDialog::PreTranslateMessage(pMsg);
}
就够了。然后响应://
BOOL CxxxxDlg::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
{
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
UINT nID =pNMHDR->idFrom;
// char txt[40];
// idFrom is actually the HWND of the control=IDC_xxx
if (pTTT->hdr.code==TTN_NEEDTEXT)
{
if (pTTT->uFlags & TTF_IDISHWND)
{
if(((CStatic*)GetDlgItem(IDC_TT))->m_hWnd==(HWND)nID)
{
pTTT->lpszText="Double click to edit the text!";
}
return TRUE;
}
}
//
return(FALSE);
}OnToolTipNotify()
OnInitDialog(){ CDialog::OnInitDialog();
EnableToolTips(TRUE);
if(!m_toolTip)
{
m_toolTip.Create(this);
m_toolTip.Activate(TRUE);
m_toolTip.AddTool(GetDlgItem(IDOK),_T("这是一个按钮"));
} return 0 //必须返回0 }