(2)相邻exe工程之间的转接;
各届邮集都是exe格式的文件,它们之间的转换有两个途径;***第一个途径——任一届奥运邮集的首页和尾页,都有转到前一届或后一届的按钮来完成转换。
由于转一另一届是需要打开exe格式的文件,所以需要用下面的特殊的代码:
Shell "rundll32.exe url.dll,FileProtocolHandler " & App.Path & "\XJ9.exe", vbMaximizedFocus
注:XJ9.exe为将被打开的新一届邮集。
提示:采用这种从一个exe文件转换一另一个exe文件时,原来的已打开的文件仍在进程中,而未被关闭;而采用下面的方法,打开一个新的exe文件后,就会关闭前面所有的已打开文件。
这一段代码看似简单,但偶也是在很多论坛上才求教得到的,也曾来之不易。如果您今后设计软件遇到exe文件之间的转换或许能用得上,如果您有更好的代码也希望在这里交流。
***第二个途径——通过屏幕左侧的悬浮窗体上的导航钮(见图)。这一方式转换的特点是,打开某一届后,就会自动关闭掉前面其它已打开的各届。实现这一方式的代码举例如下:(有一段声明)
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "USER32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Const PROCESS_TERMINATE = 1
Private Sub Command3_Click()
Dim Ltem As Long
Dim LpID As Long
Dim hLong As Long
Dim strWinName As String
strWinName = "第1届" ‘被关闭的所有届都要有相应这样的一组代码;
hLong = FindWindow(vbNullString, strWinName)
If hLong Then
GetWindowThreadProcessId hLong, LpID
Ltem = OpenProcess(PROCESS_TERMINATE, False, LpID)
TerminateProcess Ltem, 0
hLong = 0
End If
strWinName = "第2届"
hLong = FindWindow(vbNullString, strWinName)
If hLong Then
GetWindowThreadProcessId hLong, LpID
Ltem = OpenProcess(PROCESS_TERMINATE, False, LpID)
TerminateProcess Ltem, 0
hLong = 0
End If
Shell "rundll32.exe url.dll,FileProtocolHandler " & App.Path & "\xj3.exe", vbMaximizedFocus
End Sub
提示:由于目前夏季奥运会有29届,所以打开一届,就要设置关闭其它28届的28组代码,一个程序代码重复而又庞大。不知是否还有更好的代码?
[[it] 本帖最后由 jrs123 于 2008-5-3 19:57 编辑 [/it]]