Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SetWindowsHookEx() function cannot trap Alt-Tab messages

SetWindowsHookEx() function cannot trap Alt-Tab messages

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JP Manalo
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • J JP Manalo

      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.

      M Offline
      M Offline
      Marc Soleda
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups