用系统原子: GlobalAddAtom
GlobalFindAtom char* a="XXX只执行一次";
ATOM atom;
atom=GlobalFindAtom(a);
if(atom==0)
GlobalAddAtom(a);
else
MessageBox "程序运行中!"
在程序结束删除原子:
atom=GlobalFindAtom(a);
GlobalDeleteAtom(atom);
GlobalFindAtom char* a="XXX只执行一次";
ATOM atom;
atom=GlobalFindAtom(a);
if(atom==0)
GlobalAddAtom(a);
else
MessageBox "程序运行中!"
在程序结束删除原子:
atom=GlobalFindAtom(a);
GlobalDeleteAtom(atom);
解决方案 »
- 分不多140分送上,麻烦帮我看下这个问题,谢谢谢谢谢谢谢
- 在vb中怎么保存从一个文件中加载到picturebox中的图片
- 关于VB的随机文件
- SQL奇怪问题,某段数据Select比别的数据段速度慢!!
- ADO2。0建立临时表是否一定要升级到VB 6.0 SP5?
- 请教,我用ACCESS数据库,如何用代码进行数据库的备份和压缩?谢谢!
- 联合索引问题!!!!!!!!!急急急急!!!!
- 如何在做安装程序里注册自己的.dll呢???
- 急需软件安装程序的下载地址(最好有汉化包)。
- 关于VS2012使用InstallShield打包水晶报表的问题
- 难道VB写ASP组件就这么麻烦吗??
- 如何在动态程序中设置DataReport的纸张类型?
If App.PrevInstance Then
Title = App.Title
Call MsgBox("这程式已执行", vbOKOnly, vbCritical)
App.Title = "" '如此才不会Avtivate到自己
FM.Caption = ""
AppActivate Title 'activate先前就已行的程式
End
End If
to slay78(天灯石):
我应该怎么查msdn?我应该打入什么查询关键字?
让大家费心了!
Private Declare Function GlobalDeleteAtom Lib "kernel32" Alias "GlobalDeleteAtom" (ByVal nAtom As Integer) As Integer
Private Declare Function GlobalFindAtom Lib "kernel32" Alias "GlobalFindAtomA" (ByVal lpString As String) As Integer
原子其实就是系统的一个字符串
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPrivate mlMainForm As Long
Private msMainForm As StringPrivate Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_RESTORE = &HF120&
'激活窗口
Private Sub ActivateWin(ByVal lHwnd As Long)
Call SetForegroundWindow(lHwnd)
Call SendMessage(lHwnd, WM_SYSCOMMAND, SC_RESTORE, 0)
End Sub'枚举窗口回调函数
Private Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
On Error Resume Next
Dim sBuffer As String * 255, sText As String
Call GetWindowText(hwnd, sBuffer, 256)
sText = StrZToStr(sBuffer)
If msMainForm <> "" Then
sText = Mid(sText, 1, Len(msMainForm))
If sText = msMainForm Then mlMainForm = hwnd
End If
EnumChildProc = True
End FunctionPrivate Function StrZToStr(s As String) As String
If InStr(1, s, Chr$(0)) > 0 Then
StrZToStr = Left$(s, InStr(1, s, Chr$(0)) - 1)
Else
StrZToStr = s
End If
End FunctionSub Main()
On Error Resume Next
Dim lDHwnd As Long
If App.PrevInstance Then
lDHwnd = GetDesktopWindow
'打开窗口
msMainForm = "Form1"
If lDHwnd <> 0 Then Call EnumChildWindows(lDHwnd, AddressOf EnumChildProc, 0)
If mlMainForm <> 0 Then
'如果找到已经定义的窗口,激活该窗口,然后终止运行
Call ActivateWin(mlMainForm)
End
Else
frmMain.Show
End If
Else
frmMain.Show
End If
End Sub
1、你用了App.PrevInstance,这样只能是控制一个程序文件不被打开两次!我要问的是不同路径下的不同文件名的文件(但是是同一个程序,只是名字不同)!
2、用你的方法,如果我有两个不同的程序,但是窗体的名字都是FORM1,那岂不是会有问题!还是用系统原子好一些吧?怎么做?谢!
a="XXX只执行一次"
atom=GlobalFindAtom(a)
if atom=0 then
GlobalAddAtom(a)
else
MsgBox "程序运行中!"
end if
在程序结束删除原子:
dim atom as integer,a as string
a="XXX只执行一次"
atom=GlobalFindAtom(a)
GlobalDeleteAtom(atom)