AutoHotkey Community

It is currently May 26th, 2012, 3:26 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: July 22nd, 2008, 3:31 pm 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
Image

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2008, 8:21 pm 
Offline

Joined: May 17th, 2007, 6:03 pm
Posts: 391
Location: Titan
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 :shock: . Not very useful (maybe scroll here can be in certain situations) but good to know anyway.
________
VAPORIZER SHOP


Last edited by lilalurl.T32 on February 11th, 2011, 9:38 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2008, 12:18 pm 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2008, 1:19 pm 
Offline

Joined: May 17th, 2007, 6:03 pm
Posts: 391
Location: Titan
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).
________
YAMAHA SRX440 HISTORY


Last edited by lilalurl.T32 on February 11th, 2011, 9:38 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2009, 1:13 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Many thanks, this is really great.

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2009, 10:23 pm 
Offline

Joined: May 15th, 2007, 8:59 pm
Posts: 169
Wonderful Script. I was recently looking to find a way to minimize a specific app to the tray. with a small modification of this script I was able to achieve this :D

Thanks again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2009, 11:33 pm 
Offline

Joined: March 11th, 2009, 11:23 pm
Posts: 1
Great creative stuff, worked fine on my xp

Just tried it in windows 7 beta.
It only seems to work stable on windows that are not in focus.
If i try to use these functions long enough on the window in focus it sometimes work.
And i know its beta so i cant except anything to work, but lets prepare for the future :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 15 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