Get previously active window??
-
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)
-
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)
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