感谢您使用微软产品。您可以根据程序窗口的Caption获得窗口的句柄,显示该窗口,您还可以把通过ForegroundWindow函数,使您的vb程序窗口或被最大化的程序窗口获得输入焦点。涉及FindWindow,ShowWindow,SetForegroundWindow三个API函数。 如下例,使记事本程序窗口最大化。Private Declare Function SetForegroundWindow Lib "user32" _ (ByVal hwnd As Long) As LongPrivate Declare Function ShowWindow Lib "user32" _ (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongPrivate Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Const SW_MAXIMIZE = 3 Const SW_MINIMIZE = 6Private Sub Command1_Click() Dim hWindow As Long Dim lngResult As Long Dim lngReturnValue As Long hWindow = FindWindow(vbNullString, "Untitled - Notepad") lngReturnValue = ShowWindow(hWindow, SW_MAXIMIZE) '或SW_MINIMIZE lngReturnValue = SetForegroundWindow(Form1.hwnd) ‘ 或 lngReturnValue = SetForegroundWindow(hWindow)End Sub详细信息请参考以下链接: FindWindow http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_03sn.asp ShowWindow http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_2tdj.asp SetForegroundWindow http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_1eev.asp - 微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款 (http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。 为了为您创建更好的讨论环境,请参加我们的用户满意度调查 (http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
详细参见msdn
如下例,使记事本程序窗口最大化。Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As LongPrivate Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As LongPrivate Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Const SW_MAXIMIZE = 3
Const SW_MINIMIZE = 6Private Sub Command1_Click() Dim hWindow As Long
Dim lngResult As Long
Dim lngReturnValue As Long hWindow = FindWindow(vbNullString, "Untitled - Notepad")
lngReturnValue = ShowWindow(hWindow, SW_MAXIMIZE) '或SW_MINIMIZE
lngReturnValue = SetForegroundWindow(Form1.hwnd)
‘ 或 lngReturnValue = SetForegroundWindow(hWindow)End Sub详细信息请参考以下链接:
FindWindow
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_03sn.asp
ShowWindow
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_2tdj.asp
SetForegroundWindow
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/windows_1eev.asp
- 微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。