SetWindowsHookEx() function cannot trap Alt-Tab messages
-
I have read the API on how to use the SetWindowsHookEx() function and I was able to interrupt other keyboard keypresses in Windows 98 but I still can't trap Alt-Tab. Thank you.
To trap Alt+Tab you have to catch the message before the OS process it. A simple way to achieve it is to register Alt+Tab as a hotkey:
BOOL CYourDlg::OnInitDialog() { ... m_nHotKeyID = 100; // Unique identifier of the new hotkey. BOOL m_isKeyRegistered = RegisterHotKey(GetSafeHwnd(), m_nHotKeyID, MOD_ALT, VK_TAB); ... }
To process the hotkey PreTranslate WM_HOTKEY:BOOL CYourDlg::PreTranslateMessage(MSG* pMsg) { ... if((pMsg->message == WM_HOTKEY) && (pMsg->wParam == m_nHotKeyID)) MessageBox("Alt+Tab trapped"); .... }
Remember to unregister it before existing the app:BOOL CYourDlg::OnDestroy() { ... UnregisterHotKey(GetSafeHwnd(), m_nHotKeyID); ... }
Read Lock Windows Desktop[^], there are some references that shows it. I hope it helps, Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.