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("未能创建工具栏/n");
return -1; // 未能创建
}
// TODO: 如果不需要工具栏可停靠,则删除这三行
//m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
//EnableDocking(CBRS_ALIGN_ANY);
//DockControlBar(&m_wndToolBar);
...................................................................
修改提示信息
class CMainFrame : public CFrameWnd
{
..........
afx_msg BOOL OnToolTipText(UINT id_, NMHDR* pNMHDR_, LRESULT* pResult_);
};
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, &CMainFrame::OnToolTipText)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, &CMainFrame::OnToolTipText)
// copy from afximpl.h
#define _AfxGetDlgCtrlID(hWnd) ((UINT)(WORD)::GetDlgCtrlID(hWnd))
//copy and modify from CMainFrame::OnToolTipText
BOOL CMainFrame::OnToolTipText(UINT id_, NMHDR* pNMHDR_, LRESULT* pResult_)
{
ENSURE_ARG(pNMHDR_ != NULL);
ENSURE_ARG(pResult_ != NULL);
ASSERT(pNMHDR_->code == TTN_NEEDTEXTA || pNMHDR_->code == TTN_NEEDTEXTW);
// need to handle both ANSI and UNICODE versions of the message
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR_;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR_;
TCHAR szFullText[256];
CString strTipText;
UINT_PTR 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 = _AfxGetDlgCtrlID((HWND)nID);
}
if (nID != 0) // will be zero on a separator
{
CAxesErrEditorView* _pTarget = GetAxesErrEditorLangManager();
ASSERT(_pTarget);
// don't handle the message if no string resource found
if (_pTarget->LangLoadString((UINT)nID, szFullText) == 0)
return FALSE;
// this is the command id, not the button index
AfxExtractSubString(strTipText, szFullText, 1, '/n');
}
#ifndef _UNICODE
if (pNMHDR_->code == TTN_NEEDTEXTA)
Checked::strncpy_s(pTTTA->szText, _countof(pTTTA->szText), strTipText, _TRUNCATE);
else
_mbstowcsz(pTTTW->szText, strTipText, _countof(pTTTW->szText));
#else
if (pNMHDR_->code == TTN_NEEDTEXTA)
_wcstombsz(pTTTA->szText, strTipText, _countof(pTTTA->szText));
else
Checked::wcsncpy_s(pTTTW->szText, _countof(pTTTW->szText), strTipText, _TRUNCATE);
#endif
*pResult_ = 0;
UINT uFlags = 0;
// bring the tool tip window above other popup windows
uFlags |= SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER;
::SetWindowPos(pNMHDR_->hwndFrom, HWND_TOP, 0, 0, 0, 0, uFlags);
return TRUE; // message was handled
}