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 ......
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Sub Command1_Click()
Dim Url As String, Filepath As String
Url = "h ......
Option Explicit
Private Const NCBASTAT = &H33
Private Const NCBNAMSZ = 16
Private Const HEAP_ZERO_MEMORY = &H8
Private Const HEAP_GENERATE_EXCEPTIONS = &H4
Private Const NCBRESET = &H32
Private Type NCB
ncb_command As Byte
ncb_retcode As Byte
ncb_lsn As Byte
ncb_num As Byte ......
建一个模块
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilt ......
VB 注释程序代码的符号是 ',只要在某行程序前面加上该符号就可以注释该行程序。但如果程序代码语句很多的时候,一行一行地注释就非常不方便。其实 VB
本身提供了一次性注释多条语句的功能:在主菜单“视图”选项的“工具栏”下,选中“编辑”,VB
的界面会出现一排工具按钮,其中就有用 ......