Jump to content

How do you read a window handle from an INI file?


Recommended Posts

This seems really basic but I am having issues get this to work.

Run(@WindowsDir & "\notepad.exe")

Do
Until WinExists("Untitled - Notepad", "")

$handle = WinGetHandle("Untitled - Notepad", "")
IniWrite(@ScriptDir & "\test.ini", "handle_value", "handle", $handle)

$handle2 = IniRead(@ScriptDir & "\test.ini", "handle_value", "handle", "error")

;$handle and $handle2 seem to be the same
ConsoleWrite($handle & @CRLF)
ConsoleWrite($handle2 & @CRLF)

;WinClose($handle) ;does work
WinClose($handle2) ;does not work
Link to comment
Share on other sites

Windows handles change every time the program runs, so storing it is not a very good procedure. Just get the handle when you run the program and use that.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

IniRead() returns all values as strings so you need to use Hwnd() to convert it back to a handel

Run(@WindowsDir & "notepad.exe")

Do
Until WinExists("Untitled - Notepad", "")
$handle = WinGetHandle("Untitled - Notepad", "")
IniWrite(@ScriptDir & "test.ini", "handle_value", "handle", $handle)

$handle2 = HWND(IniRead(@ScriptDir & "test.ini", "handle_value", "handle", "error"))

;$handle and $handle2 seem to be the same
ConsoleWrite($handle & @CRLF)
ConsoleWrite($handle2 & @CRLF)
WinActivate($handle2)
WinClose($handle2) ;Now works

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Windows handles change every time the program runs, so storing it is not a very good procedure. Just get the handle when you run the program and use that.

I know it's not generally a good idea but I have a script that starts/runs several other scripts and then those scripts report back to the script that started them through an INI file....It basically gives me multi thread like results because I can have my program do more then one thing at the same time.

IniRead() returns all values as strings so you need to use Hwnd() to convert it back to a handel

Run(@WindowsDir & "\notepad.exe")

Do
Until WinExists("Untitled - Notepad", "")
$handle = WinGetHandle("Untitled - Notepad", "")
IniWrite(@ScriptDir & "\test.ini", "handle_value", "handle", $handle)

$handle2 = HWND(IniRead(@ScriptDir & "\test.ini", "handle_value", "handle", "error"))

;$handle and $handle2 seem to be the same
ConsoleWrite($handle & @CRLF)
ConsoleWrite($handle2 & @CRLF)
WinActivate($handle2)
WinClose($handle2) ;Now works

Thanks Bowmore.
Link to comment
Share on other sites

Just make sure that when your main script runs, it updates the INI file everytime with its new HWND.

Take into account if the main script crashes while you have other scripts running, have a way for the other scripts to re-read the INI file periodically to see if there's a change in the HWND.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

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...