【桌面美化】突破垂直任务栏宽度限制

不知是否有人和我一样,为了节约宝贵的纵向空间,选择把任务栏放在屏幕左侧,但此时任务栏即使被缩小到最小尺寸,看起来依然很宽,非常影响心情。大概是因为任务栏的内部窗口过程限制了最小宽度。

很宽的任务栏,看起来不怎么美观,而且减少了可用空间:

【桌面美化】突破垂直任务栏宽度限制

使用正常的窗口消息和函数无法移动它,但有个小漏洞能钻,向任务栏发送WM_SIZING消息时,RECT结构体的Left成员设置为负数即可。但这种方法只适用于任务栏在左侧的情况,在右侧的话就可能需要使用注入手段解决,比较复杂。

在Win10测试通过,使用前最好在任务栏设置中选择使用小任务栏按钮,并使用简短的时间格式。

使用示例:ResizeTB(40) ; 将任务栏宽度设置为40像素

ResizeTB(size){
	VarSetCapacity(AppBarData, capacity := 48), NumPut(capacity, AppBarData, 0, "uint")
	DllCall("Shell32\SHAppBarMessage", "uint", 0x00000005, "ptr", &AppBarData)
	; if taskbar is on left of screen
	if (0 = NumGet(AppBarData, 20, "uint")){
		hTB := WinExist("ahk_class Shell_TrayWnd")
		NumPut(-A_ScreenWidth, AppBarData, 24, "int"), NumPut(size, AppBarData, 32, "int")
		; if taskbar is locked
		RegRead, bMovable, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, TaskbarSizeMove
		if (0 = bMovable){
			RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, TaskbarSizeMove, 1
			SendMessage, 0x0111, 0x1A065, 0,, ahk_id %hTB%
		}
		SendMessage, 0x0214, 2, % &AppBarData + 24,, ahk_id %hTB%
		WinMove, 0, 0
		if (0 = bMovable){
			RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, TaskbarSizeMove, 0
			SendMessage, 0x0111, 0x1A065, 0,, ahk_id %hTB%
		}
	}
}

搭配下面这段代码可以手动拖动任务栏:

~LButton::
	VarSetCapacity(Point, 8), DllCall("GetCursorPos", "ptr", &Point)
	SendMessage, 0x0084, 0, % NumGet(Point, 4, "int") << 16 | NumGet(Point, "int"),, % "ahk_id " WinExist("ahk_class Shell_TrayWnd")
	if (11 = ErrorLevel){
		while (A_Cursor == "SizeWE" && GetKeyState("LButton", "P")) {
			if (posLast != posNow := NumGet(Point, "int"))
				ResizeTB(posLast := posNow)
			DllCall("GetCursorPos", "ptr", &Point)
		}
	}
	return

效果如图,苗条的任务栏是不是好看很多呢?

【桌面美化】突破垂直任务栏宽度限制

再附上V2的代码:

~LButton::{
	DllCall("GetCursorPos", "ptr", lpPoint := Buffer(8))
	if 11 = SendMessage(0x0084, 0, NumGet(lpPoint, 4,"int") << 16 | NumGet(lpPoint, "int"), WinExist("ahk_class Shell_TrayWnd")) {
		posLast := ""
		while A_Cursor == "SizeWE" && GetKeyState("LButton", "P") {
			if posLast != posNow := NumGet(lpPoint, "int")
				ResizeTB(posLast := posNow)
			DllCall("GetCursorPos", "ptr", lpPoint)
		}
	}
}

ResizeTB(size){
	pAppBarData := Buffer(48), NumPut("uint", pAppBarData.Size, pAppBarData)
	DllCall("Shell32\SHAppBarMessage", "uint", 0x00000005, "ptr", pAppBarData)
	; if taskbar is on left of screen
	if 0 = NumGet(pAppBarData, 20, "uint") {
		hTB := WinExist("ahk_class Shell_TrayWnd")
		NumPut("int", -A_ScreenWidth, pAppBarData, 24), NumPut("int", size, pAppBarData, 32)
		; if taskbar is locked
		if 0 = bMovable := RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarSizeMove") {
			RegWrite(1, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarSizeMove")
			SendMessage(0x0111, 0x1A065, 0,, hTB)
		}
		SendMessage(0x0214, 2, pAppBarData.Ptr + 24,, hTB), WinMove(0, 0)
		if 0 = bMovable {
			RegWrite(0, "REG_DWORD", "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarSizeMove")
			SendMessage(0x0111, 0x1A065, 0,, hTB)
		}
	}
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他

右键双击,以非默认应用打开文件

2021-12-9 17:14:50

其他

AHKv1文件或目录监控〔搬运〕

2021-12-10 12:55:28

2 条回复 A文章作者 M管理员
  1. AHK中文社区

    牛?

  2. dbgba
    dbgba给您打赏了¥5
个人中心
购物车
优惠劵
有新私信 私信列表
搜索