a_kungfu_mastah Posted September 10, 2015 Posted September 10, 2015 (edited) So I am making a little framework to setup my workspace from when i work at home, to when I go to the office and plug into my docking station. At the office I have 3 monitors plus the laptop monitor. So moving windows around is a key of the framework.First I will post the issue: I have a function to get the window handle from a string (in this example "Outlook" is the string I am using), and it has not failed to get the correct window handle.So I threw in a winActivate($window_handle) in to see if it was actually getting the right handle and operating on it, and it will pop outlook up just fine, but when it comes to move it, it wont budge. I have tried using$outlook_handle = get_win_handle_by_title("Notepad") move_win($outlook_handle, 0, 0) ; but this DOESNT work, only activates Outlook, curse you microsoft! $outlook_handle = get_win_handle_by_title("Outlook") move_win($outlook_handle, 0, 0)and that worked PERFECTLY, so I have no idea why the hell outlook wont move. Someone please help?And thank you in advance, this is my first time posting here after using autoit for many years now, so I hope I gave enough information, forgot to put system info, thats below:OS: Windows 7 x64 enterpriseOutlook 2013If you would like anything else, output from the autoit window info tool, whatever you want. Just let me know and I'll get it for you.Thanks again! ALSO IF ANYONE WANTS TO USE ANY OF THIS CODE, YOU ARE MORE THAN WELCOME TO USE IT FREELY AS YOU WISH Also including debug function to be thorough, but I dont see how it would affect anything, as you would see in the function, very simpleDEBUG FUNCTION:; yeah i know i should be checking to make sure $astring is actually a string type ; but that comes once i get some things working, just a pof framework for now. ; thanks again! ;_____________________________________________________________________ ;====================================================================/ ;=======--- debug($astring) ---=====================================/ ;==================================================================/ ;== takes $astring and writes it with a debug header to the ==| ;== console. output is in the form of "[debug] $astring" ==| ;==-------------------------------------------------------------==| ;== return values: ==| ;== success: True ==| ;== failure: False, but this should never happen ==| ;_________________________________________________________________/ func debug($astring) ; create header local $header = "[debug]" ; create output string, putting a carriage return at the end $astring = $header&" "&$astring&@CRLF ; print the output string $astring to the console consoleWrite($astring) ; return true return True endFuncThe functions code I am using:MAIN: ; i KNOW it is getting the right handle because a simple winActivate($outlook_handle) works perfectly $outlook_handle = get_win_handle_by_title("Outlook") ; i have the winActivate($window_handle) in the move_win function to test it was ; using the window handle right, and it DOES activate it correctly. it just doesnt move it AT ALL move_win($outlook_handle, 0, 0) FUNCTION: ; final function has lines 31 and 32 removed, they were put in for testing. ;_____________________________________________________________________ ;====================================================================/ ;========--- move_win($window_handle, $x, $y) ---===================/ ;==================================================================/ ;== move the window with $window_handle to the specified $x and ==| ;== $y coords. then check the position of $window_handle and ==| ;== confirm that is has successfully been moved there. ==| ;==-------------------------------------------------------------==| ;== return values: ==| ;== success: True ==| ;== failure: False ==| ;________________________________________________________________/ func move_win($window_handle, $x, $y) ; print header debug("[+] executing move_win("&$window_handle&', '&$x&', '&$y&')') ; WinMove($hWnd, "", 0, 0, 200, 200) ; move the window with $window_handle to $x, $y debug("activating window handle: ["&$window_handle&']') winActivate($window_handle) sleep(1000) local $result = winMove($window_handle, "", $x, $x) debug("winMove result: ["&$result&']') endFunc Edited September 10, 2015 by a_kungfu_mastah
computergroove Posted September 11, 2015 Posted September 11, 2015 Try winmove instead of move_win - https://www.autoitscript.com/autoit3/docs/functions/WinMove.htmYour syntax looks wrong. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
Malkey Posted September 11, 2015 Posted September 11, 2015 To use this example, hold down the Ctrl key with the left mouse button to drag window that the mouse is over.#include <Misc.au3> Local $hWin, $aMousePos1, $aMousePos2, $aWinPos1 HotKeySet("{ESC}", "Terminate") While 1 Sleep(10) If _IsPressed("01") And _IsPressed("11") Then ; Hold down Ctrl key with left mouse button to drag window that the mouse is over $hWin = WinGetHandle("") $aWinPos1 = WinGetPos($hWin) $aMousePos1 = MouseGetPos() While (_IsPressed("01") And _IsPressed("11")) Sleep(10) $aMousePos2 = MouseGetPos() WinMove($hWin, "", $aWinPos1[0] + ($aMousePos2[0] - $aMousePos1[0]), $aWinPos1[1] + ($aMousePos2[1] - $aMousePos1[1])) WEnd EndIf WEnd Func Terminate() Exit EndFunc ;==>Terminate
l3ill Posted September 11, 2015 Posted September 11, 2015 OP was using WinMove, but its quoted out ??Maybe this is the problem? My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
Surya Posted September 11, 2015 Posted September 11, 2015 Try this : (CODE UNTESTED)winmove(_GetHwndFromPID(ProcessExists("outlook.exe")),"",30,20) ;change outlook to the process name Func _GetHwndFromPID($PID) $hWnd = 0 $stPID = DllStructCreate("int") Do $winlist2 = WinList() For $i = 1 To $winlist2[0][0] If $winlist2[$i][0] <> "" Then DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID)) If DllStructGetData($stPID, 1) = $PID Then $hWnd = $winlist2[$i][1] ExitLoop EndIf EndIf Next Sleep(100) Until $hWnd <> 0 Return $hWnd EndFunc ;==>_GetHwndFromPIDthe modification is it is more precise No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)
a_kungfu_mastah Posted September 12, 2015 Author Posted September 12, 2015 Thank you for the feedback, but I think some of you may have missed the point a bit.The main point is the top piece of code. When I do it with "Notepad" it works flawlessly, everytime. Window activates, and moves to 0,0. I have also tried other windows as well, firefox, chrome, wireshark, etc. Works flawlessly. There is something about Outlook that is giving it trouble.$outlook_handle = get_win_handle_by_title("Notepad") move_win($outlook_handle, 0, 0) ; but this DOESNT work, only activates Outlook, curse you microsoft! $outlook_handle = get_win_handle_by_title("Outlook") move_win($outlook_handle, 0, 0)The framework is designed mainly to set up my workspace instantly, or have a window get sent to mon0 or mon1 instantly and full screened, with a hotkey system I havent decided on yet. And probably some other stuff I havent thought of yet that would be handy. Like setting up a clusterssh type session on one monitor. I will address the replies in order because thats easier.computergroove: move_win is MY function, not an internal autoit function, the problem is that outlook refuses to move, yet I can activate it with the window handle just fine. It is the base of a framework.malkey: nice piece of code, but wouldn't that not just drag the window around my mouse, similar to left clicking the titlebar and moving it, except I could do it anywhere on the window? If so, it is quite clever, but not what I am trying to do, but the basic theory could be very useful. I could use it to select the window I want moved to monX. If you dont mind I would like to use some of that code.l3ill: The commented line where I was originally moving the window, but since it was not working for outlook I added it in a different way to debug it. But its actually a bit funny because if you look right above where your cursor is in your screenshot. You see me calling WinMove(), except I am setting it to a variable. According to the documentation for WinMove(), if successfull, it will return the windows handle, and if it fails it returns 0. Which is why I have the var $results set to the WinMove() function.Surya: that is a very interesting idea by using the PID instead of the window handle. That may give different results. I will have to investigate into that. But what confuses me the most, is what I said to l3ill. I am assigning WinMove() to a variable and outputting it to see if its successful or failing. And it IS returning the window handle and not 0, which is what is driving me crazy. Outlook is the only program I have encountered that the function will not work with, and I have no idea why. Is there some special window variable where it can be prevented from being moved?I have tried WinMove() using window handle, text, class, etc and the damn thing wont budge. I've been using autoit for probably 10 years now, and I have done some pretty elaborate things with it, and I have not had anything this much of a pain in the ass.I just finished a 36 hour workday because we have an issue in a customers production environment. But tomorrow I will upload everything from the autoit window info tool and hopefully someone will see something that is out of the ordinary. Again thank you for the useful replies. They are very much appreciated. I need sleep now.
philkryder Posted September 12, 2015 Posted September 12, 2015 (edited) Did the get handle actually succede. What do error diags show afterget_win_handle_by_title("Outlook")Similarly, what did you get for diags after the winmove?also, did you intend to use $x, $x rather that $y?local $result = winMove($window_handle, "", $x, $x) Edited September 12, 2015 by philkryder
a_kungfu_mastah Posted September 14, 2015 Author Posted September 14, 2015 1) I am quite certain get_win_handle_by_title() is getting the correct handle. The simple test for making sure it was getting it correctly was putting Outlook into the background (unmaximized fyi) and running the following:$outlook_handle = get_win_handle_by_title("Outlook") winActivate($outlook_handle)Which activates Outlook and brings it to the front, just as it should. 2) No I did not intend that, that was a typo I didn't notice because I was using 0,0 as the place to move it. That has now been corrected. Thank you for noticing that as well. Although since I was using 0,0 it should still have moved it to 0,0. SOLUTION:After investigating a bit I found what was happening. It seems Outlook had some sort of what I am going to call a "subwindow", with its own handle and shit, but contained within the actual Outlook window. Details below.get_win_handle_by_title() was actually the culprit. It WAS getting a handle from outlook, and it apparently has something to do with Outlook, because activating it brings Outlook to focus. But apparently Outlook for god only knows why, runs 2 processes. I wasn't keep an eye on my debug output. Outlook had something with a title like "Outlook blah blah Help (F1)" open, but wasn't visible or was contained inside the main Outlook window, that "subwindow" could not be moved. When I changed it to "Inbox" it worked perfectly.I will have to add the ability to send a pattern to get_win_handle_by_title(), to make sure I can avoid that crap in the future. If I paid attention to my debug functions output I probably wouldn't have gotten stuck, but I did pick up some tricks like the get handle by PID which could be very useful. Thank you for all the help, it is very much appreciated.
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