问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

VB中怎么把程序缩小到又下脚,怎么在激活

发布网友 发布时间:2022-05-06 18:21

我来回答

1个回答

热心网友 时间:2023-10-14 20:53

托盘图标吗?要用api函数,你把我以下的代码复制过去,然后在你的工程里增加一个tptb的模块,再修改你的主程序的Resize和unload事件就可以了:还有,m1是一个菜单,你从菜单设计器中设计一个一个菜单m1,然后使他不可见,用来作弹出菜单来使用.

'本模块为实现托盘图标的模块 , 他在主窗体的form_resize和 form_unload中存在,看以下例子.

'Private Sub Form_Resize()
'If Me.WindowState = vbMinimized Then
' If tptb.show_yes = False Then
' tptb.AddToTray Me, m1
' tptb.show_yes = True
' tptb.SetTrayTip "资料管理"
' End If
' Me.Hide
'End If
'If Me.WindowState = 0 Then Me.WindowState = 2
'End Sub

'Private Sub Form_Unload(Cancel As Integer)
' tptb.RemoveFromTray
'End Sub

Public show_yes As Boolean
Public OldWindowProc As Long
Private TheForm As Form
Private TheMenu As Menu
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer '声明外部函数,获得鼠标按键状态
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) '模拟鼠标按键的API
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpszOp As String, _
ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal LpszDir As String, ByVal FsShowCmd As Long) _
As Long

Const SW_SHOW = 5
Const WM_USER = &H400
Const WM_RBUTTONUP = &H205
Const TRAY_CALLBACK = (WM_USER + 1001&)
Const GWL_WNDPROC = (-4)
Const GWL_USERDATA = (-21)
Const NIF_ICON = &H2
Const NIF_TIP = &H4
Const NIM_ADD = &H0
Const NIF_MESSAGE = &H1
Const NIM_MODIFY = &H1
Const NIM_DELETE = &H2
Const WM_LBUTTONDBLCLK = &H203
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const VK_LBUTTON = &H1
Const VK_RBUTTON = &H2
Const MOUSEEVENTF_RIGHTDOWN = &H8 ',模拟鼠标右键按下
Const MOUSEEVENTF_RIGHTUP = &H10 ',模拟鼠标右键抬起
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000

'记录 设置托盘图标的数据 的数据类型NOTIFYICONDATA
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
Uid As Long
UFlags As Long
UCallbackMessage As Long
HIcon As Long
SzTip As String * 64
End Type

'TheData变量记录设置托盘图标的数据
Private TheData As NOTIFYICONDATA
' *********************************************
' 新的窗口过程--主程序中采用SetWindowLong函数改变了窗口函数的地址,消息转向由NewWindowProc处理
' *********************************************
Private Function NewWindowProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

'如果用户点击了托盘中的图标,则进行判断是点击了左键还是右键
If msg = TRAY_CALLBACK Then
'如果点击了左键
If lParam = WM_LBUTTONDBLCLK Then
TheForm.WindowState = vbMaximized
TheForm.Show
Exit Function
End If
'如果点击了右键
If lParam = WM_RBUTTONUP Then
'则弹出右键菜单
TheForm.PopupMenu TheMenu
Exit Function
End If
End If

'如果是其他类型的消息则传递给原有默认的窗口函数
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, msg, wParam, lParam)
End Function
' *********************************************
' 把主窗体的图标(Form1.icon属性可改变)添加到托盘中
' *********************************************
Public Sub AddToTray(frm As Form, mnu As Menu)

'保存当前窗体和菜单信息
Set TheForm = frm
Set TheMenu = mnu

'GWL_WNDPROC获得该窗口的窗口函数的地址
OldWindowProc = SetWindowLong(frm.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)

'知识点滴:HWnd属性
'返回窗体或控件的句柄。语法: object.HWnd
'说明:Microsoft Windows 运行环境,通过给应用程序中的每个窗体和控件
'分配一个句柄(或 hWnd)来标识它们。hWnd 属性用于Windows API调用。

'将主窗体图标添加在托盘中
With TheData
.Uid = 0 '忘了吗?参考一下前面内容,Uid图标的序号,做动画图标有用
.hwnd = frm.hwnd
.cbSize = Len(TheData)
.HIcon = frm.Icon.Handle
.UFlags = NIF_ICON '指明要对图标进行设置
.UCallbackMessage = TRAY_CALLBACK
.UFlags = .UFlags Or NIF_MESSAGE '指明要设置图标或返回信息给主窗体,此句不能省去
.cbSize = Len(TheData) '为什么呢?我们需要在添加图标的同时,让其返回信息
End With '给主窗体,Or的意思是同时进行设置和返回消息
Shell_NotifyIcon NIM_ADD, TheData '根据前面定义NIM_ADD,设置为“添加模式”
End Sub
' *********************************************
' 删除系统托盘中的图标
' *********************************************
Public Sub RemoveFromTray()
'删除托盘中的图标
With TheData
.UFlags = 0
End With
Shell_NotifyIcon NIM_DELETE, TheData '根据前面定义NIM_DELETE,设置为“删除模式”

'恢复原有的设置
SetWindowLong TheForm.hwnd, GWL_WNDPROC, OldWindowProc
End Sub
' *********************************************
' 为托盘中的图标加上浮动提示(也就是鼠标移上去时出现的提示字条)
' *********************************************
Public Sub SetTrayTip(tip As String)
With TheData
.SzTip = tip & vbNullChar
.UFlags = NIF_TIP '指明要对浮动提示进行设置
End With
Shell_NotifyIcon NIM_MODIFY, TheData '根据前面定义NIM_MODIFY,设置为“修改模式”
End Sub
' *********************************************
' 设置托盘的图标(在本例中没有用到,如果要动态改变托盘内显示的图标,它非常有用)
' 例如:1、显示动画图标(方法你一定猜到了,对!使用Timer控件,不断调用此过程,注意把动画放在pic数组中)
' 2、程序处于不同状态时,显示不同的图标,方法是类似的
' 有兴趣的话试一试吧。
' *********************************************
Public Sub SetTrayIcon(pic As Picture)
'判断一下pic中存放的是不是图标
If pic.Type <> vbPicTypeIcon Then Exit Sub

'更换图标为pic中存放的图标
With TheData
.HIcon = pic.Handle
.UFlags = NIF_ICON
End With
Shell_NotifyIcon NIM_MODIFY, TheData
End Sub

热心网友 时间:2023-10-14 20:53

托盘图标吗?要用api函数,你把我以下的代码复制过去,然后在你的工程里增加一个tptb的模块,再修改你的主程序的Resize和unload事件就可以了:还有,m1是一个菜单,你从菜单设计器中设计一个一个菜单m1,然后使他不可见,用来作弹出菜单来使用.

'本模块为实现托盘图标的模块 , 他在主窗体的form_resize和 form_unload中存在,看以下例子.

'Private Sub Form_Resize()
'If Me.WindowState = vbMinimized Then
' If tptb.show_yes = False Then
' tptb.AddToTray Me, m1
' tptb.show_yes = True
' tptb.SetTrayTip "资料管理"
' End If
' Me.Hide
'End If
'If Me.WindowState = 0 Then Me.WindowState = 2
'End Sub

'Private Sub Form_Unload(Cancel As Integer)
' tptb.RemoveFromTray
'End Sub

Public show_yes As Boolean
Public OldWindowProc As Long
Private TheForm As Form
Private TheMenu As Menu
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer '声明外部函数,获得鼠标按键状态
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) '模拟鼠标按键的API
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpszOp As String, _
ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal LpszDir As String, ByVal FsShowCmd As Long) _
As Long

Const SW_SHOW = 5
Const WM_USER = &H400
Const WM_RBUTTONUP = &H205
Const TRAY_CALLBACK = (WM_USER + 1001&)
Const GWL_WNDPROC = (-4)
Const GWL_USERDATA = (-21)
Const NIF_ICON = &H2
Const NIF_TIP = &H4
Const NIM_ADD = &H0
Const NIF_MESSAGE = &H1
Const NIM_MODIFY = &H1
Const NIM_DELETE = &H2
Const WM_LBUTTONDBLCLK = &H203
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const VK_LBUTTON = &H1
Const VK_RBUTTON = &H2
Const MOUSEEVENTF_RIGHTDOWN = &H8 ',模拟鼠标右键按下
Const MOUSEEVENTF_RIGHTUP = &H10 ',模拟鼠标右键抬起
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000

'记录 设置托盘图标的数据 的数据类型NOTIFYICONDATA
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
Uid As Long
UFlags As Long
UCallbackMessage As Long
HIcon As Long
SzTip As String * 64
End Type

'TheData变量记录设置托盘图标的数据
Private TheData As NOTIFYICONDATA
' *********************************************
' 新的窗口过程--主程序中采用SetWindowLong函数改变了窗口函数的地址,消息转向由NewWindowProc处理
' *********************************************
Private Function NewWindowProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

'如果用户点击了托盘中的图标,则进行判断是点击了左键还是右键
If msg = TRAY_CALLBACK Then
'如果点击了左键
If lParam = WM_LBUTTONDBLCLK Then
TheForm.WindowState = vbMaximized
TheForm.Show
Exit Function
End If
'如果点击了右键
If lParam = WM_RBUTTONUP Then
'则弹出右键菜单
TheForm.PopupMenu TheMenu
Exit Function
End If
End If

'如果是其他类型的消息则传递给原有默认的窗口函数
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, msg, wParam, lParam)
End Function
' *********************************************
' 把主窗体的图标(Form1.icon属性可改变)添加到托盘中
' *********************************************
Public Sub AddToTray(frm As Form, mnu As Menu)

'保存当前窗体和菜单信息
Set TheForm = frm
Set TheMenu = mnu

'GWL_WNDPROC获得该窗口的窗口函数的地址
OldWindowProc = SetWindowLong(frm.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)

'知识点滴:HWnd属性
'返回窗体或控件的句柄。语法: object.HWnd
'说明:Microsoft Windows 运行环境,通过给应用程序中的每个窗体和控件
'分配一个句柄(或 hWnd)来标识它们。hWnd 属性用于Windows API调用。

'将主窗体图标添加在托盘中
With TheData
.Uid = 0 '忘了吗?参考一下前面内容,Uid图标的序号,做动画图标有用
.hwnd = frm.hwnd
.cbSize = Len(TheData)
.HIcon = frm.Icon.Handle
.UFlags = NIF_ICON '指明要对图标进行设置
.UCallbackMessage = TRAY_CALLBACK
.UFlags = .UFlags Or NIF_MESSAGE '指明要设置图标或返回信息给主窗体,此句不能省去
.cbSize = Len(TheData) '为什么呢?我们需要在添加图标的同时,让其返回信息
End With '给主窗体,Or的意思是同时进行设置和返回消息
Shell_NotifyIcon NIM_ADD, TheData '根据前面定义NIM_ADD,设置为“添加模式”
End Sub
' *********************************************
' 删除系统托盘中的图标
' *********************************************
Public Sub RemoveFromTray()
'删除托盘中的图标
With TheData
.UFlags = 0
End With
Shell_NotifyIcon NIM_DELETE, TheData '根据前面定义NIM_DELETE,设置为“删除模式”

'恢复原有的设置
SetWindowLong TheForm.hwnd, GWL_WNDPROC, OldWindowProc
End Sub
' *********************************************
' 为托盘中的图标加上浮动提示(也就是鼠标移上去时出现的提示字条)
' *********************************************
Public Sub SetTrayTip(tip As String)
With TheData
.SzTip = tip & vbNullChar
.UFlags = NIF_TIP '指明要对浮动提示进行设置
End With
Shell_NotifyIcon NIM_MODIFY, TheData '根据前面定义NIM_MODIFY,设置为“修改模式”
End Sub
' *********************************************
' 设置托盘的图标(在本例中没有用到,如果要动态改变托盘内显示的图标,它非常有用)
' 例如:1、显示动画图标(方法你一定猜到了,对!使用Timer控件,不断调用此过程,注意把动画放在pic数组中)
' 2、程序处于不同状态时,显示不同的图标,方法是类似的
' 有兴趣的话试一试吧。
' *********************************************
Public Sub SetTrayIcon(pic As Picture)
'判断一下pic中存放的是不是图标
If pic.Type <> vbPicTypeIcon Then Exit Sub

'更换图标为pic中存放的图标
With TheData
.HIcon = pic.Handle
.UFlags = NIF_ICON
End With
Shell_NotifyIcon NIM_MODIFY, TheData
End Sub
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
...时间会发作,很痛的,请问是这样吗?会痛多久? ...已经坏了,如今全身浮肿,尿排不出,医生说就这 我爷爷得了肝癌晚期,腹水,不能手术.听说氩氦超冷刀技术能治.哪里有... 父亲59岁得了肝癌晚期,医生说最多半年时间了,上面还有80多岁的爷爷... 长春跑大连的列车员,怎么区分正式分和临时工呢? 员工刚怀孕就被开除,开除负责人拒不认错,你如何看待该公司的态度?_百 ... 员工在职期间怀孕,老板可以无故迟退吗? 老板开除怀孕女员工违法吗 如何选购蚊帐 什么样的蚊帐最好 哪位老师能编一个在通达信选股器找五线开花的公式 梦见老婆被害 连续10根K线收盘价上下穿越60日均线提示多空信号太多,帮该写一下,信号提示一次就可以了 梦见老婆被别人敲诈 请高手改公式,买入,卖出条件选股 m1i如何删除图标 得胜pc-k550和艾肯ICON M1哪个好 icon m1电容麦+百灵达204d外置声卡 为什么录的音有杂音 滋滋声?是声卡还 我刚买了一款Icon utrack的声卡和一个ICON m1 用cooledit录音为什么左耳有人声右耳没有 艾肯ICON M1电容麦怎么样 喜马拉雅电台录音ICON M1麦克风够吗 我唱歌声音比较薄,用美国艾肯 icon m1怎么样? icon m1电容麦 录歌效果怎么样啊?专业么? 我的声卡是usb icon utrack声卡 闲鱼发布商品总是获取数据失败是什么情况? 请问,卷叶球兰开花香吗? 卷叶球兰能耐多少度低温? 孕妇梦见偷干尸 球兰如何养??? 内锦卷叶球兰为啥后来长出的新叶是全绿的? 蜜蜂和什么动物是互利共生 请给我的JAVA程序添加一个自动播放图片功能 梦见老婆被朋友骗然后被人救 坐便堵了怎么办啊?我家好像是旋涡型的!买了手摇疏通器,根本就插不进去!只能进去30厘米就进不去了! 坐便马桶堵住了怎么办 最好学习软件编程(JAVA)的免费网站有哪些 JAVA这个软件怎么学习 路由器的PIN是什么? 吹字在新华字典第11版里面的多少页 丢在字典里的哪一页? 雨字旁在捡字表几页 十六画的字有那些? 新华字典1029页第一个字是什么? 租房合同中写着违约怎么办 出租屋合同网上的能直接用吗 和朋友合租,合同是我朋友一个人签的,违约我要支付违约金嘛?走后我东西忘拿被房东扔了,可以索要赔偿嘛 干粉灭火器MFZ/ABC5几年换一次、检查呢 方舟怎么创房间跟朋友一起玩? 租房合同未到期违约如何处罚? 基金跌了10个点要加仓多少才能补平 基金一周跌了10%是出货还是等待