[AHK]WinAutoHide – 让窗口贴边隐藏

WinAutoHide是一款使用AutoHotkey编写的工具,可让任意窗口贴边隐藏并自动恢复显示。用户可通过快捷键Win+方向键实现窗口隐藏,鼠标移至窗口边缘即可恢复显示。本文详细介绍其使用方法及修改版功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自: https://www.appinn.com/WinAutoHide/

http://code.google.com/p/winautohide/

文章标签: 窗口 / 精选 / 隐藏.

QQ 的贴边隐藏的确是个不错的功能,一直以来很多人都想找个能让任意窗口贴边隐藏的软件。曾经小众介绍过一个 AHK 脚本,AHK 快餐店[15] 之 史上最强的 Alt + Tab [附绿色版下载] 带了这个的功能,可惜调用贴边隐藏功能不方便。@appinn

WinAutoHide 是一个用 AHK 编写的,可以让窗口贴边隐藏的小工具。前天小众读者 Forrest 问 @sfufoet 我:“autoHotkey 能不能使其他软件窗口像 QQ 那样停靠在窗口边缘?鼠标移动上去窗口显示,鼠标移开窗口恢复停靠。”既然有需求就放出来吧。我用了它很久了,因为有个奇怪的 Bug——有时候会隐藏失败,窗口已经隐藏,却界面残留,恢复一下再隐藏就行,而且不支持双显示器,所以一直未做介绍。

上面是动态演示图。对任意窗口按下快捷键 Win + ← 就可以把窗口贴边隐藏到左边。同理,Win + → / ↑ / ↓ 分别对贴边隐藏到右边、上边,下边。鼠标离开窗口后,会再次自动贴边隐藏。恢复的方法是对已隐藏的窗口再用一次快捷键,任意一个快捷键都是贴边/恢复的开关。

窗口贴边隐藏之后,不小心把指针移到上面就会弹出,比较郁闷。所以我修改了一个新版本,重命名为 winautohide_Ctrl.exe,此版本必须按住 Ctrl 键,并且把鼠标移到隐藏窗口边缘,窗口才会弹出。此修改版还处理了一个问题:在已经贴边隐藏的窗口的弹出状态,不小心把鼠标指向输入法状态条的话,窗口会自动隐藏。处理后的版本只有当鼠标移到到任务栏或者桌面上,窗口才会再次隐藏。

update: 修改版我隐藏了托盘菜单,并增加了两个快捷键:Win + home 恢复全部贴边窗口,Win + End 还原并退出。两个版本退出程序也会自动还原。

想修改快捷键?请自行修改源代码吧。我懒得写配置界面,太麻烦了。自己动手,丰衣足食。XD,此软件绝对是上班搞副业的必备利器。

 

/*
 * BoD winautohide v1.00.
 *
 * This program and its source are in the public domain.
 * Contact BoD@JRAF.org for more information.
 *
 * Version history:
 * 2008-06-13: v1.00
 */

#SingleInstance ignore

/*
 * Hotkey bindings
 */
Hotkey, #right, toggleWindowRight
Hotkey, #left, toggleWindowLeft
Hotkey, #up, toggleWindowUp
Hotkey, #down, toggleWindowDown

; uncomment the following lines to use ctrl+alt+shift instead if you don't have a "windows" key
;Hotkey, !^+right, toggleWindowRight
;Hotkey, !^+left, toggleWindowLeft
;Hotkey, !^+up, toggleWindowUp
;Hotkey, !^+down, toggleWindowDown



/*
 * Timer initialization.
 */
SetTimer, watchCursor, 300


/*
 * Tray menu initialization.
 */
Menu, tray, NoStandard
Menu, tray, Add, About..., menuAbout
Menu, tray, Add, Un-autohide all windows, menuUnautohideAll
Menu, tray, Add, Exit, menuExit
Menu, tray, Default, About...


return ; end of code that is to be executed on script start-up


/*
 * Tray menu implementation.
 */
menuAbout:
	MsgBox, 8256, About, BoD winautohide v1.00.`n`nThis program and its source are in the public domain.`nContact BoD@JRAF.org for more information.
return

menuUnautohideAll:
	Loop, Parse, autohideWindows, `,
	{
		curWinId := A_LoopField
		if (autohide_%curWinId%) {
			Gosub, unautohide
		}
	}
return

menuExit:
	Gosub, menuUnautohideAll
	ExitApp
return



/*
 * Timer implementation.
 */
watchCursor:
	MouseGetPos, , , winId ; get window under mouse pointer
	if (autohide_%winId%) { ; window is on the list of 'autohide' windows
		if (hidden_%winId%) { ; window is in 'hidden' position
			previousActiveWindow := WinExist("A")
			WinActivate, ahk_id %winId% ; activate the window
			WinMove, ahk_id %winId%, , showing_%winId%_x, showing_%winId%_y ; move it to 'showing' position
			hidden_%winId% := false
			needHide := winId ; store it for next iteration
		}
	} else {
		if (needHide) {
			WinMove, ahk_id %needHide%, , hidden_%needHide%_x, hidden_%needHide%_y ; move it to 'hidden' position
			WinActivate, ahk_id %previousActiveWindow% ; activate previously active window
			hidden_%needHide% := true
			needHide := false ; do that only once
		}
	}
return


/*
 * Hotkey implementation.
 */
toggleWindowRight:
	mode := "right"
	Gosub, toggleWindow
return

toggleWindowLeft:
	mode := "left"
	Gosub, toggleWindow
return

toggleWindowUp:
	mode := "up"
	Gosub, toggleWindow
return

toggleWindowDown:
	mode := "down"
	Gosub, toggleWindow
return


toggleWindow:
	WinGet, curWinId, id, A
	autohideWindows = %autohideWindows%,%curWinId%
	if (autohide_%curWinId%) {
		Gosub, unautohide
	} else {
		autohide_%curWinId% := true
		Gosub, workWindow
		WinGetPos, orig_%curWinId%_x, orig_%curWinId%_y, width, height, ahk_id %curWinId% ; get the window size and store original position

		if (mode = "right") {
			showing_%curWinId%_x := A_ScreenWidth - width
			showing_%curWinId%_y := orig_%curWinId%_y

			hidden_%curWinId%_x := A_ScreenWidth - 1
			hidden_%curWinId%_y := orig_%curWinId%_y
		} else if (mode = "left") {
			showing_%curWinId%_x := 0
			showing_%curWinId%_y := orig_%curWinId%_y

			hidden_%curWinId%_x := -width + 1
			hidden_%curWinId%_y := orig_%curWinId%_y
		} else if (mode = "up") {
			showing_%curWinId%_x := orig_%curWinId%_x
			showing_%curWinId%_y := 0

			hidden_%curWinId%_x := orig_%curWinId%_x
			hidden_%curWinId%_y := -height + 1
		} else { ; down
			showing_%curWinId%_x := orig_%curWinId%_x
			showing_%curWinId%_y := A_ScreenHeight - height

			hidden_%curWinId%_x := orig_%curWinId%_x
			hidden_%curWinId%_y := A_ScreenHeight - 1
		}

		WinMove, ahk_id %curWinId%, , hidden_%curWinId%_x, hidden_%curWinId%_y ; hide the window
		hidden_%curWinId% := true
	}
return


unautohide:
	autohide_%curWinId% := false
	needHide := false
	Gosub, unworkWindow
	WinMove, ahk_id %curWinId%, , orig_%curWinId%_x, orig_%curWinId%_y ; go back to original position
	hidden_%curWinId% := false
return

workWindow:
	DetectHiddenWindows, On
	WinSet, AlwaysOnTop, on, ahk_id %curWinId% ; always-on-top
	WinHide, ahk_id %curWinId%
	WinSet, Style, -0xC00000, ahk_id %curWinId% ; no title bar
	WinSet, ExStyle, +0x80, ahk_id %curWinId% ; remove from task bar
	WinShow, ahk_id %curWinId%
return

unworkWindow:
	DetectHiddenWindows, On
	WinSet, AlwaysOnTop, off, ahk_id %curWinId% ; always-on-top
	WinHide, ahk_id %curWinId%
	WinSet, Style, +0xC00000, ahk_id %curWinId% ; title bar
	WinSet, ExStyle, -0x80, ahk_id %curWinId% ; remove from task bar
	WinShow, ahk_id %curWinId%
return

This is a tiny utility that will add an icon in the notification area of the Windows taskbar, and add 4 shortcut keys (Windows+Left, Windows+Right, Windows+Up, Windows+Down).

When you press one of the shortcuts (say Windows+Right for example), the currently active window will "hide" to the right edge of your screen, showing only one pixel of its border. It will also stay "always on top" of other windows, so you will always see this one pixel border. Then when you hover your mouse on that border, the window will appear and take the focus, so you can use it. When you move back your mouse away from the window, it will hide again.

In effect the window will act like the Windows taskbar when the "auto-hide" setting is checked, or other similar bars (eg. the Google Desktop "sidebar").

This utility can be useful if you have a few small windows that you use often (for example a terminal or a command prompt) and you want to access them quickly just by moving the mouse.

Limitations:

  • Doesn't seem to work with a few "special" windows, like Winamp for example.
  • Multi-monitor setup is not supported / tested.
  • Tested only under Windows XP.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值