VB如何同时隐藏两个一样的窗口

我打开两个“计算器”窗口,都处于可见状态,现在我要用VB6实现点击COMMAND1以后,两个“计算器”窗口,同时被隐藏,程序退出时,两个窗口同时恢复可见。... 我打开两个“计算器”窗口,都处于可见状态,现在我要用VB6实现点击COMMAND1以后,两个“计算器”窗口,同时被隐藏,程序退出时,两个窗口同时恢复可见。 展开
 我来答
shaoyedh
2011-04-25 · TA获得超过102个赞
知道小有建树答主
回答量:150
采纳率:0%
帮助的人:104万
展开全部
一个模块代码
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_NORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10
Public Const SW_FORCEMINIMIZE = 11
Public Const SW_MAX = 11

Public Const WM_CLOSE = &H10
Public Function EnumProc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean '遍查主窗口
Dim buf As String * 1024
Dim length As Long

length = GetWindowText(app_hwnd, buf, Len(buf))
Title = Left$(buf, length)
If Title = "计算器" Then
ShowWindow Val(app_hwnd), SW_HIDE

End If
EnumProc = 1
End Function

Public Function EnumProcSHOW(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean '遍查主窗口
Dim buf As String * 1024
Dim length As Long

length = GetWindowText(app_hwnd, buf, Len(buf))
Title = Left$(buf, length)
If Title = "计算器" Then
ShowWindow Val(app_hwnd), SW_SHOW

End If
EnumProc = 1
End Function
click事件调用隐藏窗体
EnumWindows AddressOf EnumProc, 0 '枚举窗口列表中的所有父窗口(顶级和被所有窗口)
完毕
unload调用 显示窗体 这里一定是要窗体unload事件 某些时候直接end程序不会执行unload事件
EnumWindows AddressOf EnumProcSHOW, 0 '枚举窗口列表中的所有父窗口(顶级和被所有窗口)
由于条件有限没有测试 但是用法都在这里 你应该还需要修改下
更多追问追答
追问
不行哦。按照你的代码,点击COMMAND1以后,一点反应都没有。两个计算器窗口都还在。并且关闭窗体时,还出现一个错误。
追答
模块代码
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_NORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10
Public Const SW_FORCEMINIMIZE = 11
Public Const SW_MAX = 11

Public Const WM_CLOSE = &H10
Public Function EnumProc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean '遍查主窗口
Dim buf As String * 1024
Dim length As Long

length = GetWindowText(app_hwnd, buf, Len(buf))
Title = Left$(buf, length)
Form1.List1.AddItem app_hwnd & " Name is :" & Title

EnumProc = 1
End Function
窗体里面有个list1 一个按钮用来hide
按钮事件
If List1.Text "" Then
ShowWindow Val(List1.Text), SW_HIDE

List1.RemoveItem List1.ListIndex

End If
这是一个能够隐藏任何窗口的代码 你改改看吧
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式