关于程序间切换焦点的问题?

ysensen 2003-12-19 07:20:11
我想用shell调用一个外部的程序,并在两程序运行的时候,在我的程序和外部程序之间自动的切换。能实现吗?
具体怎么做?
...全文
13 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyl910 2003-12-20
【VB声明】
Private Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long

【说明】
将窗口设为系统的前台窗口。这个函数可用于改变用户目前正在操作的应用程序

【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError

【备注】
不应随便使用它,因为一旦程序突然从后台进入前台,可能会使用户产生迷惑

【参数表】
hwnd ----------- Long,带到前台的窗口

回复
dreamtou 2003-12-20
上面的是我的程序
Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const STATUS_PENDING = &H103&
Private Const PROCESS_QUERY_INFORMATION = &H400

Private Function RunShell(cmdline As String) As Boolean
Dim hProcess As Long
Dim ProcessID As Long
Dim ExitCodeLong As Long
Dim str1 As String
Me.Hide
ProcessID = Shell(cmdline, vbNormalFocus)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessID)
Do
Call GetExitCodeProcess(hProcess, ExitCodeLong)
DoEvents
Loop While ExitCodeLong = STATUS_PENDING
Call CloseHandle(hProcess)
RunShell = True
Me.Show
End Function
回复
dreamtou 2003-12-20
可以,只要有一个程序是你做的就行

Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const STATUS_PENDING = &H103&
Private Const PROCESS_QUERY_INFORMATION = &H400

Private Function RunShell(cmdline As String, Index As Integer) As Boolean
Dim hProcess As Long
Dim ProcessID As Long
Dim ExitCodeLong As Long
Dim str1 As String
Me.Hide
ProcessID = Shell(cmdline, vbNormalFocus)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessID)
If hProcess = 0 Then
Select Case Index
Case 0
MsgBox "无法启动输出分析平台", vbInformation, MyTitle
Case 1
MsgBox "无法启动物理解读平台", vbInformation, MyTitle
Case 2
MsgBox "无法启动研究试验平台", vbInformation, MyTitle
Case 3
MsgBox "无法启动Micaps程序", vbInformation, MyTitle
End Select
End If
Do
Call GetExitCodeProcess(hProcess, ExitCodeLong)
DoEvents
Loop While ExitCodeLong = STATUS_PENDING
Call CloseHandle(hProcess)
RunShell = True
Me.Show
End Function
回复
flc 2003-12-20
关注
学习
学习
回复
ysensen 2003-12-20
外部的程序不是vb的,
是不是不可能实现自动的在主程序和外部程序之间的焦点切换?
回复
coffeesky0131 2003-12-19
或者你用dovents
等那个程序运行完后,才切换回原来的程序。
回复
coffeesky0131 2003-12-19
你的外部等程序也是VB做的么。
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告