I took the liberty to fix (it doesn't work) and improve Matty's code.... sorry matty
code:
Option Explicit
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0
Private Const SW_SHOWNA = 8
' The callback function. This MUST be in a normal module (not a class module)
Private Function CallBack(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim lResult As Long
Dim sClassName As String * 260
lResult = GetClassName(hWnd, sClassName, Len(sClassName))
If LCase$(Left$(sClassName, lResult)) = "msgplusfloatingwindow" Then
If lParam Then
ShowWindow hWnd, SW_SHOWNA
Else
ShowWindow hWnd, SW_HIDE
End If
End If
CallBack = True
End Function
' Two seperate public procedures to show and hide the windows
Public Sub ShowFloatingWindows()
EnumWindows AddressOf CallBack, True
End Sub
Public Sub HideFloatingWindows()
EnumWindows AddressOf CallBack, False
End Sub
' Only one public procedure which can do both (with optional parameter)
' To show windows: FloatingWindowsState True
' To hide windows: FloatingWindowsState False
' If the (true/false) parameter is omitted it will also show the windows
Public Sub FloatingWindowsState(Optional State As Boolean = True)
EnumWindows AddressOf CallBack, State
End Sub
Note 1: as you can see you don't need the two seperate procedures, you can do it with one also. It depends on what you prefer I assume...
To make the code even shorter you can also do this
code:
If LCase$(Left$(sClassName, lResult)) = "msgplusfloatingwindow" Then
ShowWindow hWnd, -lParam * 8
End If
In that way you don't even need the private constants anymore and the code gets even smaller (because there is no need for the second IF THEN ELSE anymore)...
Note 2: As you'll notice I didn't use the SW_NORMAL constant as others would do, but the SW_SHOWNA constant instead. This is because SW_NORMAL will also make the floating windows active (it sets the focus to them), SW_SHOWNA does not. More info on this can be found in the
MSDN library: ShowWindow.
Download the attachment for the complete VB6 project files (using the short method)
-------------------------------
EDIT: The included compiled exe file has basically the same functionality as the one from Fergy. But it will not loose focus (because I used SW_SHOWNA instead of SW_NORMAL) when you show the floating windows. And you can also start it up with a parameter "hide" or "show":
plusfloatingwindows => Will start up as normal and will show you the two buttons
plusfloatingwindows hide => Will hide the floating windows immediatly without showing any window
plusfloatingwindows show => Will show the floating windows immediatly without showing any window (in fact, instead of "show" you can use whatever you like
)
Note: as it is an VB program it requires the useuall VB6 runtime library to be present on your system (MSVBVM60.DLL), if you don't have it (aka if you get an error when you start the program) download it
here and install it.