Jump to content

passing window handle between scripts

Recommended Posts

I have a script which provides some hotkeys to jump to various apps people are running on their desktop. I've already got hold of the window handles on creation, so I can jump to them when someone types in the correct hotkey sequence.

Now I'd like to do the same when someone clicks on a section of a powerpoint slide. I can see how to run a script to do the same, but what is the best way of passing the handle from the main script to these others that may run at any time?

I'm sort of thinking saving the handle in an environment variable and then reading that back and using it, but I'm very open to other ideas

Link to post
Share on other sites

I'm sort of thinking saving the handle in an environment variable and then reading that back and using it, but I'm very open to other ideas

This question has been asked in the forum. Just search for "+environment +parameter". There are at least three ways to solve yout problem.

1.) Write them to a config / INI file

2.) Write them to the registry

3.) Use environement variables

I'd prefer the registry.



__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to post
Share on other sites

Thanks for the prompt response. I guess my question is more specifically to do with passing window handles between scripts. The docs say these handles are not strings or numbers. I have to use handles because the apps I use have the same window names and also because at various points the windows change their titles. So I've tried to write a reg variable out and back in but something seems to be happening to transform it. In the enclosed test sample shows what I mean

$Outlook = WinGetHandle("Inbox - Microsoft Outlook")

; Save handle so we can use it later

RegWrite ("HKEY_CURRENT_USER\SOFTWARE\Mine","Email","REG_SZ",$Outlook)

... later ...

msgbox (4096,"Handle is ", $Outlook)

$Outlook = RegRead("HKEY_CURRENT_USER\SOFTWARE\Mine","Email")

msgbox (4096,"Handle is ", $Outlook)

If $Outlook <> "" and winexists ($Outlook) Then

winactivate ($Outlook)


If I comment out the ReadReg, the fragment indeed activates my outlook window. Allow the ReadReg to run and it fails to find the window. Both msgboxes produce exacly the same value on inspection, so I'm thinking these special windows handles need special handling. I get the same results with REG_BINARY as well

So any thoughts on passing these handles between different scripts??

Link to post
Share on other sites

In recent betas, there is a new HWnd statement that converts a variant into an HWnd. I did a quick test and I think you should be able to convert your HWND to a string, store it in the registry or where ever, read it back and convert it back into an HWND.

If you original HWND value is stored in $hHwnd, then in the code below, $hHwnd and $hHwnd2 should be identical:

$sHwnd = String($hHwnd)
$hHwnd2 = HWnd($sHwnd)


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

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...