Area751 Posted May 5, 2008 Share Posted May 5, 2008 I feel very stupid asking this... but I could not get this code to work in AutoIt (not AutoitX). $handle = 0x001F0980 WinClose($handle)oÝ÷ Øh¢Gºaz§vW°ØVwhÀß a¢è!¶«ªl¶¢¹¶íèZÙ^Ì+¢x kç`zÛbayÊ+ç-~æjÜ"¶®¶sb6æ6ÇVFRfÇC´FV'VræS2fwC°¥ôFV'Vu6WGWgV÷C¶FV'VrgV÷C² ¢b33c¶æFÆRÒvävWDæFÆRVçFFÆVBÒæ÷FWB¥ôFV'Vt÷WBb33c¶æFÆRÂG'VR but the debug window always returned null for $handle. What am I doing wrong? What I would like to do is close a handle with AutoItX from a Csharp application I'm writing. But AutoItX doesn't accept handles as input for WinClose() , so my idea was to write a very small executable with AutoIt that accepts a handle as parameter when it's run. Then it closes the window... Link to comment Share on other sites More sharing options...
MikeP Posted May 5, 2008 Share Posted May 5, 2008 (edited) Handles are a special type of variable.. you can't just use the string (or hexvalue in your case since you didn't put " ") and use them in functions needing those handles... To get a window handle .. use WinGetHandle and it will return what you need. Opt("WinTitleMatchMode", 2) $hCsharpwin = WinGetHandle("Csharp") WinClose($hCsharpwin) mode 2 : allow to use substring to find window titles that script will work but.. is actually awful.. why mixing handles and titles when you can just do that : WinClose("Csharp") ? I'm a bit confused. By the way if the window you're closing is responding with a message (like "Do you want to save before closing") and you would want to force the closure without that message.. use WinKill. Edited May 5, 2008 by MikeP Link to comment Share on other sites More sharing options...
Area751 Posted May 5, 2008 Author Share Posted May 5, 2008 that script will work but.. is actually awful.. why mixing handles and titles when you can just do that : WinClose("Csharp") ? I'm a bit confused.The reason I want to use handles instead of titles is that I will have multiple windows having the same title. Link to comment Share on other sites More sharing options...
weaponx Posted May 5, 2008 Share Posted May 5, 2008 The reason I want to use handles instead of titles is that I will have multiple windows having the same title.You can use handles but they have to be returned by WinGetHandle(). You can use the instance number to refer to multiple windows with the same title.Where are you getting the handles from? Link to comment Share on other sites More sharing options...
MikeP Posted May 5, 2008 Share Posted May 5, 2008 You can use handles but they have to be returned by WinGetHandle(). You can use the instance number to refer to multiple windows with the same title.Where are you getting the handles from?No idea why but I tried testing and launched twice a software called WinHTTrack .. both windows got the same title, different handles of course.. and no instance number. Hard to differentiate in that case I had to select the correct window among 3 or 4 with same titles too on another script and I created a GUI with windows list .. what I was doing was selecting it, activating it and clicking on a button in the GUI to launch my script when I had the correct window but it needed my actions.. doing it silently is still a mistery. Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 5, 2008 Share Posted May 5, 2008 No idea why but I tried testing and launched twice a software called WinHTTrack .. both windows got the same title, different handles of course.. and no instance number. Hard to differentiate in that case I had to select the correct window among 3 or 4 with same titles too on another script and I created a GUI with windows list .. what I was doing was selecting it, activating it and clicking on a button in the GUI to launch my script when I had the correct window but it needed my actions.. doing it silently is still a mistery.Use WinList() to get an array of all matching windows, then use the handles to find the exact one you want (by text, controls, position, whatever). Once you have the handle, you are good to go. Each time you launch the app, the handles will be different, but they last the life of the window. So hard-coding a handle wouldn't make sense even if you could. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
MikeP Posted May 5, 2008 Share Posted May 5, 2008 "I created a GUI with windows list (...)" ... I've used WinList() for that of course... but I needed to manually select the window to get the right handle.. in other words, no way to get which window was launched first when there are more than one... i.e is it possible to get the process creation timestamp.. Link to comment Share on other sites More sharing options...
weaponx Posted May 5, 2008 Share Posted May 5, 2008 ProcessStartDateTime Link to comment Share on other sites More sharing options...
MikeP Posted May 5, 2008 Share Posted May 5, 2008 What I would like to do is close a handle with AutoItX from a Csharp application I'm writing. But AutoItX doesn't accept handles as input for WinClose() , so my idea was to write a very small executable with AutoIt that accepts a handle as parameter when it's run. Then it closes the window...Your problem is by using WinList you would get several handles with the same window title.. and with WinGetHandle you get only one (first or last..I don't know) .. what you want is closing the right window. Your windows CAN'T be identical 100% .. positionning, text, level (even if you have 2 windows with the same text and state and positionning.. they can't be at the same level..one would be over the other). So yeah..what you're lookin for is to get such relevant infos.. with WinGetHandle you have the attribute ", text" to find a window with a certain text.. so if you can put an hint text for autoit in your windows..you're saved. Other than that .. you would have to dig the MSDN to find a function giving the window's current level... Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 5, 2008 Share Posted May 5, 2008 (edited) "I created a GUI with windows list (...)" ... I've used WinList() for that of course... but I needed to manually select the window to get the right handle.. in other words, no way to get which window was launched first when there are more than one... i.e is it possible to get the process creation timestamp.. For each window handle in your WinList array, do WinGetProcess($avWinList[$n][1]) to get the PID. There is a _ProcessListProperties() UDF to list lots of info about the process, but start time is not one of them. Doesn't mean it can't be done, though. Edit: This functionality looks useful for me too (and weaponx was poking me in the ribs), so I updated _ProcessListProperties() to include the translated .CreationDate property: Updated _ProcessListProperties() UDF Cheers! Edit: The function _ProcessListProperties() has a new home in Example Scripts. Please take criticism/suggestions to that topic. Edited May 5, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
MikeP Posted May 5, 2008 Share Posted May 5, 2008 (edited) ProcessStartDateTimemmm weaponx .. do you have a function for *insert anything* ? Yeah I think you do Thx u rocknice UDF too Psalty ! >> saved ! Edited May 5, 2008 by MikeP Link to comment Share on other sites More sharing options...
Area751 Posted May 6, 2008 Author Share Posted May 6, 2008 (edited) Thanks for all your help. This is a really supportive forum. Sadly... I couldn't solve the problem with AutoIt. I used Win32 API in Csharp and now the problem is solved. Here is the pseudo code, if anyone is maybe interested in the future: int SC_CLOSE = 0xF060; // constant int handle = 0x00030354; // the HEX handle of the window to close (can be decimal format also) IntPtr hWndtemp = new IntPtr(handle); Win32.PostMessage(hWndtemp,(int)Win32.WindowMessages.WM_SYSCOMMAND,(IntPtr)SC_CLOSE,IntPtr.Zero); Edited May 6, 2008 by Area751 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 6, 2008 Moderators Share Posted May 6, 2008 Thanks for all your help. This is a really supportive forum. Sadly... I couldn't solve the problem with AutoIt. I used Win32 API in Csharp and now the problem is solved. Here is the pseudo code, if anyone is maybe interested in the future: int SC_CLOSE = 0xF060; // constant int handle = 0x00030354; // the HEX handle of the window to close (can be decimal format also) IntPtr hWndtemp = new IntPtr(handle); Win32.PostMessage(hWndtemp,(int)Win32.WindowMessages.WM_SYSCOMMAND,(IntPtr)SC_CLOSE,IntPtr.Zero);$handle = 0x001F0980 WinClose($handle) Hmm... $handle = 0x001F0980 If IsHwnd($handle) = 0 Then $handle = HWND($handle) If WinClose($handle) = 0 Then WinKill($handle) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 6, 2008 Share Posted May 6, 2008 Hmm... $handle = 0x001F0980 If IsHwnd($handle) = 0 Then $handle = HWND($handle) If WinClose($handle) = 0 Then WinKill($handle) Nice call, SmOke_N. I think I had seen HWND() before, but never having needed it, it never occurred to me. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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