在对话框中的CToolTipCtrl为什么显示不出来 简单,在resourceView里右击你的那个IDC_STATIC_TEST,然后点属性-->点styles-->勾上Notify的检查框,重编译OK.原因分析:没有SS_NOTIFY的风格的static控制是不会把鼠标信息Notify到它的父窗口的,所以你的RelayEvent压根不会被调用... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HOWTO: How to Add Tooltips for Controls to an MFC Modal Dialog Box ID: Q141758 --------------------------------------------------------------------------------The information in this article applies to:The Microsoft Foundation Classes (MFC), used with:Microsoft Visual C++, 32-bit Editions, versions 2.1, 2.2, 4.0--------------------------------------------------------------------------------SUMMARYTo make the CToolTipCtrl class work correctly, you must call the CToolTipCtrl::RelayEvent() function. This makes it possible for the mouse messages to be passed to the tooltip control. For a non-modal dialog box window in an MFC application, use the window's CWnd::PreTranslateMessage() function to call CToolTipsCtrl::RelayEvent(). However, for a modal dialog box in MFC versions prior to 4.0, the CDialog::PreTranslateMessage() function is not called because modal dialog boxes have their own message loops. In versions of MFC 4.0 and later, this is not a problem because of changes to the implementation of DoModal. Therefore, to use CToolTipCtrl in a modal dialog box, you need a different approach for versions prior to 4.0. This article gives you step-by-step example that shows how to use the CToolTipCtrl class in a MFC modal dialog box for 4.0 and prior versions. MORE INFORMATIONStep-by-Step ExamplesThe following procedures generate a default MFC skeleton application and add tooltips to the OK button on the About dialog box and the dialog box itself. For Versions of MFC 4.0 or Later Use These Steps: Use the Appwizard in Visual C++ to generate an MFC application. Call it Tooltips, and use all the Appwizard default settings. Use ClassWizard to add a PreTranslateMessage override to CAboutDialog as follows: CAboutDialog::PreTranslateMessage(MSG* pMsg) { if (NULL != m_pToolTip) m_pToolTip->RelayEvent(pMsg); return CDialog::PreTranslateMessage(pMsg); } Use ClassWizard to add a member variable for the OK button in the CAboutDlg class, and call it m_btOK. Also, add a m_pToolTip pointer to a CToolTipCtrl object: class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; CButton m_btOK; //}}AFX_DATA CToolTipCtrl* m_pToolTip; //... }; Add code to the CAboutDlg class constructor and destructor to initialize and release the tooltip object. You might also need to add a default destructor first: CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { m_pToolTip = NULL; } CAboutDlg::~CAboutDlg() { delete m_pToolTip; } Override the OnInitDialog() function of the CAboutDlg class to set up the tooltip control. BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); //Set up the tooltip m_pToolTip = new CToolTipCtrl; if(!m_pToolTip->Create(this)) { TRACE("Unable To create ToolTip\n"); return TRUE; } if(m_pToolTip->AddTool(this, "About Box")) { TRACE("Unable to add Dialog to the tooltip\n"); } if (m_pToolTip->AddTool(&m_btOK,"OK Button")) { TRACE("Unable to add OK button to the tooltip\n"); } m_pToolTip->Activate(TRUE); return TRUE; } Rebuild the application, and bring up the About dialog box, you will see the tooltips. For Versions of MFC Prior to 4.0 Use These Steps: Use the Appwizard in Visual C++ to generate an MFC application. Call it Tooltips, and use all the Appwizard default settings. Include the <Afxcmn.h> header file in the Stdafx.h file. Add the following member variables to the CTooktipsApp class in the Tooltips.h file: class CTooltipsApp : public CWinApp { //... public: HWND m_hwndDialog; CToolTipCtrl* m_gpToolTip; //... }; Initialize the two variables in the application's constructor to NULL: CTooltipsApp::CTooltipsApp() { m_hwndDialog = NULL; m_gpToolTip = NULL; } Override the CTooltipsApp::ProcessMessageFilter() function as follows: BOOL CTooltipsApp::ProcessMessageFilter(int code, LPMSG lpMsg) { if (m_hwndDialog != NULL) if (lpMsg->hwnd == m_hwndDialog || ::IsChild(m_hwndDialog, lpMsg->hwnd)) { if (NULL != m_gpToolTip) m_gpToolTip->RelayEvent(lpMsg); } return CWinApp::ProcessMessageFilter(code, lpMsg); } Use ClassWizard to add a member variable for the OK button in the CAboutDlg class, and call it m_btOK. Also, add a m_pToolTip pointer to a CToolTipCtrl object: class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; CButton m_btOK; //}}AFX_DATA CToolTipCtrl* m_pToolTip; //... }; Add code to the CAboutDlg class constructor and destructor to initialize and release the tooltip object. You might also need to add a default destructor first: CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { m_pToolTip = NULL; } CAboutDlg::~CAboutDlg() { delete m_pToolTip; } Override the OnInitDialog() function of the CAboutDlg class to pass the dialog's handle to the application: BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); ((CTooltipsApp*)AfxGetApp())->m_hwndDialog=m_hWnd; if (!m_pToolTip) { m_pToolTip = new CToolTipCtrl; if(!m_pToolTip->Create(this)) { TRACE("Unable To create ToolTip\n"); return TRUE; } ((CTooltipsApp*)AfxGetApp())->m_gpToolTip = m_pToolTip; if(m_pToolTip->AddTool(this, "About Box")) { TRACE("Unable to add Dialog to the tooltip\n"); } if (m_pToolTip->AddTool(&m_btOK,"OK Button")) { TRACE("Unable to add OK button to the tooltip\n"); } m_pToolTip->Activate(TRUE); } return TRUE;//return TRUE unless you set the focus to a control //EXCEPTION: OCX Property Pages should return FALSE } Override the PostNcDestroy() function of the CAboutDlg class to reset the variables in the application class: void CAboutDlg::PostNcDestroy( ) { CDialog::PostNcDestroy(); ((CToolTipsApp*)AfxGetApp())->m_hwndDialog= NULL; ((CToolTipsApp*)AfxGetApp())->m_gpToolTip= NULL; } Rebuild the application, and bring up the About dialog box, you will see the tooltips.Additional query words: 2.10 2.20 3.10 3.20 4.00 Keywords : kbcode kbMFC kbToolTip KbUIDesign kbVC210 kbVC220 kbVC400 kbGrpMFCATL kbDialog Version : winnt:2.1,2.2,4.0 Platform : winnt Issue type : kbhowto Technology : kbvc Last Reviewed: March 13, 2000© 2000 Microsoft Corporation. All rights reserved. Terms of Use. --------------------------------------------------------------------------------Send feedback to MSDN.Look here for MSDN Online resources. VC动态链接库 支持多语言切换 [散分]原因不详 代码太长,怎么能方便确认"{"和"}"的对应关系 关于局域网上文件的读取和拷贝 给控件加背景色 毕业设计 急!急!急! 能否实现把当前屏幕上所显示的字符和图片内容从显存中提取出并另存? 求关于视频实时传输的源码(类似QQ视频,但不传送声音) VC+ADO+ACCESS,连接数据库失败,更新数据库失败? 通过消息机制或DDE控制foxpro的程序,摆得平5000分或者现金200大元! 请问如何在一个对话框中建立一个Splitter window? 请教c的高手,很急的问题 变速齿轮原理
ID: Q141758
--------------------------------------------------------------------------------
The information in this article applies to:The Microsoft Foundation Classes (MFC), used with:
Microsoft Visual C++, 32-bit Editions, versions 2.1, 2.2, 4.0--------------------------------------------------------------------------------
SUMMARY
To make the CToolTipCtrl class work correctly, you must call the CToolTipCtrl::RelayEvent() function. This makes it possible for the mouse messages to be passed to the tooltip control. For a non-modal dialog box window in an MFC application, use the window's CWnd::PreTranslateMessage() function to call CToolTipsCtrl::RelayEvent(). However, for a modal dialog box in MFC versions prior to 4.0, the CDialog::PreTranslateMessage() function is not called because modal dialog boxes have their own message loops. In versions of MFC 4.0 and later, this is not a problem because of changes to the implementation of DoModal. Therefore, to use CToolTipCtrl in a modal dialog box, you need a different approach for versions prior to 4.0. This article gives you step-by-step example that shows how to use the CToolTipCtrl class in a MFC modal dialog box for 4.0 and prior versions. MORE INFORMATIONStep-by-Step Examples
The following procedures generate a default MFC skeleton application and add tooltips to the OK button on the About dialog box and the dialog box itself. For Versions of MFC 4.0 or Later Use These Steps:
Use the Appwizard in Visual C++ to generate an MFC application. Call it Tooltips, and use all the Appwizard default settings.
Use ClassWizard to add a PreTranslateMessage override to CAboutDialog as follows: CAboutDialog::PreTranslateMessage(MSG* pMsg)
{
if (NULL != m_pToolTip)
m_pToolTip->RelayEvent(pMsg); return CDialog::PreTranslateMessage(pMsg);
} Use ClassWizard to add a member variable for the OK button in the CAboutDlg class, and call it m_btOK. Also, add a m_pToolTip pointer to a CToolTipCtrl object: class CAboutDlg : public CDialog
{
public:
CAboutDlg(); // Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CButton m_btOK;
//}}AFX_DATA CToolTipCtrl* m_pToolTip; //...
}; Add code to the CAboutDlg class constructor and destructor to initialize and release the tooltip object. You might also need to add a default destructor first: CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
m_pToolTip = NULL;
} CAboutDlg::~CAboutDlg()
{
delete m_pToolTip;
} Override the OnInitDialog() function of the CAboutDlg class to set up the tooltip control. BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog(); //Set up the tooltip
m_pToolTip = new CToolTipCtrl;
if(!m_pToolTip->Create(this))
{
TRACE("Unable To create ToolTip\n");
return TRUE;
} if(m_pToolTip->AddTool(this, "About Box"))
{
TRACE("Unable to add Dialog to the tooltip\n");
} if (m_pToolTip->AddTool(&m_btOK,"OK Button"))
{
TRACE("Unable to add OK button to the tooltip\n");
} m_pToolTip->Activate(TRUE); return TRUE;
} Rebuild the application, and bring up the About dialog box, you will see the tooltips.
For Versions of MFC Prior to 4.0 Use These Steps:
Use the Appwizard in Visual C++ to generate an MFC application. Call it Tooltips, and use all the Appwizard default settings.
Include the <Afxcmn.h> header file in the Stdafx.h file.
Add the following member variables to the CTooktipsApp class in the Tooltips.h file: class CTooltipsApp : public CWinApp
{
//...
public:
HWND m_hwndDialog;
CToolTipCtrl* m_gpToolTip; //...
}; Initialize the two variables in the application's constructor to NULL: CTooltipsApp::CTooltipsApp()
{
m_hwndDialog = NULL;
m_gpToolTip = NULL;
} Override the CTooltipsApp::ProcessMessageFilter() function as follows: BOOL CTooltipsApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if (m_hwndDialog != NULL)
if (lpMsg->hwnd == m_hwndDialog ||
::IsChild(m_hwndDialog, lpMsg->hwnd))
{
if (NULL != m_gpToolTip)
m_gpToolTip->RelayEvent(lpMsg);
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
} Use ClassWizard to add a member variable for the OK button in the CAboutDlg class, and call it m_btOK. Also, add a m_pToolTip pointer to a CToolTipCtrl object: class CAboutDlg : public CDialog
{
public:
CAboutDlg(); // Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CButton m_btOK;
//}}AFX_DATA CToolTipCtrl* m_pToolTip; //...
}; Add code to the CAboutDlg class constructor and destructor to initialize and release the tooltip object. You might also need to add a default destructor first: CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
m_pToolTip = NULL;
} CAboutDlg::~CAboutDlg()
{
delete m_pToolTip;
} Override the OnInitDialog() function of the CAboutDlg class to pass the dialog's handle to the application: BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog(); ((CTooltipsApp*)AfxGetApp())->m_hwndDialog=m_hWnd; if (!m_pToolTip)
{
m_pToolTip = new CToolTipCtrl;
if(!m_pToolTip->Create(this))
{
TRACE("Unable To create ToolTip\n");
return TRUE;
} ((CTooltipsApp*)AfxGetApp())->m_gpToolTip = m_pToolTip; if(m_pToolTip->AddTool(this, "About Box"))
{
TRACE("Unable to add Dialog to the tooltip\n");
} if (m_pToolTip->AddTool(&m_btOK,"OK Button"))
{
TRACE("Unable to add OK button to the tooltip\n");
} m_pToolTip->Activate(TRUE);
} return TRUE;//return TRUE unless you set the focus to a control
//EXCEPTION: OCX Property Pages should return FALSE
} Override the PostNcDestroy() function of the CAboutDlg class to reset the variables in the application class: void CAboutDlg::PostNcDestroy( )
{
CDialog::PostNcDestroy(); ((CToolTipsApp*)AfxGetApp())->m_hwndDialog= NULL;
((CToolTipsApp*)AfxGetApp())->m_gpToolTip= NULL;
} Rebuild the application, and bring up the About dialog box, you will see the tooltips.Additional query words: 2.10 2.20 3.10 3.20 4.00 Keywords : kbcode kbMFC kbToolTip KbUIDesign kbVC210 kbVC220 kbVC400 kbGrpMFCATL kbDialog
Version : winnt:2.1,2.2,4.0
Platform : winnt
Issue type : kbhowto
Technology : kbvc
Last Reviewed: March 13, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.