Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Make new windows open on screen with mouse pointer


  • Please log in to reply
No replies to this topic
dragonhelios
  • New members
  • 1 posts
  • Last active: Aug 11 2015 09:29 AM
  • Joined: 11 Aug 2015

Original thread: http://www.autohotke...inter-is/page-0

 

With some tweaks to akbars' post I was able to generate a script that opens newly launched windows and dialog boxes on the screen that has the mouse pointer:

 

#Persistent
SetBatchLines, -1
Process, Priority,, High


Gui +LastFound
hWnd := WinExist()


DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return


ShellMessage( wParam,lParam ) {
  If ( wParam = 1 ) ;  HSHELL_WINDOWCREATED := 1
     {
       Sleep, 10
       MouseGetPos, X, Y   ; get mouse location 
       WinGetTitle, Title, ahk_id %lParam%
       WinGet, maximized, MinMax, %title%


       ; Mouse screen coords = mouse relative + win coords therefore..
       WinGetPos, xtemp, ytemp,,, A ; get active windows location


       ;; Calculate actual position
       ;; -16 on x and y pos allows you to doubleclick and close window(most of the time) 
       xpos:=X+xtemp - 16
       ypos:=Y+ytemp - 16
       if (maximized != 0)
       {
        WinRestore, %Title%
       }


       WinMove, %Title%, , %xpos%, %ypos%  ; move window to mouse
       if (maximized = 1) 
       { 
          WinMaximize, %title%
       }
       else if (maximized = -1)
      {
         WinMinimize, %title%
      }
     }
}

Edited by GeekDude, 11 August 2015 - 05:27 PM.
Added code box and link to original thread