AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

NCHITTEST Full Throttled - basic Window manipulations

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Tue Jul 22, 2008 3:31 pm    Post subject: NCHITTEST Full Throttled - basic Window manipulations Reply with quote



i just wanted to make something using WM_NCHITTEST.
if people finds it useful i might add Minimize to Tray feature later on the Minimize button and more.
notice that first 3 lines of NCHITTEST() function are made by Sean which is the heart of this script.
Thanks to Sean.

this script does not use global variables at all.
everything is in functions. so you can embed it to your personal script easily.

usage : see the pic
untold feature -> RButton on Menubar will move to center, CTRL+RButton with resize

Code:
; heresy
;
; Thanks to Sean for http://www.autohotkey.com/forum/viewtopic.php?t=22178#141704

#NoEnv
#NoTrayIcon
SetWinDelay, -1
CoordMode, Mouse, Screen
ToolTip("Script Started")
EmptyMem()

*~RButton::NCHITTEST()

NCHITTEST(){
    MouseGetPos, x, y, hwnd
    SendMessage, 0x84, 0, (x&0xFFFF) | (y&0xFFFF) << 16,, ahk_id %hwnd%
    RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" . ErrorLevel+2&0xFFFFFFFF . "}(?<AREA>\w+\b)", HT)
    ;if GetKeyState("Alt") reserved for winmove in dual monitor environment
    ;if GetKeyState("Shift") reserved
    ;if GetKeyState("LWin") reserved
    if htarea in CLIENT,CAPTION,SYSMENU,HSCROLL,VSCROLL,OBJECT,HELP,ERROR,TRANSPARENT,NOWHERE
        Return
    else if (GetKeyState("CTRL") && htarea="CLOSE"){
        ToolTip, Script will exit in 3 secs..
        Sleep, 3000
        Exitapp
    }
    else if (htarea="CLOSE"){
        WinGet, tVal, Transparent, ahk_id %hwnd%
        WinSet, Trans, % (tVal!=127) ? 127 : 255, ahk_id %hwnd%
    } else if (htarea="MAXBUTTON"){
        WinGet, aVal, ExStyle, ahk_id %hwnd%
        WinSet, AlwaysOnTop, % (aVal & 0x8) ? "Off" : "On", ahk_id %hwnd%
        ToolTip((aVal & 0x8) ? "Always On Top : Off" : "Always On Top : On")
    } else if (htarea="MINBUTTON")
        tooltip("reserved")
    else if (GetKeyState("CTRL") && htarea="TOPLEFT")
        SizeWin(hwnd, "LTOP")
    else if (htarea="TOPLEFT")
        MoveWin(hwnd)
    else if (GetKeyState("CTRL") && htarea="TOP")
        SizeWin(hwnd, "TOP")
    else if (htarea="TOP")
        MoveWin(hwnd, "U")
    else if (GetKeyState("CTRL") && htarea="TOPRIGHT")
        SizeWin(hwnd, "RTOP")
    else if (htarea="TOPRIGHT")
        MoveWin(hwnd, "RU")
    else if (GetKeyState("CTRL") && htarea="RIGHT")
        SizeWin(hwnd, "RIGHT")
    else if (htarea="RIGHT")
        MoveWin(hwnd, "R")
    else if (GetKeyState("CTRL") && (htarea="BOTTOMRIGHT" || A_Cursor="SizeNWSE"))
        SizeWin(hwnd, "RBOTTOM")
    else if (htarea="BOTTOMRIGHT" || A_Cursor="SizeNWSE")
        MoveWin(hwnd, "RB")
    else if (GetKeyState("CTRL") && htarea="BOTTOM")
        SizeWin(hwnd, "BOTTOM")
    else if (htarea="BOTTOM")
        MoveWin(hwnd, "B")
    else if (GetKeyState("CTRL") && htarea="BOTTOMLEFT")
        SizeWin(hwnd, "LBOTTOM")
    else if (htarea="BOTTOMLEFT")
        MoveWin(hwnd, "LB")
    else if (GetKeyState("CTRL") && htarea="LEFT")
        SizeWin(hwnd, "LEFT")
    else if (htarea="LEFT")
        MoveWin(hwnd, "L")
    else if (GetKeyState("CTRL") && htarea="MENU"){
        WinGet, MMState, MinMax, ahk_id %hwnd%
        if MMState=1
            WinRestore, ahk_id %hwnd%
        SizeWin(hwnd, "CENTER")
    } else if (htarea="MENU"){
        WinGet, MMState, MinMax, ahk_id %hwnd%
        if MMState=1
            WinRestore, ahk_id %hwnd%
        MoveWin(hwnd, "Center")
    }
}

MoveWin(wHwnd, Pos="LU"){
    WinGetPos,,, W, H, ahk_id %wHwnd%
    SysGet, m, MonitorWorkArea
    if (pos="LU")
        WinMove, ahk_id %wHwnd%,, 0, 0
    else if (pos="L")
        WinMove, ahk_id %wHwnd%,, 0, % (mBottom-H)//2
    else if (pos="LB")
        WinMove, ahk_id %wHwnd%,, 0, % mBottom-H
    else if (pos="B")
        WinMove, ahk_id %wHwnd%,, % (mRight-W)//2, % mBottom-H
    else if (pos="RB")
        WinMove, ahk_id %wHwnd%,, % mRight-W, % mBottom-H
    else if (pos="R")
        WinMove, ahk_id %wHwnd%,, % mRight-W, % (mBottom-H)//2
    else if (pos="RU")
        WinMove, ahk_id %wHwnd%,, % mRight-W, 0
    else if (pos="U")
        WinMove, ahk_id %wHwnd%,, % (mRight-W)//2, 0
    else if (pos="Center")
        WinMove, ahk_id %wHwnd%,, % (mRight-W)//2, % (mBottom-H)//2
}

SizeWin(wHwnd, Pos){
    WinGetPos,,, W, H, ahk_id %wHwnd%
    SysGet, m, MonitorWorkArea
    if (pos="TOP")
        WinMove, ahk_id %wHwnd%,, 0, 0, %mRight%, % mBottom//2
    else if (pos="LEFT")
        WinMove, ahk_id %wHwnd%,, 0, 0, % mRight//2, %mBottom%
    else if (pos="BOTTOM")
        WinMove, ahk_id %wHwnd%,, 0, % mBottom//2, %mRight%, % mBottom//2
    else if (pos="RIGHT")
        WinMove, ahk_id %wHwnd%,, % mRight//2, 0, % mRight//2, %mBottom%
    else if (pos="CENTER")
        WinMove, ahk_id %wHwnd%,, % (mRight//2)//2, % (mBottom//2)//2, % mRight//2, % mBottom//2
    else if (pos="LTOP")
        WinMove, ahk_id %wHwnd%,, 0, 0, % mRight//2, % mBottom//2
    else if (pos="LBOTTOM")
        WinMove, ahk_id %wHwnd%,, 0, % mBottom//2, % mRight//2, % mBottom//2
    else if (pos="RTOP")
        WinMove, ahk_id %wHwnd%,, % mRight//2, 0, % mRight//2, % mBottom//2
    else if (pos="RBOTTOM")
        WinMove, ahk_id %wHwnd%,, % mRight//2, % mBottom//2, % mRight//2, % mBottom//2
}

ToolTip(S, Seconds=2500, X="", Y="") {
    SetTimer, Off, %Seconds%
    ToolTip, %S%, %X%, %Y%
    Return
   
    Off:
    ToolTip
    SetTimer, Off, Off
    Return
}

EmptyMem(PID="AHK Rocks"){
    pid:=(pid="AHK Rocks") ? DllCall("GetCurrentProcessId") : pid
    h:=DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid)
    DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1)
    DllCall("CloseHandle", "Int", h)
}

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
lilalurl.T32



Joined: 17 May 2007
Posts: 41
Location: Titan

PostPosted: Tue Jul 22, 2008 8:21 pm    Post subject: Reply with quote

Nice idea and nice implementation (less than 150 lines and I believe it is quite easy to read without any documentation)

Binding functions to where right click doesn't usually have a function was very smart.

Ofc apps with custom menus/GUIs seem to be a problem (RButton on Menubar will move to center didn't work in Office apps, nothing worked for Winamp).

Min to tray would make sense but maybe you reserved the button for another use you already have in mind, as you seem to have for Alt, Shift and LWin.

PS; thanks to your script I have discovered that hscroll and vscroll have a right click menu Shocked . Not very useful (maybe scroll here can be in certain situations) but good to know anyway.
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Wed Jul 23, 2008 12:18 pm    Post subject: Reply with quote

Thanks for your feedback lilalurl
and yeah i've noticed that the HScroll / VScroll could be used as well but i couldn't have idea for that yet. it might be used as scrolling related feature as you said. also i was aware of that menubar issue so it might be changed to another later but it'll be kept as it is until i can get more intuitive interface for the centering feature. cause i would like to bind it to single RButton as same as other features. by the way. my idea for additional keys (alt,etc) was Process Priority/Affinity Mask set features but it seems these are not used often.
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
lilalurl.T32



Joined: 17 May 2007
Posts: 41
Location: Titan

PostPosted: Wed Jul 23, 2008 1:19 pm    Post subject: Reply with quote

heresy wrote:
and yeah i've noticed that the HScroll / VScroll could be used as well but i couldn't have idea for that yet. it might be used as scrolling related feature as you said.


Well, what I meant is that there is actually a native right click menu on scroll bars. But yes, it could be used for something else because what it offers right now I think is useless.
Maybe something to cycle between different scroll wheel speed (number of lines per scroll): slower than normal (1 line?), normal, faster than normal (for large documents).

heresy wrote:
by the way. my idea for additional keys (alt,etc) was Process Priority/Affinity Mask set features but it seems these are not used often.


Maybe because until now there have been no script to work with those with an easy interface Wink
I suppose that you got the idea because it might be useful for you. If so, do it your way.
As long as you document correctly your script people will be able to change what can be done and change to their heart content.
Thus don't mind posting here or commenting in your script whatever ideas you have had. Even if you don't use them, reading them can give ideas to others (the same way I discovered hscroll/vscroll were right-clickable).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group