AutoHotkey Community

It is currently May 27th, 2012, 10:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: May 27th, 2009, 9:04 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Code:
#Persistent
SetTimer, chk, 50
return

chk:
If GetKeyState("Alt", "P") && GetKeyState("LButton", "P")
   PostMessage, 0xA1, 2,,, A
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject: One step further
PostPosted: June 5th, 2009, 6:21 pm 
Offline

Joined: June 5th, 2009, 6:19 pm
Posts: 7
This is my first post. I look forward to contributing and learning from the community!

I run 2 monitors. Sometimes a window is maximized in one monitor and I want to move it to the other monitor. It would be great if the script would also do the following:

1. Alt + Left Click the maximized window anywhere on the window (not just the title bar)
2. "Restore" the window
3. Allow for the dragging of the window without placing the cursor over the title bar (this is already done with the code)

Is this just an If statement that checks for whether the window is maximized? If it is, then it executes a different block of code.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2009, 9:19 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Here you are; it unpins the window allowing the drag (mouse cursor will be far off) and restores to maximized state when releasing left mouse button:
Code:
#Persistent
SetTimer, chk, 50
return

chk:
If GetKeyState("Alt", "P") && GetKeyState("LButton", "P")
   {
   WinGet, wstate, MinMax, A
   If wstate = 1
      {
      wasmax = 1
      PostMessage, 0x112, 0xF120,,, A   ; SC_RESTORE
      }
   PostMessage, 0xA1, 2,,, A
   }
If GetKeyState("Alt", "P") && !GetKeyState("LButton", "P") && wasmax
   {
   wasmax = 0
   PostMessage, 0x112, 0xF030,,, A   ; SC_MAXIMIZE
   }
return


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 7th, 2009, 10:43 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Here's an updated version with animation. Inspired by recent code by SKAN (thank you!). Enjoy!
Code:
; MoveIt - move windows with animation by ALT+LClick
; by Drugwash, June 7, 2009

#Persistent
DetectHiddenWindows, On
SysGet, mc, 80
if mc < 2, return
minW := 16 ; intermediary window size
VarSetCapacity(MI, 16*mc, 0)
hCB := RegisterCallback("MCB","", 4)
DllCall("EnumDisplayMonitors", UInt, NULL, UInt, NULL, UInt, hCB, UInt, 0)
SetTimer, move, 50
return

move:
If GetKeyState("Alt", "P") && GetKeyState("LButton", "P")
   {
   hWnd := WinExist("A")
   WinGet, wstate, MinMax, A
   If wstate = 1
      {
      wasmax = 1
      SendMessage, 0x112, 0xF120,,, A   ; SC_RESTORE
      }
   VarSetCapacity(Rect, 32, 0)
   DllCall("GetWindowRect", UInt, hWnd, UInt, &Rect) ; get current window position
   chMon := DllCall("MonitorFromRect", UInt, &Rect, UInt, 0x2) ; MONITOR_DEFAULTTONEAREST
   Loop, %mc%
      {
      if (chMon = hMon%A_Index%)
         {
         cMon := A_Index
         nMon := (A_Index = mc) ? "1" : A_Index + 1
         break
         }
      }
   aMon := (nMon = 1) ? nMon : cMon
   mw := NumGet(MI, 8+16*(aMon-1), "Int")
   mh := NumGet(MI, 12+16*(aMon-1), "Int")
   intl := mw - minW//2
   intt := mh//2 - minW//2
   intr := intl + minW
   intb := intt + minW
   newl := NumGet(Rect, 0, "Int") - NumGet(MI, 0+16*(cMon-1), "Int") + NumGet(MI, 0+16*(nMon-1), "Int")
   newt := NumGet(Rect, 4, "Int") - NumGet(MI, 4+16*(cMon-1), "Int") + NumGet(MI, 4+16*(nMon-1), "Int")
   newr := NumGet(Rect, 8, "Int") - NumGet(MI, 0+16*(cMon-1), "Int") + NumGet(MI, 0+16*(nMon-1), "Int")
   newb := NumGet(Rect, 12, "Int") - NumGet(MI, 4+16*(cMon-1), "Int") + NumGet(MI, 4+16*(nMon-1), "Int")
   NumPut(intl, Rect, 16, "Int")
   NumPut(intt, Rect, 20, "Int")
   NumPut(intr, Rect, 24, "Int")
   NumPut(intb, Rect, 28, "Int")
   WinHide, ahk_id %hWnd%
   DllCall("DrawAnimatedRects", UInt, hwnd, Int, 3, UInt, &Rect, UInt, &Rect+16) ; IDANI_CAPTION
   DllCall("RtlMoveMemory", UInt, &Rect, UInt, &Rect+16, UInt, 16)
   NumPut(newl, Rect, 16, "Int")
   NumPut(newt, Rect, 20, "Int")
   NumPut(newr, Rect, 24, "Int")
   NumPut(newb, Rect, 28, "Int")
   DllCall("DrawAnimatedRects", UInt, hwnd, Int, IDANI_CAPTION, UInt, &Rect, UInt, &Rect+16)
   WinMove, ahk_id %hWnd%,, %newl%, %newt%
   WinShow, ahk_id %hWnd%
   }
If wasmax && (!GetKeyState("Alt", "P") || !GetKeyState("LButton", "P"))
   {
   wasmax = 0
   SendMessage, 0x112, 0xF030,,, A   ; SC_MAXIMIZE
   }
return

MCB(hM, hDC, pRect, data)
{
global MI, hMon1, hMon2, hMon3, hMon4
static idx=1
hMon%idx% := hM
DllCall("RtlMoveMemory", UInt, &MI+16*(idx-1), UInt, pRect, UInt, 16)
idx++
return True
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Using WM_NCLBUTTONDOWN
PostPosted: June 9th, 2009, 3:21 pm 
Here's another method that just tell the window it's title bar is being dragged by sending it the WM_NCLBUTTONDOWN message.

Quote:
~!LButton::
{
MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 2

Control, Disable, , , ahk_id %OutputVarControl%
Result := DllCall("ReleaseCapture")
Control, Enable, , , ahk_id %OutputVarControl%
SendMessage, 161, 2, 0, , ahk_id %OutputVarWin%

return
}


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group