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. Visual Basic
  4. Get previously active window??

Get previously active window??

Scheduled Pinned Locked Moved Visual Basic
csharpjsonquestionannouncement
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
    matsnas
    wrote on last edited by
    #1

    Hi! Trying to get the handle of the window (actual app, not textbox or other window) that was active before I clicked in my own win form? I've tried GetActiveWindow and GetWindow with the GW_HWNDNEXT and GW_HWNDPREV paremeters but I'm no expert using Windows API's and can't seem to get it to work: 'Get the next window handle. Dim vWndActive As IntPtr = GetActiveWindow Dim vWndPrev As IntPtr = GetWindow(vWndActive, GW_HWNDPREV) 'this line doesn't work!! 'Activate previously active window Dim vClassName As String = Space(256) GetWindowText(vWndPrev, vClassName, vClassName.Length) AppActivate(vClassName) I know this code doesn't work and may not make much sense but it's the stripped version of what I'm trying to do and I think you get the point. (Ps. Using vb.net)

    D 1 Reply Last reply
    0
    • M matsnas

      Hi! Trying to get the handle of the window (actual app, not textbox or other window) that was active before I clicked in my own win form? I've tried GetActiveWindow and GetWindow with the GW_HWNDNEXT and GW_HWNDPREV paremeters but I'm no expert using Windows API's and can't seem to get it to work: 'Get the next window handle. Dim vWndActive As IntPtr = GetActiveWindow Dim vWndPrev As IntPtr = GetWindow(vWndActive, GW_HWNDPREV) 'this line doesn't work!! 'Activate previously active window Dim vClassName As String = Space(256) GetWindowText(vWndPrev, vClassName, vClassName.Length) AppActivate(vClassName) I know this code doesn't work and may not make much sense but it's the stripped version of what I'm trying to do and I think you get the point. (Ps. Using vb.net)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      There is no function that will return the previously active window. AFAIK, the only reliable way would be to override your window's WndProc and look for the WM_ACTIVATE message. If the low order word of the wParam field of this message contains the WA_ACTIVE or WA_CLICKACTIVE message, the lParam of the message will contain the handle to the window that lost the focus. Once this message is processed by your application, it's way too late to call any function to find out what the previous window was. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      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