Jump to content

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

Button for Always on top


  • Please log in to reply
8 replies to this topic
Tintifax
  • Members
  • 4 posts
  • Last active: Jan 12 2016 12:19 PM
  • Joined: 20 Jun 2013

Hi!

 

I'm new to AutoHotkey and I wonder if it's possible to add an indicator next to the three Buttons (minimize,close...) in the top right corner of every window that indicates wether a window is "Always on top" or not. If it is possible to make it a clickable Button this would be perfect! :-)

The tool eXtra Buttons does exactly that but first this tool offers a bunch of options I don't need (I only need AlwaysOnTop) and I don't want another process running just for that, and second eXtra Buttons is very unstable and keeps crashing all the time.

 

Would be nice if someone could tell me if this is possible with AutoHotkey and if it can be easily done.

 

Cheers,

Johannes

 



Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

I don't know about how to add a button to a window title bar, but this is a hotkey I use all the time..

;Alt+T = Toggle AlwaysOnTop state of the active window
!t::WinSet, AlwaysOnTop, Toggle, A

Join us at the new forum - http://www.ahkscript.org/

 


dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010

What you are asking for is almost certainly possible in AHk, but it would not be 'simple' or 'easy'. And it would probably require that the script run in the background all the time just like the program you already have.

 

There may be other ways to indicate whether a window is always on top. You could change the window style, which would make the window look different. Or you could possibly change the window title to include some indication of its status.

 

This is not exactly what you asked for but you might find some of the code interesting or useful:

http://crzyinc.weebl...m/stick-it.html


"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Tintifax
  • Members
  • 4 posts
  • Last active: Jan 12 2016 12:19 PM
  • Joined: 20 Jun 2013

@Linear Spoon: That's what I'm using too! :-) Thought I could pimp that "shortcut" with an indicator and/or button.

 

@dmg: Changing the window-style!!! That's it. This is even better than a small icon/button in the titel bar! I'll use the framecolor as indiactor. Let's see if this is possible. Thanks a lot!



Tintifax
  • Members
  • 4 posts
  • Last active: Jan 12 2016 12:19 PM
  • Joined: 20 Jun 2013

Hm, I can't find any information about how to change the color of the titlebar and/or the border of the active window.

Maybe WinSet, Style..., but there is no parameter for that in the styles table?



Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

Probably because the border colors are a user set theme that's a global setting. You're not supposed to mess with the user's settings so windows doesn't make it easy. You might be able to change it with SetSysColors, but it would affect every window...

 

There's this if you have the Aero theme: http://www.autohotke...ib-aero-libary/

The links are dead but the library is still in "Google's Archive" from the broken links sticky

 

Or maybe this: http://www.autohotke...ero#entry522212

 

Or you can just change the window title...

!t::  ;Alt+T - it will append " - AlwaysOnTop" to windows when they are AlwaysOnTop
  WinGetActiveTitle, t
  WinGet, ExStyle, ExStyle, %t%
  if (ExStyle & 0x8)
  {
    WinSet, AlwaysOnTop, Off, %t%
    WinSetTitle, %t%,, % RegexReplace(t, " - AlwaysOnTop")
  }
  else
  {
    WinSet, AlwaysOnTop, On, %t%
    WinSetTitle, %t%,, %t% - AlwaysOnTop
  }
return

Join us at the new forum - http://www.ahkscript.org/

 


noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011

CTT5Bfu.png

 

 

You could change the titlebar icon when it is OnTop.If you want it to survive  a restart you could use a settimer to check for the Ontop windows according to their style setting.


f4::
newIcon:="E:\go-top.ico"  ;16x16 icon file

WinGet, winID,id,A

WinGet, ExStyle, ExStyle, ahk_id %winID%
if (ExStyle & 0x8)  ; 0x8 is WS_EX_TOPMOST.
    {
    soundbeep  ;just for debugging
    WinSet, alwaysontop,off,ahk_id %winID%
    SendMessage, 0x80, 0, 0,, ahk_id %winID%  ; (0x80 is WM_SETICON).
    return
    }
else
    {
    WinSet, alwaysontop,on,ahk_id %winID%
    hIcon := DllCall("LoadImage", uint, 0, str, newIcon,uint, 1, int, 0, int, 0, uint, 0x10)   
    SendMessage, 0x80, 0, hIcon,, ahk_id %winID%  ; (0x80 is WM_SETICON).
    }
return

winXP  and ahk unicode


Tintifax
  • Members
  • 4 posts
  • Last active: Jan 12 2016 12:19 PM
  • Joined: 20 Jun 2013
Thanks a lot!
I'll go with both: WIN+A now appends "AlwaysOnTop" to the window title and changes the icon (I stole the pin-icon from eXtra Buttons hehe)

The only problem is the taskbar icon: It shows the same pin-icon when the window is set to "AlwaysOnTop", but it doesn't change back to the original window-icon when set to "Not AlwaysOnTop".
Maybe I would have to add another LoadImage-DllCall in the if-branch that restores the original icon.
Do you know how to read the path of the icon of the active window?

Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

WM_GETICON looks like what you need, but I don't have time to write an example of its usage:

http://msdn.microsof...5(v=vs.85).aspx


Join us at the new forum - http://www.ahkscript.org/