重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net托盘程序的简单介绍

VB.net做的程序在进程结束后托盘图标不会消失,需要鼠标滑过才会消失,怎么处理这个问题?

只有windows 7等以上版本的操作系统才可以自动消失。其他windows NT内核版本,例如:windows 2003,windows xp,windows 2000等老版本,要让图标托盘消失,必须至少要两种方法:

在新会等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计制作、成都网站建设 网站设计制作定制网站建设,公司网站建设,企业网站建设,成都品牌网站建设,营销型网站,成都外贸网站建设,新会网站建设费用合理。

1:退出程序时,在代码里调用删除托盘图标的代码。

2:程序崩溃时或者是手动结束进程后,图标遗留在右下角,只能用鼠标移动到上面,它才会消失。

所以,必须要在代码里面写上退出托盘的程序,因为很多人当然也包括我自己,有时候编写代码,只编写了启动托盘的代码,没有写退出托盘的代码,以为程序退出了,托盘图标会自己消失。而事实上不是这样的,托盘的启动和退出,必须要自己来显式的在程序里面实现。启动托盘实现后,必须要实现退出托盘。

所以建议大家在编写托盘图标程序时,在退出程序的时候,显式的调用删除托盘图标的代码就可以了。

vb.net 托盘!

我记在弹出菜单的时候可以指定位置的吧?依稀记得有个x和y的参数吧?你试试修改一下,把y值再减少一点呢?

找了个以前的代码:

mnuPrize.Show(lblMenu, New Point(0, lblMenu.Height))

我这个是在Label的下面弹出来,你可以改一下Point的赋值,提高菜单显示位置

vb.net怎么把其它程序最小化到托盘

如果用vb.net程序打开可以用如下代码:

Shell("C:\文件", AppWinStyle.Hide)'打开C:\文件,并在其打开时将其隐藏

如不懂可以追问

望采纳

如何把VB.NET程序最小化到托盘图标区

VB.NET编写托盘程序

托盘程序作为一类特殊的窗体,其快捷图标显示在

系统托盘

中,窗体本身则隐藏不可见。在.NET之前版本的VB中编写托盘程序是十分困难的,但是VB.NET提供的新的NotifyIcon组件却使VB初学者也能轻松编写一个这样的程序:

新建“Windows应用程序”,设置主窗体Opacity属性为0,FormBorderStyle属性为None,ShowInTaskbar属性为

False,这样窗体将在启动后隐藏。在窗体上放置一个NotifyIcon组件NotifyIcon1,一个ContextMenu(弹出菜单)组件

ContextMenu1,并根据需要为ContextMenu1添加菜单项。

设置NotifyIcon1的ICON属性,这个图标就是应用程序出现在系统托盘中的快捷图标;设置NotifyIcon1的Text属性为“VB.NET托盘程序”,这就是鼠标移动到托盘图标时弹出的文字说明;设置NotifyIcon1的ContextMenu属性为ContextMenu1,也就是右键单击快捷图标时的弹出菜单为

ContextMenu1。OK,按F5运行!

几乎不用编写代码,一个托盘程序就这样轻松实现了。

哪位大侠教教俺VB 6.0 全局热键&托盘程序

VB6没有什么做不到,谁说VB6不如VB.net,只是方法的使用而已,其实这些都是可以VB6都是可以做到的,可以交流!vb中设置全局热键的方法很多,我介绍几种吧:第一种回调用,添加模块复制下面代码Private Declare Function CallNextHookEx Lib "user32" _

(ByVal hHook As Long, _

ByVal nCode As Long, _

ByVal wParam As Long, _

lParam As Any) As Long

Private Declare Function SetWindowsHookEx Lib "user32" _

Alias "SetWindowsHookExA" _

(ByVal idHook As Long, _

ByVal lpfn As Long, _

ByVal hmod As Long, _

ByVal dwThreadId As Long) As Long

Private Declare Function UnhookWindowsHookEx Lib "user32" _

(ByVal hHook As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _

Alias "RtlMoveMemory" _

(Destination As Any, _

Source As Any, _

ByVal Length As Long)

Private Type PKBDLLHOOKSTRUCT

vkCode As Long

scanCode As Long

flags As Long

time As Long

dwExtraInfo As Long

End Type

Private Const WM_KEYDOWN = H100

Private Const WM_SYSKEYDOWN = H104

Private Const WM_KEYUP = H101

Private Const WM_SYSKEYUP = H105

Private Const HC_ACTION = 0

Private Const WH_KEYBOARD_LL = 13

Private lngHook As Long

Public Function HotKey(ByVal nCode As Long, _

ByVal wParam As Long, _

ByVal lParam As Long) As Long

Dim p As PKBDLLHOOKSTRUCT

If nCode = HC_ACTION Then

Select Case wParam

Case WM_KEYDOWN, WM_SYSKEYDOWN

Call CopyMemory(p, ByVal lParam, Len(p))

If p.vkCode = vbKeyF10 Then '这里定义热键

MsgBox "你按下了F10" '这里,执行你要执行的程序,我这里示范msgbox

End If '如果你想定义多个热键就复制上面3行代码然后把vbKeyF10 改成你想要的就可以了。

Case Else

End Select

End If

Call CallNextHookEx(WH_KEYBOARD_LL, nCode, wParam, lParam)

End Function

Public Sub HooK()

lngHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf HotKey, App.hInstance, 0)

End Sub

Public Sub UnHooK()

Call UnhookWindowsHookEx(lngHook)

End Sub

'窗体中代码

Private Sub Form_Load()

HooK

End Sub

Private Sub Form_Unload(Cancel As Integer)

UnHooK

End Sub

第二种方法 1、建立一个模块代码如下:

'******************************

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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

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 RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fskey_Modifiers As Long, ByVal vk As Long) As Long

Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long

Const WM_HOTKEY = H312

Const MOD_ALT = H1

Const MOD_CONTROL = H2

Const MOD_SHIFT = H4

Const GWL_WNDPROC = (-4) '窗口函数的地址

Dim key_preWinProc As Long '用来保存窗口信息

Dim key_Modifiers As Long, key_uVirtKey As Long, key_idHotKey As Long

Dim key_IsWinAddress As Boolean '是否取得窗口信息的判断

Function keyWndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

If Msg = WM_HOTKEY Then

Select Case wParam 'wParam 值就是 key_idHotKey

Case 1 '激活 3 个热键后,3 个热键所对应的操作,大家在其他的程序中,只要修改此处就可以了

MsgBox "alt+1"

Case 2

MsgBox "alt+2"

Case 3

MsgBox "alt+3"

Case 4

MsgBox "alt+4"

End Select

End If

' 将消息传送给指定的窗口

keyWndproc = CallWindowProc(key_preWinProc, hwnd, Msg, wParam, lParam)

End Function

Function SetHotkey(ByVal KeyId As Long, ByVal KeyAss0 As String, ByVal Action As String)

Dim KeyAss1 As Long

Dim KeyAss2 As String

Dim i As Long

i = InStr(1, KeyAss0, ",")

If i = 0 Then

KeyAss1 = Val(KeyAss0)

KeyAss2 = ""

Else

KeyAss1 = Right(KeyAss0, Len(KeyAss0) - i)

KeyAss2 = Left(KeyAss0, i - 1)

End If

key_idHotKey = 0

key_Modifiers = 0

key_uVirtKey = 0

If key_IsWinAddress = False Then '判断是否需要取得窗口信息,如果重复取得,再最后恢复窗口时,将会造成程序死掉

' 记录原来的window程序地址

key_preWinProc = GetWindowLong(Form1.hwnd, GWL_WNDPROC)

' 用自定义程序代替原来的window程序

SetWindowLong Form1.hwnd, GWL_WNDPROC, AddressOf keyWndproc

End If

key_idHotKey = KeyId

Select Case Action

Case "Add"

If KeyAss2 = "Ctrl" Then key_Modifiers = MOD_CONTROL

If KeyAss2 = "Alt" Then key_Modifiers = MOD_ALT

If KeyAss2 = "Shift" Then key_Modifiers = MOD_SHIFT

If KeyAss2 = "Ctrl+Alt" Then key_Modifiers = MOD_CONTROL + MOD_ALT

If KeyAss2 = "Ctrl+Shift" Then key_Modifiers = MOD_CONTROL + MOD_SHIFT

If KeyAss2 = "Ctrl+Alt+Shift" Then key_Modifiers = MOD_CONTROL + MOD_ALT + MOD_SHIFT

If KeyAss2 = "Shift+Alt" Then key_Modifiers = MOD_SHIFT + MOD_ALT

key_uVirtKey = Val(KeyAss1)

RegisterHotKey Form1.hwnd, key_idHotKey, key_Modifiers, key_uVirtKey '向窗口注册系统热键

key_IsWinAddress = True '不需要再取得窗口信息

Case "Del"

SetWindowLong Form1.hwnd, GWL_WNDPROC, key_preWinProc '恢复窗口信息

UnregisterHotKey Form1.hwnd, key_uVirtKey '取消系统热键

key_IsWinAddress = False '可以再次取得窗口信息

End Select

End Function

2、form中的代码:

'******************************

Private Sub Form_Load()

SetHotkey 1, "Alt,49", "Add"

SetHotkey 2, "Alt,50", "Add"

SetHotkey 3, "Alt,51", "Add"

SetHotkey 4, "Alt,52", "Add"

End Sub

Private Sub Form_Unload(Cancel As Integer)

SetHotkey 1, "", "Del"

SetHotkey 2, "", "Del"

SetHotkey 3, "", "Del"

SetHotkey 4, "", "Del"

End Sub

当然还有别的方法。方法真的很多。托盘程序呢,这个就没必要发了吧。网上多的数不清,基本都是有右键的。如果你找不到你就搜一下vb托盘控件,那些都能直接当成控件调用方便的可以。 这个就能满足你要求。 这个也可以。太多了。我就不写出来了吧。


网页名称:vb.net托盘程序的简单介绍
本文来源:http://cqcxhl.cn/article/hcopoc.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP