Jump to content

What am i missing here ?


Recommended Posts

$Handle = WinGetHandle( WindowTitle )

MsgBox( 0, "Handle", $Handle )

MsgBox( 0, "int", IsInt( $Handle ) ) ; this one return 0

MsgBox( 0, "num", IsNumber( $Handle ) ) ; this one return 0

MsgBox( 0, "str", IsString( $Handle ) ) ; this one return 0

MsgBox( 0, "a", StringIsInt( $Handle ) ) ;but this return 1 in v3.1.1 and 0 in v3.1.1.90 :graduated:B)

MsgBox( 0, "b", StringIsXDigit( $Handle ) ) ; and this return 1 in v3.1.1 and 0 in v3.1.1.90 :):o

how autoit stores $Handle ?

Link to comment
Share on other sites

thanx, but i dont want to check if it an HWND, i just want to know how it is stored.

i have this problem

---------------------------------------------------

$Handle = GetWindowHandle( WindowTitle )

if $Handle == 0x00000000 do somthing <--- this give me LOTS of troubles, in v3.1.1 and v3.1.1.90

if $Handle == 0 do somthing <--- this give me LOTS of troubles too, in v3.1.1 and v3.1.1.90

if $Handle == Hex( 0, 8 ) do somthing <--- this works in v3.1.1 but not in v3.1.1.90

if Dec( $Handle ) == 0 do somthing <--- this somtimes works in v3.1.1 and in v3.1.1.90

---------------------------------------------------

so, how are handles stored in autoit ?

Edited by AutoIT Geek
Link to comment
Share on other sites

I think IsHWnd is what you'll need when using beta

from the help file

IsHWnd

Checks if a variable's base type is HWND.

IsHWnd ( variable )

Parameters

variable The variable/expression to check.

Return Value

Success: Returns 1.

Failure: Returns 0 if expression is not HWND type.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

thanx, but i dont want to check if it an HWND, i just want to know how it is stored.

Unimaginatively, it's stored as an HWND. Funny how that works, no?

You would do well to actually listen to (read) the responses people are giving you. You've been told IsHWND() is the function you need when using the beta. Also, in another thread, I've told you that HWND's changed between versions 3.1.1.65 and 3.1.1.66 so obviously there is going to be a difference in behavior between versions of AutoIt prior to that and after that. In other words, put two and two together and try to come up with four this time.

Link to comment
Share on other sites

VALIK, you are a wiseass, DONT YOU ?B):o

did you understand the problem i posted ?

" ==, Tests if two values are equal (case sensitive if used with strings)"

$Handle = WinGetHandle( WindowTitle )

IF $Handle == 0 do somthing <-- this dont work

IF $Handle == 00000000 do somthing <-- this dont work

IF $Handle == 0x0 do somthing <-- this dont work

IF $Handle == 0x00000000 do somthing <-- this dont work

IF $Handle == "00000000" do somthing <-- this dont work

IF $Handle == "0x00000000" do somthing <-- this dont work

IF $Handle == Hex( 0, 8 ) do somthing <--- this works in v3.1.1 but not in v3.1.1.90

IF Dec( $Handle ) == 0 do somthing <--- this somtimes works in v3.1.1 and in v3.1.1.90

I DONT WANT TO KNOW IF A VARIANT IS AN "HWND"

SINCE I USED A FUNCTION TO GET AN "HWND" --> WinGetHandle()

IE, I DONT WANT TO USE IsHWND()

CAN YOU UNDERSTAND THIS SIMPLE THING ?? NO ?? ??

your answer tells NOTHING to NO ONE --> HWNS IS HWND ---> AN APPLE IS AN APPLE

since you can NOT read between the lines, i'll make it easier for YOU,

what DATA TYPE is hwnd in auto it ? if it is different in LATEST betas, then IN WHAT FORM AUTOIT STORES IT ?

A STRING ? --> "ABCDEFGH" OR "0x1234ABCD"

A NUMBER ? --> 123 OR HEX 00000123 OR HEX 0x00000123

A DIFFERENT DATA TYPE ?

IF YOU DONT UNDERSTAND THIS, DONT ANSWER ME, BUT DO ( IF YOU CAN ) SUPPLY THE SOURCE CODE

FOR IsHWND() SO I CAN COMPARE IT TO WinGetHandle() AND SEE WHAT ARE THE DIFFRENCES.

IF IM WRONG OR MISSING SOMTHING OR JUST PLAIN IDIOT ( which might be ), BE KIND YOU ALL MIGHTY DEVELOPER LORD, AND POINT ME TO MY MISTAKE, THANK YOU.

Link to comment
Share on other sites

There is no need to post in all-caps. It is rude, annoying and immature. People have been very patient with you so far.

$Handle = WinGetHandle( WindowTitle )

IF $Handle == 0 do somthing <-- this dont work

IF $Handle == 00000000 do somthing <-- this dont work

IF $Handle == 0x0 do somthing <-- this dont work

IF $Handle == 0x00000000 do somthing <-- this dont work

IF $Handle == "00000000" do somthing <-- this dont work

IF $Handle == "0x00000000" do somthing <-- this dont work

Why on Earth are you comparing a handle to 0? If you want to know if WinGetHandle() was successful then check @Error:

$Handle = WinGetHandle('My window')
If @Error Then MsgBox(0x30, 'Error', 'Window not found.')

what DATA TYPE is hwnd in auto it ? if it is different in LATEST betas, then IN WHAT FORM AUTOIT STORES IT ?

In the latest betas, handles are stored in their own data type called HWnds. This is why an IsHWnd() function exists, just like IsNumber() and IsString() exist for numbers and strings.

Perhaps the HWnd data type is similar to the number data type because an HWnd can be viewed as a number, but they are different. This has already been mentioned.

If this doesn't answer your (very unclear) question then take a deep breath and try again. Give examples of code; explain what you're trying to achieve; show some more courtesy and we'll do our best to help you.

Edited by LxP
Link to comment
Share on other sites

Could you give a complete code example that shows the issue? I'm not exactly sure what the problem is. In other words, it seems that there should already be a workaround for most HWND-related programming problems in AutoIt.....

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

@ERROR works only in internal AutoIT functions, i wrote some UDF's of my own to manipulate handles

and that is why i check if handle is zero

since handles are stored differently in autoit, i get errors in my code and that is why i want to know how handles are stored, in what form, so i can interface my code with that

IsHWND() is an internal BOOLEAN autoit function which check an internal autoit data type

in Win API, handles are represented as hex numbers of "unsigned int"

in autoit, handles are not strings nor numbers,fine, so what are thay ? how are thay stored ?

Link to comment
Share on other sites

$Handle = WinGetHandle( WindowTitle )

IF $Handle == 0 do somthing <-- this dont work

IF $Handle == 00000000 do somthing <-- this dont work

IF $Handle == 0x0 do somthing <-- this dont work

IF $Handle == 0x00000000 do somthing <-- this dont work

IF $Handle == "00000000" do somthing <-- this dont work

IF $Handle == "0x00000000" do somthing <-- this dont work

You are comparing $Handle to numbers and strings, neither of which are HWnds. That is why they don't evaluate to true.

Perhaps you're looking for a way to write a hard-coded value in a script and have it treated as an HWnd. You would use the HWnd() function for this. I don't understand why you'd want to hard-code an HWnd value though, considering that they are volatile values.

IF $Handle == Hex( 0, 8 ) do somthing <--- this works in v3.1.1 but not in v3.1.1.90

In v3.1.1 handles were stored as plain numbers; in v3.1.1.90 they are not.

IF Dec( $Handle ) == 0 do somthing <--- this somtimes works in v3.1.1 and in v3.1.1.90

When WinGetHandle() fails, it returns an empty string. Dec('') gives 0. This is why this sometimes works -- it will work whenever a valid handle isn't returned by WinGetHandle().

I hope I've been somewhat useful to you; don't break my heart now and flame me with all-caps. B)

Link to comment
Share on other sites

@ERROR works only in internal AutoIT functions, i wrote some UDF's of my own to manipulate handles

and that is why i check if handle is zero

You can write UDFs that set @Error. Please refer to SetError() in the help file.

since handles are stored differently in autoit, i get errors in my code and that is why i want to know how handles are stored, in what form, so i can interface my code with that

Please show a complete code segment as an example, otherwise no one will be able to help you.

in autoit, handles are not strings nor numbers,fine, so what are thay ? how are thay stored ?

I thought that this has been answered already but I'll try another approach.

My guess is that internally they are stored as numbers, however they have an extra flag added to them that tells AutoIt not to treat them like a standard number, or to let the script see them as a standard number. As a non-developer I cannot tell you why things are done this way; as a heavy AutoIt scripter however, I can (and am more than happy to) tell you how to work around it if you supply me with the right information.

Edited by LxP
Link to comment
Share on other sites

Sure, heres a code

-----------------------------------------------------------------

$GW_CHILD = 5

$Result = DllCall( "USER32.DLL", "hwnd", "GetWindow", "hwnd", $Handle, "int", $GW_CHILD )

If $Result[ 0 ] == ( what ever i put here gives me crap )

-----------------------------------------------------------------

i want to check directly if i got a valid result,

Link to comment
Share on other sites

Okay, IsHWnd() is indeed useless for you because even if GetWindow returns NULL, AutoIt typecasts it to an HWnd because of the second argument to DLLCall().

I am able to do this with no problems under v3.1.1.91:

Local Const $GW_CHILD = 5

Local $Handle = WinGetHandle('Calculator')
Local $Ret = DLLCall('User32', 'HWnd', 'GetWindow', 'HWnd', $Handle, 'Int', $GW_CHILD)
MsgBox(0x40, 'Was a handle returned?', $Ret[0] <> 0); Displays True/1 or False/0

This code also works for v3.1.1 if you change the first 'HWnd' in DLLCall() to 'Int'. (Edit: That's a lie; you don't need to change it.)

I understand that you claimed to have problems with this in your first post; please try it again and let us know of any cases where the above code fails.

Edited by LxP
Link to comment
Share on other sites

-------------------------

Local Const $GW_CHILD = 5

Local $Handle = WinGetHandle('Calculator')

Local $Ret = DLLCall('User32', 'HWnd', 'GetWindow', 'HWnd', $Handle, 'Int', $GW_CHILD)

MsgBox(0x40, 'Was a handle returned?', $Ret[0] <> 0); Displays True/1 or False/0

---------------------------

works in 3.1.1 EVEN if i dont change 'HWnd' to 'int' , BUT, since in autoit, handles are NOT numbers,

and you check against a ZERO which IS a number, how can you do this ?

Link to comment
Share on other sites

I suppose that since you are asking to compare it with a number (0), AutoIt is forced to also treat the HWnd as a number during the comparison. I can't really say any more than that as an end-user with no understanding of AutoIt's internals.

I've just discovered that you can do this with the beta, which makes sense if you think about it:

MsgBox(0x40, 'True = 0', True = 0)
MsgBox(0x40, 'False = 0', False = 0)
MsgBox(0x40, 'True = 1', True = 1)
MsgBox(0x40, 'False = 1', False = 1)

The help file states however that if you attempt to compare a string with a number, the string will be treated as 0.

Link to comment
Share on other sites

LxP, you brainstormed me, :graduated::):D

ok, hers a new discovery, maybe I AM an idiot or this is a flaw in AutoIT

----------------------------------------------------------------------------------

Local $Handle = WinGetHandle('Calculator')

MsgBox( 0, '', $Handle ) <-- in 3.1.1 you get 1234ABCD, in 3.1.1.91 you get 0x1234ABCD

now, copy the string you got and put it here insted of "040e0912" and run it again

If $Handle == "040e0912" Then MsgBox( 0, "", "Lower Case" ) <-- this dont work

If $Handle == "040E0912" Then MsgBox( 0, "", "Upper Case" ) <-- this works

this suggests that handles are stored as strings, no ?

now do this

MsgBox( 0, '', IsString( $Handle ) ) <--- in both 3.1.1 and 3.1.1.9 you get 0, WTF ?

now, if you close 'Calculator' and do this

If $Handle == "" Then MsgBox( 0, "", "Empty String" ) this works

--------------------------------------------------------------------------------------------

isnt this confusing ? B):o

Edited by AutoIT Geek
Link to comment
Share on other sites

I'll try to explain what (I believe) is happening here.

Local $Handle = WinGetHandle('Calculator')

In v3.1.1, WinGetHandle() returns a string representing the handle (note that it uses uppercase letters when letters are needed). In v3.1.1.91, an actual HWnd data type is returned (which appears to really just be a number).

Local $Handle = MsgBox( 0, '', $Handle ) <-- in 3.1.1 you get 1234ABCD, in 3.1.1.91 you get 0x1234ABCD

Here AutoIt is being requested to display the content of the variable. For v3.1.1 this is a string, so there is no trouble. For v3.1.1.91, a representation must be chosen to display the data; the developers have decided that hexadecimal is best for this.

now, copy the string you got and put it here insted of "040e0912" and run it again

If $Handle == "040e0912" Then MsgBox( 0, "", "Lower Case" ) <-- this dont work

If $Handle == "040E0912" Then MsgBox( 0, "", "Upper Case" ) <-- this works

this suggests that handles are stored as strings, no ?

Yes; for v3.1.1 this is definitely the case as stated in the help file. I found that the code below will work in the beta, which I didn't expect:

Local $Handle = WinGetHandle('Calculator')
If $Handle = '0x00B204CA' Then MsgBox(0, '', $Handle)

now do this

MsgBox( 0, '', IsString( $Handle ) ) <--- in both 3.1.1 and 3.1.1.9 you get 0, WTF ?

This is the expected result for v3.1.1.91, however I don't understand why this happens for v3.1.1. The help file claims that WinGetHandle() will always return a string. Perhaps this was a v3.1.1 bug.

now, if you close 'Calculator' and do this

If $Handle == "" Then MsgBox( 0, "", "Empty String" ) this works

This is expected behaviour for both v3.1.1 and v3.1.1.91 as WinGetHandle() returns an empty string when it cannot find a matching window. Edited by LxP
Link to comment
Share on other sites

OK, LxB, HWND's are stored as strings since this is the way autoit treats them

in v3.1.1, thay are in this format --> '1234ABCD' <-- all upper case

in v3.1.1.91, thay are in this format --> '0x1234ABCD' <-- all upper case

in case of failure, thay are stored as empty string, ie, ""

a DLLCALL that returns an HWND, returns a string in the above format, BUT,

in case of failure, it is not an empty string, ie, "00000000" in v3.1.1 and "0x00000000" in 3.1.1.91

mystery SOLVED,

now, the question is, why to make a special container for HWND's ?

why not treat HWND's as plain hex numbers ? life would be much simpler that way, no ?

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...