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 

Window Management Functions

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



Joined: 02 Jul 2004
Posts: 206

PostPosted: Thu May 26, 2005 10:54 pm    Post subject: Window Management Functions Reply with quote

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:

Code:

;_____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.

Code:

#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.
_________________
<enormous animated gif>
Back to top
View user's profile Send private message AIM Address
Heliosphan
Guest





PostPosted: Wed May 07, 2008 8:49 pm    Post subject: This no longer works! Reply with quote

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
Back to top
pockinator



Joined: 06 Dec 2007
Posts: 33

PostPosted: Thu May 08, 2008 1:21 pm    Post subject: Re: This no longer works! Reply with quote

Heliosphan wrote:
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:
Code:
RollExcludeClasses

Try that and see how it works.
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