Private Sub Form_Load() If App.PrevInstance = True Then MsgBox "程序已经运行" Me.WindowState = 2 End If End Sub
楼上的方法有点错误应该是 Private Sub Form_Load() If App.PrevInstance = True Then MsgBox "程序已经运行" '添加查询同一标题的窗体程序,然后发送消息最大化,使用APIEnd If End Sub
应该是 Private Sub Form_Load() If App.PrevInstance = True Then MsgBox "程序已经运行" '添加查询同一标题的窗体程序,然后发送消息最大化,使用API Unload me End If End Sub该方法还有毛病,就是 窗体先装载,后关闭更好的办法是使用 新过程,在里面创建Main过程然后在Main过程体里加判断代码
If App.PrevInstance = True Then 通過FindWindow()獲取窗口的句柄,再ShowWindow() End end if
用FindWindows函数检查主窗体是否被调用函数的声明格式: Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long其中lpClassName参数设置为vbNullString,WindowsNmae要为要检查窗体的标题。
’另一种思路 '首先该程序做个热键 我这个程序为F12,一按F12就最大化 If App.PrevInstance = True Then Unload Me Call keybd_event(VK_F12, 0, 0, 0) DoEvents Sleep 100 DoEvents Call keybd_event(VK_F12, 0, KEYEVENTF_KEYUP, 0) End End If
'按照 leolan(史留香)的思路 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Const SW_MAXIMIZE = 3Private Sub Form_Load() If App.PrevInstance Then Dim hwnd As Long, Title As String Title = Me.Caption Me.Caption = "xxx" hwnd = FindWindow(vbNullString, Title) Call ShowWindow(hwnd, SW_MAXIMIZE) End End If End Sub
模块中加入:private sub main() If App.PrevInstance = True Then MsgBox "程序已经运行!" End If end sub设置工程属性,启动对象设置为Sub Main
If App.PrevInstance = True Then
MsgBox "程序已经运行"
Me.WindowState = 2
End If
End Sub
Private Sub Form_Load()
If App.PrevInstance = True Then
MsgBox "程序已经运行"
'添加查询同一标题的窗体程序,然后发送消息最大化,使用APIEnd If
End Sub
Private Sub Form_Load()
If App.PrevInstance = True Then
MsgBox "程序已经运行"
'添加查询同一标题的窗体程序,然后发送消息最大化,使用API
Unload me
End If
End Sub该方法还有毛病,就是 窗体先装载,后关闭更好的办法是使用 新过程,在里面创建Main过程然后在Main过程体里加判断代码
通過FindWindow()獲取窗口的句柄,再ShowWindow()
End
end if
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long其中lpClassName参数设置为vbNullString,WindowsNmae要为要检查窗体的标题。
'首先该程序做个热键 我这个程序为F12,一按F12就最大化 If App.PrevInstance = True Then
Unload Me
Call keybd_event(VK_F12, 0, 0, 0)
DoEvents
Sleep 100
DoEvents
Call keybd_event(VK_F12, 0, KEYEVENTF_KEYUP, 0)
End
End If
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_MAXIMIZE = 3Private Sub Form_Load()
If App.PrevInstance Then
Dim hwnd As Long, Title As String
Title = Me.Caption
Me.Caption = "xxx"
hwnd = FindWindow(vbNullString, Title)
Call ShowWindow(hwnd, SW_MAXIMIZE)
End
End If
End Sub
If App.PrevInstance = True Then
MsgBox "程序已经运行!"
End If
end sub设置工程属性,启动对象设置为Sub Main
这么多方法呀
我以为就 argodon(天一) 这一种方法呢,
一定要学习
收藏了!