HHOOK hHook = NULL;
// Hook procedure for WH_GETMESSAGE hook type.
LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM
lParam)
{
// Switch the module state for the correct handle to be used.
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
// If this is a keystrokes message, translate it in controls'
// PreTranslateMessage().
LPMSG lpMsg = (LPMSG) lParam;
if( (nCode >= 0) &&
PM_REMOVE == wParam &&
AfxGetApp()->PreTranslateMessage(lpMsg))
{
lpMsg->message = WM_NULL;
lpMsg->lParam = 0L;
lpMsg->wParam = 0;
}
// Passes the hook information to the next hook procedure in
// the current hook chain.
return ::CallNextHookEx(hHook, nCode, wParam, lParam);
}
int CCToolBarCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// Create a CToolBar window which is a child of ActiveX control.
if (!m_ToolBar.Create(this,
WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS) ||
!m_ToolBar.LoadToolBar(IDR_TOOLBAR))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
// Toolbar has to have TBSTYLE_TOOLTIPS style. Otherwise,
// notification handler for TTN_NEXTTEXT won't be called.
m_ToolBar.ModifyStyle (0, TBSTYLE_TOOLTIPS);
// Move the toolbar so it is VISIBLE on the screen.
CRect rc;
GetClientRect(&rc);
rc.bottom = rc.top + 34;
m_ToolBar.MoveWindow(&rc);
// Because ActiveX control is an inproc server, it does not have a
// message pump. So, messages to child windows created by the
// ActiveX control are not going to be received by the control.
// Thus, we set up a message hook to call PreTranslateMessage().
// This results in the call to FilterToolTipMessage(), which
// activates tooltips.
hHook = ::SetWindowsHookEx(
WH_GETMESSAGE,
GetMessageProc,
AfxGetInstanceHandle(),
GetCurrentThreadId());
ASSERT (hHook);
return 0;
}
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。