CFrameWnd::CFrameWnd 不能显示tooltips

ussthamcn 2012-09-02 11:56:30
原帖没有人恩回复,我自己不能跟新,新开一个帖子。

研究了下正常的tooltips处理过程应该是
CToolTipsCtrl CToolBar
TTM_GETTOOLINFO ------------>
TTM_GETTOOLINFO<-------------
TTM_ADDTOOL ---------------->
TTM_ADDTOOL <----------------
TTM_ACTIVATE -------
TTM_ACTIVATE -------
TTM_WINDOWFROMPOINT ---------
TTM_WINDOWFROMPOINT ---------
TTM_RELAYEVENT ------------->
TTM_RELAYEVENT <-------------
TTM_DELTOOL ---------------->
TTM_DELTOOL <----------------
我的程序却没有TTM__XXX tooltips消息,不知道消息去哪里了呢
...全文
203 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
看不见的裂痕 2012-09-02
  • 打赏
  • 举报
回复
楼主你老帖我有映像,贴出来看看吧。
ussthamcn 2012-09-02
  • 打赏
  • 举报
回复
4.PreTranslateMessage中调用m_pfnFilterToolTipMessage指针指向的函数
BOOL CWnd::PreTranslateMessage(MSG* pMsg)
{
// handle tooltip messages (some messages cancel, some may cause it to popup)
AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE();
if (pModuleState->m_pfnFilterToolTipMessage != NULL)
(*pModuleState->m_pfnFilterToolTipMessage)(pMsg, this);

// no default processing
return FALSE;
}
ussthamcn 2012-09-02
  • 打赏
  • 举报
回复
整理下今天看的MFC的源代码:
1. CWnd是CToolBar的父类,CWnd有个成员函数FilterToolTipMessage(...)
该函数中过滤tooltips消息TTM_XX, 创建CToolTipCtrl对象,并把地址赋给_AFX_THREAD_STATE的m_pToolTip,并向CToolTipCtrl窗口发送TTM_XX消息.

2. 在CToolBar的父类中, m_toolbar.Create(..CBRS_TOOLTIPS...)
3. DockControlBar(&m_toolbar)的时候调用pBar->SetBarStyle(dwStyle);在SetBarStyle()中调用
EnableToolTips(..),
{
    pModuleState->m_pfnFilterToolTipMessage=CWnd::FilterToolTipMessage
  }
ussthamcn 2012-09-02
  • 打赏
  • 举报
回复
原帖:http://topic.csdn.net/u/20120709/21/254c4d23-d649-4b6a-bc98-ef6693b5c0ca.html
我的程序没有Tooltips消息,我的CMainFrame框架类中使用了框架结构VisualFx.h/VisualFx.cpp
有TTabItem/TVisualObject/TVisualFramework这些类
是不是这些消息被这些框架截获了,不过spy++应该能截获这个消息啊,困惑啊
// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "五子棋.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif HCURSOR m_hcursor; ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_WM_SETCURSOR() //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers BOOL CMainFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default BOOL br = CFrameWnd::OnSetCursor( pWnd, nHitTest,message) ; if(star==1) { if(flag==1) { m_hcursor= AfxGetApp()->LoadCursor(IDC_hei); SetCursor(m_hcursor); br = TRUE; } else if(flag==2) { m_hcursor= AfxGetApp()->LoadCursor(IDC_bai); SetCursor(m_hcursor); br = TRUE; } } return br; // return CFrameWnd::OnSetCursor(pWnd, nHitTest, message); }
自己写的数据库大作业,用MFC ODBC +access 写的 内含完整工程,解压后就能用 // MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "ODBCdemo.h" #include "MainFrm.h" #include "BrwMessagedlg.h" #include "ReaderAdmindlg.h" #include "BookUpdatedlg.h" #include "LogIndlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_COMMAND(ID_BCG, OnBcg) ON_COMMAND(IDD_ReaderUpdate, OnReaderUpdate) ON_COMMAND(IDBK_UPDATE, OnBookUpdate) //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here m_bAutoMenuEnable=FALSE; } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } if (!m_wndDlgBar.Create(this, IDD_DIALOGBAR, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, IDD_DIALOGBAR)) { TRACE0("Failed to create dialogbar\n"); return -1; // fail to create } m_wndDlgBar.EnableDocking(CBRS_ORIENT_HORZ); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndDlgBar); CLogIndlg cdlg; if( cdlg.DoModal()==IDOK) { if(cdlg.role=="读者") { for(int i=0;iGetSubMenu(i)->EnableMenuItem(1,MF_BYPOSITION|MF_GRAYED); } } else Destroy
// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "Snake.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers //DEL void CMainFrame::OnGameStart() //DEL { //DEL // TODO: Add your command handler code here //DEL IniGame(); //DEL m_nGameStatus = 1; //DEL SetTimer(1,100,NULL); //DEL Invalidate(); //DEL }
// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "Menu.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_COMMAND(IDM_TEST, OnTest) ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut) ON_UPDATE_COMMAND_UI(ID_FILE_NEW, OnUpdateFileNew) ON_COMMAND(IDM_SHOW, OnShow) //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here m_bAutoMenuEnable = FALSE; } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); /* GetMenu()->GetSubMenu(0)->CheckMenuItem(0, MF_BYPOSITION | MF_CHECKED); GetMenu()->GetSubMenu(0)->CheckMenuItem(ID_FILE_NEW, MF_BYCOMMAND | MF_CHECKED); GetMenu()->GetSubMenu(0)->SetDefaultItem(1,TRUE); GetMenu()->GetSubMenu(0)->SetDefaultItem(ID_FILE_OPEN,FALSE); GetMenu()->GetSubMenu(0)->SetDefaultItem(5,TRUE); CString str; str.Format("x=%d, y=%d",GetSystemMetrics(SM_CXMENUCHECK),GetSystemMetrics(SM_CYMENUCHECK)); MessageBox(str); m_bitmap.LoadBitmap(IDB_BITMAP1); GetMenu()->GetSubMenu(0)->SetMenuItemBitmaps(0,MF_BYPOSITION, &m_bitmap, &m_bitmap); */ GetMenu()->GetSubMenu(0)->EnableMenuItem(1, MF_BYPOSITION | MF_DISABLED); SetMenu(NULL); CMenu menu; menu.LoadMenu(IDR_MAINFRAME); SetMenu(&menu); menu.Detach(); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers void CMainFrame::OnTest() { // TODO: Add your command handler code here MessageBox("MainFrame Clicked"); } void CMainFrame::OnUpdateEditCut(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here if(2 == pCmdUI->m_nIndex) pCmdUI->Enable(); } void CMainFrame::OnUpdateFileNew(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here // if(ID_FILE_NEW == pCmdUI->m_nID); /* if(0 == pCmdUI->m_nIndex) pCmdUI->Enable(FALSE); */ } void CMainFrame::OnShow() { // TODO: Add your command handler code here MessageBox("Main show"); }

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧