Zohar Posted February 8, 2009 Share Posted February 8, 2009 (edited) HelloThis code should get a Handle to the last active window, and then MsgBox the last active window's Title.Yet it returns a different result.. of some different window..Anyone knows what I need to change in this code in order to make it work?CODE#Include <Constants.au3>Local $hWnd =DllCall("user32.dll","hwnd","GetNextWindow","hwnd",WinGetHandle("[ACTIVE]"),"int",$GW_HWNDNEXT)Local $Title =WinGetTitle($hWnd)MsgBox(0,"",$Title)this API function is from here:GetNextWindow Functionhttp://msdn.microsoft.com/en-us/library/ms633509(VS.85).aspx Edited February 12, 2009 by Zohar Link to comment Share on other sites More sharing options...
martin Posted February 8, 2009 Share Posted February 8, 2009 Hello This code should get a Handle to the last active window, and then MsgBox the last active window's Title. Yet it returns a different result.. of some different window.. Anyone knows what I need to change in this code in order to make it work? CODE #Include <Constants.au3> Local $hWnd =DllCall("user32.dll","hwnd","GetNextWindow","hwnd",WinGetHandle("[ACTIVE]"),"int",$GW_HWNDNEXT) Local $Title =WinGetTitle($hWnd) MsgBox(0,"",$Title) this API function is from here: GetNextWindow Function http://msdn.microsoft.com/en-us/library/ms633509(VS.85).aspxThe value of @error is 3 for me after making the dllcall so there is no such function. If you use GetWindow instead then you might have more luck. Also you get an array returned from dllcall if it succeeds. #Include <Constants.au3> Local $hWnd =DllCall("user32.dll","hwnd","GetWindow","hwnd",WinGetHandle("[ACTIVE]"),"int",$GW_HWNDLAST);$GW_HWNDNEXT) ConsoleWrite(@error & @CRLF) Local $Title =WinGetTitle($hWnd[0]) $wp = WinGetPos($hwnd[0]) ConsoleWrite($wp[0] & ', ' & $wp[1] & ', ' & $wp[2] & ', ' & $wp[3] & @CRLF) MsgBox(0,"",$Title) But it might be easier to use WinList which gives the windows in their Z order and just select the visible ones because I suspect that GetWindow will not care if the window is visible or not so you might not get the window of the previously active application in the way that Alt TAB gives for example. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Zohar Posted February 8, 2009 Author Share Posted February 8, 2009 hi martin.. yeah I did eventually use WinList() to get the previous window CODEFunc GetPreviousWindow() Local $WinList =WinList() For $i = 1 to $WinList[0][0] If ($WinList[$i][0]<>"") AND BitAnd(WinGetState($WinList[$i][1]),2) Then ExitLoop Next Return $WinList[$i][1] EndFunc The code is very short so I am happy, tho I wonder why my API call did not work That function does exist.. as MSDN shows:) but ok thank you ! Link to comment Share on other sites More sharing options...
trancexx Posted February 8, 2009 Share Posted February 8, 2009 It's not in my user32.dll either (XP SP3) ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
martin Posted February 8, 2009 Share Posted February 8, 2009 ..That function does exist.. as MSDN shows:)but okthank you !How much do you want to bet? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Richard Robertson Posted February 8, 2009 Share Posted February 8, 2009 Minimum operating systems Windows 95, Windows NT 3.1I would assume that means it's a much older function. Link to comment Share on other sites More sharing options...
monoceres Posted February 8, 2009 Share Posted February 8, 2009 It's not in my user32.dll either (XP SP3) It's because GetNextWindow is just an alias for GetWindow(), from WinUser.h: #define GetNextWindow(hWnd, wCmd) GetWindow(hWnd, wCmd) Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
trancexx Posted February 8, 2009 Share Posted February 8, 2009 Yes, I see. Like that AVI function that was killing you. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Zohar Posted February 9, 2009 Author Share Posted February 9, 2009 (edited) How much do you want to bet?hehe =] It's because GetNextWindow is just an alias for GetWindow(), from WinUser.h: #define GetNextWindow(hWnd, wCmd) GetWindow(hWnd, wCmd)damn, you're good :] btw I must say, that even after changing the Function Name to GetWindow: Local $hWnd =DllCall("user32.dll","hwnd","GetWindow","hwnd",WinGetHandle("[ACTIVE]"),"int",$GW_HWNDNEXT) Local $Title =WinGetTitle($hWnd) MsgBox(0,"",$Title) It still shows the title of Current Window instead of the previous one. (I did solve the problem with WinList, as said, tho it makes me wonder, why a simple API call does not succeed =( ) Edited February 9, 2009 by Zohar Link to comment Share on other sites More sharing options...
Richard Robertson Posted February 9, 2009 Share Posted February 9, 2009 Is your $GW_HWNDNEXT defined correctly? Link to comment Share on other sites More sharing options...
Zohar Posted February 9, 2009 Author Share Posted February 9, 2009 I have "#Include <Constants.au3>" at the top of the file.. so it means yes.. Link to comment Share on other sites More sharing options...
KaFu Posted February 9, 2009 Share Posted February 9, 2009 Why don't you use Winlist() for this task? As far as I know it returns hWnd in order of last activity. $var = WinList() For $i = 1 to $var[0][0] If $var[$i][0] <> "" AND IsVisible($var[$i][1]) AND $var[$i][1] <> WinGetHandle("[ACTIVE]") Then MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1]) ExitLoop EndIf Next Func IsVisible($handle) If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now