我们时常会看到某些软件有这样的功能.
当程序已经运行的时候再运行这个程序程序会把以前运行的主界面显示在前台来.下面代码就是这个功能.
VERSION 5.00
Begin VB.Form frmMain
Caption = "李小俊是个猪头"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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 Form_Load()
Me.WindowState = 1
If App.PrevInstance Then
Me.Caption = ""
Dim hWnd As Long
hWnd = FindWindow(vbNullString, "李小俊是个猪头")
If hWnd > 0 Then
SendMessage hWnd, WM_SYSCOMMAND, SC_RESTORE, 0
SetForegroundWindow hWnd
Unload Me: End
End If
End If
End Sub