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. Bringing desktop window to the top without taking focus

Bringing desktop window to the top without taking focus

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

    Off and on for some time I've tried to find the best way to bring a window (whose parent is the desktop) to the top of all the other application windows on some particular event. They could very well be using another application window at the time so I can't allow it to take the focus away as this could result in lost keystrokes. My current implementation of this is basically the following: HWND hwnd = ::GetForegroundWindow(); ::SetWindowPos(myhwnd, hwnd, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE); ::SetWindowPos(myhwnd, hwnd, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE); I've investigated numerous other ways over time. This works well but doesn't always work perfectly. Some times focus is stolen and sometimes the z-order isn't correct. These are rare cases and usually involve some specific other application that was in use at the time. I'm wondering if anyone could offer solutions they've tested and used in the past for performing something similar? Craig

    C 1 Reply Last reply
    0
    • C casid

      Off and on for some time I've tried to find the best way to bring a window (whose parent is the desktop) to the top of all the other application windows on some particular event. They could very well be using another application window at the time so I can't allow it to take the focus away as this could result in lost keystrokes. My current implementation of this is basically the following: HWND hwnd = ::GetForegroundWindow(); ::SetWindowPos(myhwnd, hwnd, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE); ::SetWindowPos(myhwnd, hwnd, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE); I've investigated numerous other ways over time. This works well but doesn't always work perfectly. Some times focus is stolen and sometimes the z-order isn't correct. These are rare cases and usually involve some specific other application that was in use at the time. I'm wondering if anyone could offer solutions they've tested and used in the past for performing something similar? Craig

      C Offline
      C Offline
      casid
      wrote on last edited by
      #2

      Sorry, I meant to code it: HWND hwnd = ::GetForegroundWindow(); ::SetWindowPos(myhwnd, hwnd, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE); ::SetWindowPos(hwnd, myhwnd, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);

      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