VB怎样判断、防止程序重复执行
Private Sub Form_load()
'判断程序是否已经运行
If App.PrevInstance
Then
MsgBox "本程序已经运行!", vbInformation Or vbOKOnly, "提示信息"
Unload
Me
Exit Sub
End If
'以下是主要程序
' ……
End
Sub
附:另一个例子:
Option Explicit
Public Sub CheckExist(fm
As Form) '防止程序重复执行
Dim title As String
If App.PrevInstance
Then
title = App.title
Call MsgBox("这程序已执行",
vbCritical)
App.title = "" '如此才不会 Avtivate 到自己
fm.Caption =
""
AppActivate title 'activate 先前就已运行的程序
End ' 结束
End
If
End Sub
Private Sub Form_Load()
Call
CheckExist(Me)
End Sub
相关文档:
VB编写托盘图标有两个要点,一是使用 Shell_NotifyIcon 函数显示图标;二是向系统注册 TaskbarCreated 消息,以便explorer崩溃时恢复托盘的图标。
首先需要增加一个模块文件,内容如下:
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOT ......
'代码:
Option Explicit
'======================用于查找进程和终止进程的API函数常数定义================ =====
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessF ......
mxl=1 && 最大的文本框编号
mnl=1 &n ......
在工程中添加一个类模块,名为 Selection
然后加入以下代码:
Dim colRows As Collection
Dim ControlKey As Boolean
Public WithEvents flx As M ......