Jump to content

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

Window Management Functions


  • Please log in to reply
2 replies to this topic
savage
  • Members
  • 207 posts
  • Last active: Jul 03 2008 03:12 AM
  • Joined: 02 Jul 2004
I put together a small library of ahk functions for window management. This is likely to grow as I need more stuff.

Right now there's functions to roll/unroll windows, check if the mouse is in the caption, and toggle transparency.

Here's the thing:

;_____Window Management Functions
;_____A couple of useful functions for managing windows, and the variables they need to work
;_____Include this file in your autoexecute section and you're ready to go :)

;_____Initialize variables for window rolling
RolledWindowIds = 
SysGet, CaptionHeight, 4

;any window you want to ignore rolling, such as a desktop class, put here, seperated by spaces
RollExcludeClasses = DesktopBackgroundClass

;_____rolls window under cursor if its unrolled, unrolls if rolled
ToggleWindowRoll(hwnd)
{
    global
    IfInString, RolledWindowIds, ~%hwnd%~
    {
	UnRollWindow(hwnd)
    }
    else
    {
	RollWindow(hwnd)
    }
}

;_____rolls the window under cursor into its caption
RollWindow(hwnd)
{
    global
    WinGetPos, x, y, width, height, ahk_id %hwnd%
    if height > 45
    {
	RolledWindowDim%hwnd% = %height%
	RolledWindowIds := RolledWindowIds . "~" . hwnd . "~"
	WinMove, ahk_id %hwnd%, , , , ,%captionheight%
    }
}

;_____unrolls the window under cursor
UnRollWindow(hwnd)
{
    global
    StringReplace, RolledWindowIds, RolledWindowIds, ~%hwnd%~
    Transform, OldHeight, deref, `%RolledWindowDim%hwnd%`%
    ;this shouldn't happen, but just in case ....
    If OldHeight = 0
	OldHeight = 400
    WinMove, ahk_id %hwnd%, , , , ,%OldHeight%
    RolledWindowDim%hwnd% = 0
}


;_____unrolls all windows, you should call this in an OnExit sub
RestoreWindows()
{
    global RolledWindowIds
    StringSplit, winid, RolledWindowIds, ~
    If winid0 != 0
    {
	Loop, %winid0%
	{
	    out := winid%A_index%
	    if out !=
		UnRollWindow(winid%A_index%)
	}
    }
}



;_____returns the id if the mouse is in the caption area of the window, excluding icon area, and certain classes
IsInCaption()
{
    global CaptionHeight, RollExclude Classes
    MouseGetPos, x, y, id
    WinGetClass, class, Ahk_id %id%
    WinGetPos, winx, winy, winw, winh, ahk_id %id%
    If (x > (20 + winx)) && (x < (winx + winw)) && (y < (CaptionHeight + winy)) && (y > (winy)) && (InString(RollExcludeClasses,class) != 1)
	return id
    else
	return 0
}

;____function version of ifinstring
InString(lookin, lookfor)
{
    IfInString, lookin, lookfor
	return 1
    else
	return 0
}

;_____Toggles 150 transparency on/off
ToggleActiveTransparency()
{
    Winget, trans, transparent, A
    if trans = 150
	Winset, transparent, OFF, A
    else
	Winset, transparent, 150, A
}

And here's an example on how it's meant to be used

You can roll up a window by right-clicking on the caption, and toggle its transparency by middle clicking there.

#include windowfunctions.ahk
OnExit, ext

;_____Roll Window
RButton::
    r_id := IsInCaption()
    If r_id = 0
	MouseClick, r
    else
	ToggleWindowRoll(r_id)
return

#r::
    MouseGetPos, , , r_id
    ToggleWindowRoll(r_id)
return


;_____Transparency Toggle
MButton::
    r_id := IsInCaption()
    If r_id = 0
	MouseClick, m
    else
	ToggleActiveTransparency()
return

#!t::
    ToggleActiveTransparency()
return

exit:
RestoreWindows()
return

I noticed occasional Wacky Behaviorâ„¢, so please let me know if you encounter it so that it can be fixed. So far I've had problems pinning down the cause.

Heliosphan
  • Guests
  • Last active:
  • Joined: --
Hi
I was quite interested to see the window roll in action, but I just tried it with AHK v1.0.47.06 and it shows this error -

Error at line 75 in #include file....
Line Text : RollExclude Classes
Error: This line does not contain a recognised action.

The program will exit.

I'm presuming this worked for an earlier version of AHK and now no longer does so. If I knew AHK any better I'd fix it myself.

Helio

RiseUp
  • Members
  • 38 posts
  • Last active: Jan 04 2016 01:42 PM
  • Joined: 06 Dec 2007

Hi
I was quite interested to see the window roll in action, but I just tried it with AHK v1.0.47.06 and it shows this error -

Error at line 75 in #include file....
Line Text : RollExclude Classes
Error: This line does not contain a recognised action.

Hi Heliosphan,

From a quick (untested) look at the code, it appears all you need to do is remove the space between the two words in the Line Text, so it should now look like:
RollExcludeClasses
Try that and see how it works.