各位老师 帮我看看
你好
是这样的,我准备做个程序可以控制其他程序,效果是,单击我的程序,就可以把别的程序从窗口中显示出来,变成有焦点的(前提是被控制的程序已经打开)。麻烦各位老师给学生指点一下,为已经做到查询被控的程序是否运行,但怎么得到焦点,就不知道了。恳请帮吗给解决一下。谢谢
Dim NowFhWnd As Long '当前拥有焦点窗口句柄
Dim FindhWnd As Long '查找窗口的句柄
Dim FindRect As RECT '查找窗口的矩形
Dim MinRect As RECT '最小化的矩形
Dim MaxRect As RECT '最大化的矩形
Dim Zt As String
With MinRect
.Bottom = 0
.Left = 0
.Right = 0
.Top = 0
End With
Call GetClientRect(GetDesktopWindow, MaxRect)
NowFhWnd = GetActiveWindow
FindhWnd = FindWindow(vbNullString, InputBox("请输入要查找窗口的标题、、(必填)"))
If FindhWnd = 0 Then MsgBox "找不到指定窗口": Exit Sub
If GetClientRect(FindhWnd, FindRect) = 0 Then MsgBox "获取指定窗体信息失败、":
‘这里就把找到的程序得到焦点,就像鼠标单击了窗口显示程序效果一样 谢谢
[最优解释]
实现方式很多,比如:
Private Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
BringWindowToTop &HF05E2
SetFocusAPI &HF05E2
End Sub
[其他解释]
还可以用SetForegroundWindow设置前台窗口。