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. Capture Window Focus Change

Capture Window Focus Change

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • M Offline
    M Offline
    mjmim
    wrote on last edited by
    #1

    Hey Guys, If I want to know the process ID of the window that currently has focus then I call GetForegroundProcessID().... I am trying to think of the best way to capture a change in the focused window. I could create a systemhook on WH_CALLWNDPROC and search for a WM_ACTIVATE or WM_FOCUS message and check the process to whom it's being sent. or I could poll every x seconds and check who the window in focus is. Is there any option that I am not thinking of that won't hurt my perfomance like system hooks will?

    S 1 Reply Last reply
    0
    • M mjmim

      Hey Guys, If I want to know the process ID of the window that currently has focus then I call GetForegroundProcessID().... I am trying to think of the best way to capture a change in the focused window. I could create a systemhook on WH_CALLWNDPROC and search for a WM_ACTIVATE or WM_FOCUS message and check the process to whom it's being sent. or I could poll every x seconds and check who the window in focus is. Is there any option that I am not thinking of that won't hurt my perfomance like system hooks will?

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      If you're going to use a system hook, a WH_SHELL hook (look for a HSHELL_WINDOWACTIVATED notification) might be cheaper performance-wise? Otherwise, your other solution seems a pretty cheap (performance-wise) alternative. I don't know of other alternatives myself :-(

      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