以下是代码:
Private Sub Form_load()
......
form2.show
XXXX
.......
END Sub
其中,XXXX以及后面的代码就是你原来希望的,d出消息框之后可以继续执行的代码(程序并未挂起,仍在执行)。
Form2 的代码:
在Form2中,“确定”按钮的名称为Command_sub1,“取消”按钮的名称为Command_sub2,以区别于Form1中的按钮。
Dim TimeLeft As Integer
Private Sub Form_load()
TimeLeft = 10
Timer1.Interval = 1000
Timer1.Enabled = True
Label_sub2.Caption = "若未决定,将在" &Str$(TimeLeft) &" 秒后继续。"
End Sub
Private Sub Timer1_Timer()
TimeLeft = TimeLeft - 1
Label_sub2.Caption = "若未决定,将在" &Str$(TimeLeft) &" 秒后继续。"
If TimeLeft = 0 Then
Timer1.Enabled = False
DoEvents
Call Command_sub1_Click
End If
End Sub
Private Sub Command_sub1_Click()
'此段是"确定"按钮要执行的
Unload Form2
Set Form2 = Nothing
End Sub
Private Sub Command_sub2_Click()
'此段是"取消"按钮代码
Unload Form2
Set Form2 = Nothing
End Sub
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or &HFFF)
Private Declare Function NtSuspendProcess Lib "ntdll.dll" (ByVal hProc As Long) As Long
Private Declare Function NtResumeProcess Lib "ntdll.dll" (ByVal hProc As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private hProcess As Long
Private Sub cmdClose_Click()
CloseHandle hProcess
End Sub
Private Sub cmdResume_Click()
If IsNumeric(txtPid.Text) Then
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, CLng(txtPid.Text))
If hProcess <>0 Then
NtResumeProcess hProcess '继续
'NtSuspendProcess 挂起
End If
End If
End Sub
Private Sub cmdTerminate_Click()
If hProcess Then
TerminateProcess hProcess, 0
Else
If IsNumeric(txtPid.Text) Then
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, CLng(txtPid.Text))
If hProcess <>0 Then
TerminateProcess hProcess, 0
End If
End If
End If
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)