Sign in to follow this  
Followers 0
DaleHohm

Window handle data type and HWND question

12 posts in this topic

Using COM, the InternetExplorer.Application object has an HWND property.

$o_object = ObjCreate("InternetExplorer.Application")
$IEhandle = $o_object.HWND ()

I want to be able to get this value and then use it in AutoIt functions like WinActivate etc.

Unfortunately, when I retrieve it with COM it comes back as an integer (e.g. 592114 and IsInt returns 1) and AutoIt represents handles as some sort of special datatype (IsInt returns 0) and I cannot use the value in these AutoIt functions.

Any suggestions for how I can turn the COM value into something that the AutoIt functions can use?

Thanks,

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hmm... Good question... I tried this:

$hwnd = WinGetHandle("Windows Media Player")
MsgBox(0, "WMP", $hwnd)
$o_object = ObjCreate("InternetExplorer.Application")
$IEhandle = Hex($o_object.HWND (), 8)
MsgBox(0, "IE", $IEhandle)
$title1 = WinGetTitle($hwnd)
MsgBox(0, "WMP", $title1)
$title2 = WinGetTitle($IEHandle)
MsgBox(0, "IE", $title2)

But the final $IEhandle returned 0...

Because it looks like the returns for hWnd's are Hex values... Anyone else wanna give it a shot?

EDIT: Couldn't find much here: http://msdn.microsoft.com/library/default....netexplorer.asp

Edited by layer

FootbaG

Share this post


Link to post
Share on other sites

Hmm, this is a good point.  Maybe ezztabi will get his wish about ToHandle() conversion functions after all...

<{POST_SNAPBACK}>

It would definitely help in some of my scripts.

I really would like this.

Share this post


Link to post
Share on other sites

Hmm, this is a good point.  Maybe ezztabi will get his wish about ToHandle() conversion functions after all...

<{POST_SNAPBACK}>

Thank you!!!!!!!!! :)

FootbaG

Share this post


Link to post
Share on other sites

This is a question of protocol...

Is this already considered to be a real feature request based on the discussion here (including Jon's reply)? It is certainly not a bug, but should it perhaps be moved to the V3 Idea Lab so that it doesn't get lost?

Thanks,

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Using COM, the InternetExplorer.Application object has an HWND property. 

$o_object = ObjCreate("InternetExplorer.Application")
$IEhandle = $o_object.HWND ()

I want to be able to get this value and then use it in AutoIt functions like WinActivate etc.

Unfortunately, when I retrieve it with COM it comes back as an integer (e.g. 592114 and IsInt returns 1) and AutoIt represents handles as some sort of special datatype (IsInt returns 0) and I cannot use the value in these AutoIt functions.

Any suggestions for how I can turn the COM value into something that the AutoIt functions can use?

Thanks,

Dale

Actually, I'll check with Sven. I would expect that code to return a native HWND type rather than a integer.

Share this post


Link to post
Share on other sites

Actually, I'll check with Sven.  I would expect that code to return a native HWND type rather than a integer.

<{POST_SNAPBACK}>

Jon,

COM doesn't know anything about HWNDs. It always returns an integer value in this case. There is no way to determine if it's actually a HWND (unless I do an 'IsHandler()' call on EVERY COM function, but that's what we call 'Spaghetti Programming' here).

Also: Isn't the purpose of AutoIt to be datatypeless where possible? So I propose it would be better to modify functions like WinGetTitle(), so it will check for you if you have passed it a valid HWND or not. In this way the user does not have to worry about whether he/she is handling with integers or HWNDs.

Regards,

-Sven

Share this post


Link to post
Share on other sites

Jon,

COM doesn't know anything about HWNDs.  It always returns an integer value in this case. There is no way to determine if it's actually a HWND (unless I do an 'IsHandler()' call on EVERY COM function, but that's what we call 'Spaghetti Programming' here).

Also: Isn't the purpose of AutoIt to be datatypeless where possible?  So I propose it would be better to modify functions like WinGetTitle(), so it will check for you if you have passed it a valid HWND or not. In this way the user does not have to worry about whether he/she is handling with integers or HWNDs.

Regards,

-Sven

Ah, that answers it then - i'd assumed that COM was returning a native HWND type and autoit was misinterpereting it.

int / HWND conversion is a bit weird - the compiler doesn't just let you cast and iirc I did some pretty weird stuff to make it work (in some of the WinWait conversion functions). Maybe I should modify the Win functions so that they try an automatic HWND conversion if passes an int.

Share this post


Link to post
Share on other sites

Gah, where are we discussing this at, the private thread or this one? I've stated in the other thread my reservations about automatically trying to cast int's to HWND. Let's talk about things there for now, two threads are confusing.

Share this post


Link to post
Share on other sites

Yeah! 3.1.1.66 adds the new HWnd function and it works beautifully.

This allows us to readily get a reference to a COM-created IE window that can be used in all of the traditional AutoIt functions:

$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$handle = HWnd($oIE.HWND)
WinFlash($handle)

Thanks all!

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Works like a charm!

Hmm, the first time I've seen someone use my function!!! w00000000000000000000000000t, I feel so cool now :dance:

:whistle:

The latest BETA (.66) looks so great :dance:

You made my day :">

Edited by layer

FootbaG

Share this post


Link to post
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
Sign in to follow this  
Followers 0