BOOL CRichEditNcBorder::Initialize(HWND hwndRichEdit) { if (hwndRichEdit) // hook { if (IsHooked()) return TRUE; // else if (HookWindow(hwndRichEdit)) { VerifyThemedBorderState(); return TRUE; } // else return FALSE; } // else unhook if (IsHooked()) return HookWindow(NULL); // else return TRUE; }
BOOL CToolbarHelper::Release(BOOL bClearDropBtns) { if (HookWindow(NULL) && ScHookWindow(NULL)) { if (bClearDropBtns) { // iterate the buttons the hard way POSITION pos = m_mapTHButtons.GetStartPosition(); while (pos) { THButton dm = { 0 }; UINT nCmdID = 0; m_mapTHButtons.GetNextAssoc(pos, nCmdID, dm); ClearDropButton(nCmdID, FALSE); } } m_pToolbar = NULL; m_mapTHButtons.RemoveAll(); m_tt.DestroyWindow(); return TRUE; } return FALSE; }
BOOL CShortcutManager::Release() { if (!IsHooked()) return TRUE; return HookWindow(NULL); }
void TestApp::OnInitialize(u32 width, u32 height) { mWindow.Initialize(GetInstance(), GetAppName(), width, height); HookWindow(mWindow.GetWindowHandle()); mTimer.Initialize(); mGraphicsSystem.Initialize(mWindow.GetWindowHandle(), false); SimpleDraw::Initialize(mGraphicsSystem); const u32 windowWidth = mGraphicsSystem.GetWidth(); const u32 windowHeight = mGraphicsSystem.GetHeight(); mCamera.Setup(Math::kPiByTwo, (f32)windowWidth / (f32)windowHeight, 0.01f, 1000.0f); mCamera.SetPosition(Math::Vector3(0.0f, 2.0f, 1.0f)); mCamera.SetLookAt(Math::Vector3(0.0f, 1.0f, 0.0f)); mRenderer.Initialize(mGraphicsSystem); mModel.Load(mGraphicsSystem, "../Data/Models/soldier1.txt"); mAnimationController.Initialize(mModel); //AnimationClip clip; //mAnimationController.StartClip(clip, true); mAnimationController.StartClip(*mModel.mAnimations[0], true); }
BOOL CWndPrompt::Initialize(HWND hWnd, LPCTSTR szPrompt, UINT nCheckMsg, LRESULT lRes, int nVertOffset) { ASSERT (hWnd); ASSERT (!IsHooked()); // ASSERT (szPrompt && *szPrompt); ASSERT (nCheckMsg); if (!IsHooked() && hWnd && szPrompt && *szPrompt && nCheckMsg) { if (HookWindow(hWnd)) { m_sPrompt = szPrompt; m_nCheckMsg = nCheckMsg; m_lCheckResult = lRes; m_sClass = CWinClasses::GetClass(hWnd); m_nVertOffset = max(nVertOffset, 0); if (WantPrompt()) Invalidate(); return TRUE; } } return FALSE; }
CShortcutManager::~CShortcutManager(void) { if (m_hWndHooked) { HookWindow((HWND)NULL); } ASSERT(m_hWndHooked==NULL); }
LRESULT CALLBACK GetMsgProc (int nCode, WPARAM wParam, LPARAM lParam) { if (nCode >= 0) { if (bbSkinMsg == ((MSG*)lParam)->message && BBLS_LOAD == ((MSG*)lParam)->wParam) { //dbg_printf("getmsg hwnd %x hk %x", ((MSG*)lParam)->hwnd, hGetMsgHook); HookWindow(((MSG*)lParam)->hwnd, 0); } } return CallNextHookEx(hGetMsgHook, nCode, wParam, lParam); }
BOOL CToolbarHelper::Initialize(CToolBar* pToolbar, CWnd* pToolbarParent, const CShortcutManager* pShortcutMgr) { ASSERT_VALID(pToolbar); if (!pToolbar || !pToolbar->GetSafeHwnd() || !pToolbarParent || !HookWindow(*pToolbarParent)) return FALSE; m_pToolbar = pToolbar; m_pShortcutMgr = pShortcutMgr; InitTooltips(); return TRUE; }
BOOL CSkinWin::InstallSkin(CWnd *wnd) { if ( !wnd || !m_bInit ) return FALSE; HookWindow( (HWND)NULL); int r = HookWindow( wnd ); m_pHookedWnd = wnd; DWORD style = GetWindowLong( m_hWnd, GWL_STYLE ); m_sizable = style & WS_SIZEBOX; m_minable = style & WS_MINIMIZEBOX; m_maxable = style & WS_MAXIMIZEBOX; m_sysmenu = style & WS_SYSMENU; style &= ~(WS_MINIMIZEBOX); style &= ~WS_MAXIMIZEBOX; style &= ~WS_SYSMENU; DWORD nCaption = style & WS_CAPTION ; SetWindowLong( m_hWnd, GWL_STYLE, style ); return r; }
BOOL CToolbarHelper::Initialize(CToolBar* pToolbar, CWnd* pToolbarParent) { if (!pToolbarParent || !HookWindow(*pToolbarParent)) { return FALSE; } ASSERT_VALID(pToolbar); m_pToolbar = pToolbar; InitTooltips(); return TRUE; }
BOOL CDockManager::Initialize(CWnd* pMainWnd, CWnd* pDockWnd, DM_POS nPos, DM_POS nLastPos, int nWidthDocked, int nWidthDockedMax, int nHeightDocked, int nHeightDockedMax) { if (!HookWindow(*pMainWnd) || !ScHookWindow(*pDockWnd)) return FALSE; m_nLastDockPos = nLastPos; m_nWidthDocked = nWidthDocked; m_nWidthDockedMax = nWidthDockedMax; m_nHeightDocked = nHeightDocked; m_nHeightDockedMax = nHeightDockedMax; return Dock(nPos); }
BOOL CShortcutManager::Initialize(CWnd* pOwner, WORD wInvalidComb, WORD wFallbackModifiers) { if (wInvalidComb && !IsHooked()) { if (pOwner && HookWindow(*pOwner)) { m_wInvalidComb = wInvalidComb; m_wFallbackModifiers = wFallbackModifiers; //LoadSettings(); return TRUE; } } return FALSE; }
LRESULT CToolbarHelper::WindowProc(HWND hRealWnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_NOTIFY: { LPNMHDR pNMHDR = (LPNMHDR)lp; switch (pNMHDR->code) { case TBN_DROPDOWN: // check its our toolbar if (pNMHDR->hwndFrom == m_pToolbar->GetSafeHwnd()) { // load the menu LPNMTOOLBAR pNMTB = (LPNMTOOLBAR)pNMHDR; if (DisplayDropMenu((UINT)pNMTB->iItem)) return FALSE; // we handled it } break; #ifndef _UNICODE case TTN_NEEDTEXTA: #else case TTN_NEEDTEXTW: #endif { // to be thorough we will need to handle UNICODE versions of the message also !! TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR; // only handle this if it's not already been done if (pTTT->lpszText && *(pTTT->lpszText)) break; UINT nID = pNMHDR->idFrom; if (pTTT->uFlags & TTF_IDISHWND) // idFrom is actually the HWND of the tool nID = ::GetDlgCtrlID((HWND)nID); // get cursor pos CPoint point(::GetMessagePos()); m_pToolbar->ScreenToClient(&point); // get tip static CString sTipText; sTipText = GetTip(nID, &point); if (!sTipText.IsEmpty()) // will be zero on a separator { pTTT->lpszText = (LPTSTR)(LPCTSTR)sTipText; return TRUE; } } break; case TTN_SHOW: { CWnd* pTooltipCtrl = CWnd::FromHandle(pNMHDR->hwndFrom); ASSERT (pTooltipCtrl); pTooltipCtrl->SendMessage(TTM_SETMAXTIPWIDTH, 0, (m_bMultiline ? m_nMultilineWidth : UINT_MAX)); if (m_pShortcutMgr) { static UINT nIDLastShow = 0; UINT nCmdID = pNMHDR->idFrom; // prevent re-entrancy on same tip if (nCmdID != nIDLastShow) { TOOLINFO ti = { 0 }; ti.cbSize = sizeof(ti); ti.hwnd = *m_pToolbar; // restore callback on last shown item if (nIDLastShow) { ti.uId = nIDLastShow; pTooltipCtrl->SendMessage(TTM_GETTOOLINFO, 0, (LPARAM)&ti); ti.lpszText = LPSTR_TEXTCALLBACK; pTooltipCtrl->SendMessage(TTM_SETTOOLINFO, 0, (LPARAM)&ti); nIDLastShow = 0; } // append shortcut text to new item THButton dm = { 0 }; if (m_mapTHButtons.Lookup(nCmdID, dm)) { if (dm.nDefCmdID) nCmdID = dm.nDefCmdID; } CString sShortcut = m_pShortcutMgr->GetShortcutTextByCmd(nCmdID); if (!sShortcut.IsEmpty()) { // store original id immediately to prevent re-entrancy nIDLastShow = pNMHDR->idFrom; const int TIP_LEN = 80; TCHAR szTip[TIP_LEN] = { 0 }; ti.lpszText = szTip; ti.hwnd = *m_pToolbar; ti.uId = pNMHDR->idFrom; pTooltipCtrl->SendMessage(TTM_GETTEXT, TIP_LEN, (LPARAM)&ti); CString sTip; sTip.Format(_T("%s (%s)"), szTip, sShortcut); ti.lpszText = (LPTSTR)(LPCTSTR)sTip; pTooltipCtrl->SendMessage(TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); pTooltipCtrl->SendMessage(TTM_UPDATE); } } } } break; } } break; case WM_COMMAND: { HWND hCtrlFrom = (HWND)lp; // if m_pToolbar sent the command and we have a mapping for it then // change it to the default cmd for that button if (hCtrlFrom == *m_pToolbar) { THButton dm = { 0 }; UINT nCmdID = LOWORD(wp); if (m_mapTHButtons.Lookup(nCmdID, dm)) { // if we have an enabled default command then send it if (dm.nDefCmdID && IsCmdEnabled(dm.nDefCmdID)) { wp = MAKEWPARAM(dm.nDefCmdID, HIWORD(wp)); } else { BOOL bRes = DisplayDropMenu(nCmdID, TRUE); if (bRes) return 0L; // we handled it } } } } break; case WM_DESTROY: { // must call rest of chain first LRESULT lr = CSubclassWnd::WindowProc(hRealWnd, msg, wp, lp); HookWindow(NULL); return lr; } } return CSubclassWnd::WindowProc(hRealWnd, msg, wp, lp); }
CSubclassWnd::~CSubclassWnd() { if (m_hWnd) HookWindow((HWND)NULL); // unhook window }
////////////////// // Call this to install the menu manager. Install(NULL) to un-install. // void CCoolMenuManager::Install(CFrameWnd* pFrame) { ASSERT_VALID(pFrame); m_pFrame = pFrame; HookWindow(pFrame); // install message hook }
LRESULT CToolbarHelper::WindowProc(HWND hRealWnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_NOTIFY: { LPNMHDR pNMHDR = (LPNMHDR)lp; switch (pNMHDR->code) { case TBN_DROPDOWN: // check its our toolbar if (pNMHDR->hwndFrom == m_pToolbar->GetSafeHwnd()) { // load the menu LPNMTOOLBAR pNMTB = (LPNMTOOLBAR)pNMHDR; if (DisplayDropMenu((UINT)pNMTB->iItem)) { return FALSE; // we handled it } } break; case TTN_NEEDTEXT: { // to be thorough we will need to handle UNICODE versions of the message also !! TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pNMHDR; UINT nID = pNMHDR->idFrom; if (pTTT->uFlags & TTF_IDISHWND) // idFrom is actually the HWND of the tool { nID = ::GetDlgCtrlID((HWND)nID); } // get cursor pos CPoint point(::GetMessagePos()); m_pToolbar->ScreenToClient(&point); // get tip static CString sTipText; sTipText = GetTip(nID, &point); if (!sTipText.IsEmpty()) // will be zero on a separator { pTTT->lpszText = (LPTSTR)(LPCTSTR)sTipText; return TRUE; } } break; case TTN_SHOW: { CWnd* pTooltipCtrl = CWnd::FromHandle(pNMHDR->hwndFrom); ASSERT(pTooltipCtrl); pTooltipCtrl->SendMessage(TTM_SETMAXTIPWIDTH, 0, m_bMultiline ? m_nMultilineWidth : UINT_MAX); } break; } } break; case WM_COMMAND: { HWND hCtrlFrom = (HWND)lp; // if m_pToolbar sent the command and we have a mapping for it then // change it to the default cmd for that button if (hCtrlFrom == *m_pToolbar) { THButton dm; UINT nCmdID = LOWORD(wp); if (m_mapTHButtons.Lookup(nCmdID, dm)) { // if we have an enabled default command then send it if (dm.nDefCmdID && IsCmdEnabled(dm.nDefCmdID)) { wp = MAKEWPARAM(dm.nDefCmdID, HIWORD(wp)); } else { BOOL bRes = DisplayDropMenu(nCmdID, TRUE); if (bRes) { return 0L; // we handled it } } } } } break; case WM_KICKIDLE: break; case WM_DESTROY: { // must call rest of chain first LRESULT lr = CSubclassWnd::WindowProc(hRealWnd, msg, wp, lp); HookWindow(NULL); return lr; } } return CSubclassWnd::WindowProc(hRealWnd, msg, wp, lp); }