1,488
社区成员
发帖
与我相关
我的任务
分享Option Explicit
Private Sub cmdToggle_Click()
If cmdToggle.Caption = "&Hide VB" Then
HideVB
cmdToggle.Caption = "&Show VB"
cmdToggle.ToolTipText = "Show the Visual Basic IDE"
Else
ShowVB
cmdToggle.Caption = "&Hide VB"
cmdToggle.ToolTipText = "Hide the Visual Basic IDE"
Show
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
ShowVB
End Sub
Option Explicit
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal aint As Integer) As Integer
Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Integer) As Integer
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Public Const SW_HIDE = 0
Public Const SW_SHOW = 5
Sub HideVB()
Dim CurhWnd As Long
Dim i As Integer
CurhWnd = FindWindowPartial("Microsoft Visual Basic")
i = ShowWindow(CurhWnd, SW_HIDE)
CurhWnd = FindWindowPartial("CONJURE.MAK")
i = ShowWindow(CurhWnd, SW_HIDE)
End Sub
Sub ShowVB()
Dim CurhWnd As Long
Dim i As Integer
CurhWnd = FindWindowPartial("Microsoft Visual Basic")
i = ShowWindow(CurhWnd, SW_SHOW)
CurhWnd = FindWindowPartial("CONJURE.MAK")
i = ShowWindow(CurhWnd, SW_SHOW)
End Sub
Function FindWindowPartial(ByVal TitlePart As String) As Long
Dim hWndTmp As Long
Dim nRet As Integer
Dim TitleTmp As String
Const GW_HWNDNEXT = 2
'We alter the title to compare it case-insensitively.
TitlePart = UCase$(TitlePart)
'First find all the open windows so we can
'loop through them and find the right one.
hWndTmp = FindWindow(0&, 0&)
Do Until hWndTmp = 0
TitleTmp = VBA.Space$(256)
nRet = GetWindowText(hWndTmp, TitleTmp, Len(TitleTmp))
If nRet Then
'Let's prepare to compare ;)
TitleTmp = UCase(VBA.Left$(TitleTmp, nRet))
'Now we see if the window we chased down actually
'has the caption we want.
If InStr(TitleTmp, TitlePart) Then
FindWindowPartial = hWndTmp
Exit Do
End If
End If
hWndTmp = GetWindow(hWndTmp, GW_HWNDNEXT)
Loop
End Function