VAN0 Posted November 18, 2018 Share Posted November 18, 2018 (edited) Hello. My understanding that if window doesn't exist, WinGetHandle() returns 0x00000000, which pretty much equal to "false", this raises two questions for me: 1) why do we need WinExists()? 2) why do we need @error flag in WinGetHandle()? Edited November 18, 2018 by VAN0 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted November 18, 2018 Share Posted November 18, 2018 @VAN0 To see if a Window exists, why don't you use directly WinExists()? WinGetHandle() is used when you need to "manage" your window (move, use Control* functions...). So, you can use WinExist() to check if a window exists or not. @error (and @extended in some cases) is an AutoIt macro which tells you what has going on when you called a function; in almost every case, it will be 0 if no error occurred, otherwise it will be non-zero (you can find the reference of all error possible values in the Help file, of the specific function you are calling). It's a good macro because you can debug your code, and, for example, in case of error, decide to exit your script. So, that's it Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Earthshine Posted November 18, 2018 Share Posted November 18, 2018 (edited) WinGetHandle returns DOES NOT return a null pointer. only if successful does it return the handle (pointer to) the window Return Value Success: a handle to the window. Failure: sets the @error flag to non-zero if the window is not found. Remarks This function allows you to use handles to specify windows rather than "title" and "text". Once you have obtained the handle you can access the required window even if its title changes. return is NOT a pointer unless it is VALID!!! so, your understanding wrong. if failure, it sets @error flag to non-zero, so that is a lot more checking than a WinExists Edited November 18, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
VAN0 Posted November 18, 2018 Author Share Posted November 18, 2018 (edited) 6 hours ago, Earthshine said: WinGetHandle returns DOES NOT return a null pointer. only if successful does it return the handle (pointer to) the window So? If it doesn't return handle, it means window doesn't exist, which is exactly my point... Here is a little example: #include <GUIConstantsEx.au3> $hGUI = GUICreate("Existing window") GUISetState(@SW_SHOW, $hGUI) $we1 = WinExists("Existing window") $we2 = WinExists("Non-existing window") $wgh1 = WinGetHandle("Existing window") $wgh2 = WinGetHandle("Non-existing window") ConsoleWrite("WinExists(existing) = " & ($we1 ? true : false) & ": (" & $we1 & ")" & @CR) ConsoleWrite("WinExists(non-existing) = " & ($we2 ? true : false) & ": (" & $we2 & ")" & @CR) ConsoleWrite("WinGetHandle(existing) = " & ($wgh1 ? true : false) & ": (" & $wgh1 & ")" & @CR) ConsoleWrite("WinGetHandle(non-existing) = " & ($wgh2 ? true : false) & ": (" & $wgh2 & ")" & @CR) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Exit Both WinExists() and WinGetHandle() can be used in If .. .Then without need of @error So my point is, WinGetHandle practically replaces WinExists and @error is redundant as it doesn't contain any more useful information then a 0x00000000 handle returned when window doesn't exist Unless of course WinGetHandle is super inefficient compare to WinExists... Edited November 18, 2018 by VAN0 Link to comment Share on other sites More sharing options...
Earthshine Posted November 18, 2018 Share Posted November 18, 2018 (edited) Whatever floats your boat. Winexists is still easier. If it makes you happy though. Your understanding was still incorrect. And you could do testing on your own to see what’s more efficient Edited November 18, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
VAN0 Posted November 18, 2018 Author Share Posted November 18, 2018 My understanding of what exactly is wrong? Link to comment Share on other sites More sharing options...
Earthshine Posted November 18, 2018 Share Posted November 18, 2018 Re-read the thread and answer your own question. I’m done FrancescoDiMuro 1 My resources are limited. You must ask the right questions 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