用vb怎样实现点击程序的最小化按钮后把窗口变到右下角成为一个图标?

然后点击右下角的图标后又能还原窗口.

建立一个图象筐把它的名称改为imgicon1.
form1窗体的代码:

Private Sub Command1_Click()

Me.Hide
Timer2.Enabled = False
TrayIcon.cbSize = Len(TrayIcon)
' Handle of the window used to handle messages - which is the this form
TrayIcon.hwnd = Me.hwnd
' ID code of the icon
TrayIcon.uId = vbNull
' Flags
TrayIcon.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
' ID of the call back message
TrayIcon.ucallbackMessage = WM_MOUSEMOVE
' The icon - sets the icon that should be used
TrayIcon.hIcon = imgicon1.Picture
' The Tooltip for the icon - sets the Tooltip that will be displayed
TrayIcon.szTip = "备份管理器" & Chr$(0)
' Add icon to the tray by calling the Shell_NotifyIcon API
'NIM_ADD is a Constant - add icon to tray
Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
' Don't let application appear in the Windows task list
App.TaskVisible = False
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

Static Message As Long
Static RR As Boolean

'x is the current mouse location along the x-axis
Message = x / Screen.TwipsPerPixelX
If RR = False Then
RR = True
Select Case Message
' Left double click (This should bring up a dialog box)
Case WM_LBUTTONDBLCLK
Me.Show
Timer2.Enabled = True
TrayIcon.cbSize = Len(TrayIcon)
TrayIcon.hwnd = Me.hwnd
TrayIcon.uId = vbNull
'Remove icon for Tray
Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)

' Right button up (This should bring up a menu)
Case WM_RBUTTONUP
Me.PopupMenu mainmenu
End Select
RR = False
End If

End Sub

新建一个标准模块把代码复制进:
Option Explicit

'**Originally published by Ryan Heldt (rheldt@vb-online.com)
'**Modified by Donovan Parks (donopark@awinc.com)

'Win32 API declaration
Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

' Constants used to detect clicking on the icon
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONUP = &H205

' Constants used to control the icon
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIF_MESSAGE = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4

' Used as the ID of the call back message
Public Const WM_MOUSEMOVE = &H200

' Used by Shell_NotifyIcon
Public 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

'create variable of type NOTIFYICONDATA
Public TrayIcon As NOTIFYICONDATA
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-05-12
VB里有一个部件可以做到,具体叫什么我忘记了.我有压缩格式的VB工程,写上你的QQ或邮箱吧

用vb怎样实现点击程序的最小化按钮后把窗口变到右下角成为一个图标?
建立一个图象筐把它的名称改为imgicon1.form1窗体的代码:Private Sub Command1_Click()Me.Hide Timer2.Enabled = False TrayIcon.cbSize = Len(TrayIcon)' Handle of the window used to handle messages - which is the this form TrayIcon.hwnd = Me.hwnd ' ID code of the icon TrayIcon...

vb中,如何让程序运行后最小化时在右下角
在窗体添加一个systray部件,然后在窗体上添加一个systray控件,然后再加上简单代码即可。例如,将所添加的systray控件命名为“sty”,在窗体中添加下述代码即可。Private Sub Form_Resize()If WindowState = 1 Then sty.InTray = True Hide Else sty.InTray = False Show End If End Sub ...

...VB 怎么实现 点关闭铵钮后,将窗口最小化到右下角的托盘中!_百度知 ...
可以用API来实现,不过还是采用微软封装好的控件来实现比较方便,不过改控件并不在VB安装目录中,需要找到VB的安装盘的COMMON\\TOOLS\\VB\\UNSUPPRT\\SYSTRAY目录,将Systray目录拷到硬盘上面并编译为ocx控件,然后在自己的VB程序中添加改控件。改控件的属性InTray属性用来设置是否显示在托盘中,True为显示在托盘...

vb.net中怎样实现程序最小化到右下角
设置NotifyIcon1的ICON属性,这个图标就是应用程序出现在系统托盘中的快捷图标;设置NotifyIcon1的Text属性为“VB.NET托盘程序”,这就是鼠标移动到托盘图标时弹出的文字说明;设置NotifyIcon1的ContextMenu属性为ContextMenu1,也就是右键单击快捷图标时的弹出菜单为 ContextMenu1。OK,按F5运行 ...

VB如何设置按退出变成右下角的地方?
注释:如果用户点击了托盘中的图标,则进行判断是点击了左键还是右键 If Msg = TRAY_CALLBACK Then 注释:如果点击了左键 If lParam = WM_LBUTTONUP Then 注释:而这时窗体的状态是最小化时 If TheForm.WindowState = vbMinimized Then _ 注释:恢复到最小化前的窗体状态 TheForm.WindowState = TheForm.La...

vb如何让当程序最小化时最小化到托盘 急!!!
最小化的事件在resize中判断即可,这时窗口的WindowState属性是1 Private Sub Form_Resize()If Me.WindowState = 1 Then “到托盘去”End Sub 在设计阶段,把窗体的WindowState属性改为0或2,可能是这里被你改为1,所以一启动就最小化了。

VB最小化到右下角
在Form1_mousemove里写代码可以检测到托盘图标上的Mouse操作。还原窗口用form1.show,并且 windowstate=0 '要不我给个源程序给你自己研究 QQ 58507961

VB.net如何实现点击关闭按钮时最小化到
1.降窗体的WindowState 属性 设置为 Mininmized;将ShowInTaskbar属性设置为False 2.在窗体的Load事件中添加下面的代码 if Me.WindowState = FormWindowState.Minimized then me.hide()end if

编一个程序,怎么让它最小化到桌面右下角显示运行?就像QQ一样,最小化...
1、新建立一个VB6工程,将Form1的ShowInTaskBar属性设置为False 2、菜单:工程--添加模块 按“打开”这样就添加了一个新模块,名为Module1,保存为Module1.bas 3、在Module1中写下如下代码:Option Explicit Public Const MAX_TOOLTIP As Integer = 64 Public Const NIF_ICON = &H2 Public Const NIF...

10分 VB 按窗口最小化按钮后,程序显示到系统托盘
Private Const WM_LBUTTONDOWN = &H201 '按鼠标左键 Private Const WM_RBUTTONDOWN = &H204 '按鼠标右键 Private Const NIM_ADD = 0 '添加图标 Private Const NIM_MODIFY = 1 '修改图标 Private Const NIM_DELETE = 2 '删除图标 Private Const NIF_MESSAGE = 1 'message 有效 Private Const...

相似回答