VB6之调整任务栏按钮的位置

好无聊,睡前一更~

XP的任务栏没办法像win7那样随意拖动交换顺序,偶觉不爽,遂写程序搞之。这个不算什么新东西,参考了很多别人写的东东。

程序启动后,会在右下角托盘区显示钢铁侠的图标。右键击之,可选择退出程序全局范围内,使用快捷键Ctrl+方向键左(或者右)即可调整任务栏的按钮(即程序)的位置。

由于我在调试的时候使用了很多debug.print,觉得有碍观瞻的童鞋可以删除之。点我下载源文件!

有图才有真相:

这里仅贴出主要实现的模块:

  1 ‘主要实现模块
  2 ‘code by [email protected]
  3 Private Type TOOLBAR_BUTTONGROUPINFO
  4     AppTitle As String
  5     ToolTip As String
  6     hWnd As Long ‘parent hwnd
  7     btnId(1) As Long
  8     btnIndex(1) As Long
  9 End Type
 10
 11 Private Function GetToolbarHwnd() As Long
 12     Dim tbHwnd As Long
 13     Dim ClassName As Variant
 14
 15     For Each ClassName In Array("Shell_TrayWnd", _
 16         "ReBarWindow32", _
 17         "MSTaskSwWClass", _
 18         "ToolbarWindow32")
 19         tbHwnd = FindWindowEx(tbHwnd, 0&, ClassName, vbNullString)
 20     Next
 21     GetToolbarHwnd = tbHwnd
 22 End Function
 23
 24 Private Sub GetToolbarInfo(ByRef tb() As TOOLBAR_BUTTONGROUPINFO)
 25     Dim tbHwnd As Long
 26     Dim BtnCount As Long
 27     Dim pid As Long
 28     Dim hp As Long
 29     Dim pmem As Long
 30
 31     tbHwnd = GetToolbarHwnd()
 32     BtnCount = SendMessage(tbHwnd, TB_BUTTONCOUNT, 0&, 0&)
 33     Call GetWindowThreadProcessId(tbHwnd, pid)
 34     hp = OpenProcess(PROCESS_ALL_ACCESS Or PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, pid)
 35     pmem = VirtualAllocEx(hp, ByVal 0&, ByVal 4096&, MEM_COMMIT, PAGE_READWRITE)
 36
 37     Dim i As Long
 38     Dim btnId As Long
 39     Dim pbuff As Long
 40     Dim lpbuff(1024) As Byte
 41     Dim pbtnHwnd As Long
 42     Dim btnHwnd As Long
 43
 44     For i = 0 To BtnCount - 1
 45
 46         Call SendMessage(tbHwnd, TB_GETBUTTON, i, ByVal pmem)
 47         ‘get button-id
 48         Call ReadProcessMemory(hp, ByVal pmem + 4, ByVal VarPtr(btnId), ByVal 4&, ByVal 0&)
 49
 50         ‘get the tooltip or program-title of button
 51         Call ReadProcessMemory(hp, ByVal pmem + 16, ByVal VarPtr(pbuff), ByVal 4&, ByVal 0&)
 52         Call ReadProcessMemory(hp, ByVal pbuff, ByVal VarPtr(lpbuff(0)), ByVal 1024&, 0&)
 53
 54         ‘get hwnd of button-parent-window
 55         Call ReadProcessMemory(hp, ByVal pmem + 12, ByVal VarPtr(pbtnHwnd), ByVal 4, ByVal 0&)
 56         Call ReadProcessMemory(hp, ByVal pbtnHwnd, ByVal VarPtr(btnHwnd), ByVal 4, ByVal 0&)
 57
 58         Debug.Print BtnCount, i, btnId, Hex(btnHwnd), Left(lpbuff, InStr(lpbuff, Chr(0)))
 59         If i Mod 2 = 0 Then
 60             ReDim Preserve tb(i \ 2) As TOOLBAR_BUTTONGROUPINFO
 61         End If
 62         If btnHwnd = 0 Then
 63             With tb(i \ 2)
 64                 .AppTitle = Left(lpbuff, InStr(lpbuff, Chr(0)))
 65                 .btnId(0) = btnId
 66                 .btnIndex(0) = i
 67             End With
 68         Else
 69             With tb(i \ 2)
 70                 .btnId(1) = btnId
 71                 .btnIndex(1) = i
 72                 .hWnd = btnHwnd
 73                 .ToolTip = Left(lpbuff, InStr(lpbuff, Chr(0)))
 74             End With
 75         End If
 76
 77     Next
 78
 79     Call VirtualFreeEx(hp, ByVal pmem, ByVal 4096&, MEM_RELEASE)
 80     Call CloseHandle(hp)
 81 End Sub
 82
 83 Private Sub MoveToolbarButton(ByVal CurrentIndex As Long, _
 84     ByVal Position As Long, _
 85     Optional Direction = 0)
 86
 87     Dim tbHwnd As Long
 88     tbHwnd = GetToolbarHwnd()
 89
 90     ‘move right
 91     If Direction = 0 Then
 92         Call SendMessage(tbHwnd, TB_MOVEBUTTON, CurrentIndex, ByVal (CurrentIndex + Position * 3))
 93         Call SendMessage(tbHwnd, TB_MOVEBUTTON, CurrentIndex, ByVal (CurrentIndex + Position * 3))
 94     ‘move left
 95     ElseIf Direction = 1 Then
 96         Call SendMessage(tbHwnd, TB_MOVEBUTTON, CurrentIndex, ByVal (CurrentIndex - Position * 2))
 97         CurrentIndex = CurrentIndex + 1
 98         Call SendMessage(tbHwnd, TB_MOVEBUTTON, CurrentIndex, ByVal (CurrentIndex - Position * 2))
 99     End If
100 End Sub
101
102 Private Sub MoveButton(Optional Direction As Long)
103     Dim tb() As TOOLBAR_BUTTONGROUPINFO
104     Call GetToolbarInfo(tb)
105     If Direction = 0 Then
106         Call MoveToolbarButton(tb(0).btnIndex(0), UBound(tb), 0)
107     ElseIf Direction = 1 Then
108         Call MoveToolbarButton(tb(UBound(tb)).btnIndex(0), UBound(tb), 1)
109     End If
110     Erase tb
111 End Sub
112
113 Public Function CallbackWndProc(ByVal hWnd As Long, _
114     ByVal wMsg As Long, _
115     ByVal wParam As Long, _
116     ByVal lParam As Long) As Long
117
118     If wMsg = WM_HOTKEY Then
119         If wParam = HotKeyId1 Then
120             Debug.Print "move top right side"
121             Call MoveButton(0)
122         ElseIf wParam = HotKeyId2 Then
123             Debug.Print "move top left side"
124             Call MoveButton(1)
125         End If
126     ElseIf wMsg = WM_NOTIFYICON Then
127         If lParam = WM_RBUTTONUP Then
128             Debug.Print "Right Button Clicked"
129             Form1.PopupMenu Form1.TrayMenu
130         ElseIf lParam = WM_LBUTTONUP Then
131             Debug.Print "Left Button Clicked"
132         End If
133     End If
134     CallbackWndProc = CallWindowProc(lpPrevWndFunc, hWnd, wMsg, wParam, lParam)
135 End Function
136
137 Public Function LoadIconFromRes() As Long
138 ‘该功能的实现参考了以下2个链接
139 ‘@http://bbs.csdn.net/topics/360099153
140 ‘@http://blog.csdn.net/modest/article/details/2468937
141
142     Dim lpIE As ICONDIRENTRY
143     Dim buff() As Byte
144
145     buff = LoadResData(101, "ICON")
146     ‘For i = 0 To buff(4) - 1
147     ‘    Call CopyMemory(lpIE, buff(6 + i * Len(lpIE)), Len(lpIE))
148     ‘    Debug.Print lpIE.bWidth
149     ‘Next
150     Call CopyMemory(lpIE, buff(6), Len(lpIE))
151     LoadIconFromRes = CreateIconFromResourceEx(buff(lpIE.dwImageOffset), lpIE.dwBytesInRes, -1, &H30000, 32&, 32&, 0&)
152     Erase buff
153 End Function
154
155 Public Sub SetNotifyIcon()
156     With notify
157         .cbSize = Len(notify)
158         .hIcon = LoadIconFromRes()
159         .hWnd = Form1.hWnd
160         .szTip = "ToolbarSwitcher ver/0.1" & vbCrLf & _
161             "Code by [email protected]" & Chr(0)
162         .uCallbackMessage = WM_NOTIFYICON
163         .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
164         .uID = 1111&
165     End With
166     Call Shell_NotifyIcon(NIM_ADD, notify)
167 End Sub
168
169 Public Sub RemoveNotifyIcon()
170     Call Shell_NotifyIcon(NIM_DELETE, notify)
171 End Sub

VB6之调整任务栏按钮的位置

时间: 2024-11-05 20:47:52

VB6之调整任务栏按钮的位置的相关文章

iOS 调整导航栏返回按钮的位置

调整导航栏返回按钮的位置 //创建返回按钮 UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem]; leftBtn.frame = CGRectMake(0, 0, 25,25); [leftBtn setBackgroundImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [leftBtn addTarget:se

自定义导航栏按钮

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"侧栏" style:UIBarButtonItemStylePlain target:self action:@selector(clickleftButton:)]; 如果我们使用这行代码来定义按钮,无论左边右边,图片还是文字,他都会把字体或图片颜色变成默认的蓝色,然而并不是我们的需求, 所以我们这样 //导航栏 double

iOS7 UI兼容 导航栏按钮边距

转载自:http://www.cnblogs.com/maxfong/p/3375167.html iOS7之前的UI为: 而在iOS7中,由于设计方面的原因,使得UI变为: 修改的方法重写UINavigationItem的setLeftBarButtonItem和setRightBarButtonItem方法,使之与之前版本兼容: 代码如下: @interface UINavigationItem (margin) @end @implementation UINavigationItem (

js--手机头像点击显示按钮的位置自适应

在手机页面的中,头像显示的div,第一行的最后一个为点击显示更多的按钮(more),因为手机宽度的大小不一致,所以每行显示的头像个数也不一致,more按钮的位置总是固定在最后一排,所以需要通过计算屏幕宽度的大小,然后根据每个li的大小算出一行中最多能放几个,然后在将more通过js插入,如下图 iPhone5 显示如下: iPhone6 显示如下: 一下贴代码: HTML <div class="pic"> <ul> <li><img src=

jQuery实现两个按钮的位置互换

页面上有2个按钮A和B.点击按钮A和按钮B互换位置 ,点击按钮B和按钮A互换位置.应该如何实现? html代码如下: <body> <!--页面上有2个按钮A和B. 点击按钮A和按钮B互换位置 点击按钮B和按钮A互换位置--> <input type="button" value="按钮A" id="a"/> <input type="button" value="按钮B&q

UIButton如何正确调整imageView及titleLabel的位置

    一些开发者知道通过imageEdgeInsets及titleEdgeInsets 可以调整imageView及titleLabel的位置,但不知道如何正确计算,基本上都是通过多次调整相应的值达到期望的目标(次数过多可能会失去信 心),究其原因就是不能正确理解imageEdgeInsets及titleEdgeInsets. 下面步入主题. 如果button的bounds足够大(宽度至少是imageView宽度与titleLabel宽度之和,高度至少为imageView高度与titleLab

使用ultramon调整任务栏高度

取消锁定,调整任务栏的高度为一行图标的高度,然后再锁定即可.为啥程序没有默认设置?

iOS 开发之 - iOS6适配 - 导航栏按钮透明方法

首先上张图: 1:ios6导航栏默认按钮 rightBarButtonItem   是不是很丑的赶脚? 现在通过以下方法来改变以下:code: UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; rightButton.frame = CGRectMake(0, 0, 40, 40); [rightButton setTitle:@"提交" forState:UIControlStateNormal

scroll与按钮的位置

<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>scroll</title> </head> <style> *{ margin: 0; padding: 0; } header{ width: 100%; height: 100px; background:rgba(0,0,0,