Results 1 to 19 of 19

Thread: Hide/Show all open windows

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Question Hide/Show all open windows

    Hey All,

    The test below works for me in Windows 98, but apparently doesn't work in
    Windows XP. Does anyone know how to hide/show all open windows?

    Thanks in advance,
    Ron

    I'm using VB5.
    Attached Files Attached Files

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Hide/Show all open windows

    not sure if this will help u.. but here is how u restore the showdesktop shortcut...

    If the Show Desktop icon is deleted from Quick Launch, the procedure below will recreate the file.

    Open Notepad and enter the following text:

    [Shell]
    Command=2
    IconFile=explorer.exe,3
    [Taskbar]
    Command=ToggleDesktop

    Save the new file as Show Desktop.scf then drag and drop the icon on the Quick Launch bar or whatever location you want the shortcut to appear.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: Hide/Show all open windows

    no...it doesn't help..........thanks anyway

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Hide/Show all open windows

    well y not create the file.. and shell it?

    Shell app.path & "\show desctop.scf"

    might work?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: Hide/Show all open windows

    are you trying to minimize the windows? or actually hide them ? are the windows parts of your application?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Hide/Show all open windows

    How about using my codebank example?

    http://www.vbforums.com/showthread.php?t=360571
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: Hide/Show all open windows

    Sorry, I guess I didn't explain it very well...

    Let's say I have Eudora, Office, Notepad, and a couple of Internet Explorer
    windows open. I'm trying to hide them with a click of a button, and then
    show them again clicking another button.

    In the code I posted above, the minimize works in XP, but the hide does not.

    Any ideas?

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Hide/Show all open windows

    You could try my CWindows class ...

    VB Code:
    1. Dim windows As CWindows, window As CWindow
    2. windows.GetWindows
    3.  
    4. For Each window In windows
    5.     window.Hide
    6. Next

    Downloadable from here

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: Hide/Show all open windows

    thanks penagate...but I get a syntax error on line 79

    VB Code:
    1. Public Property Get HWNDs() As Long()

    I'm using VB5

  10. #10
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Hide/Show all open windows

    This doesn't do the trick but it will not show any programs in the bottom, but people can still open them by using ALT+Tab.

    In your module, make the following changes.

    VB Code:
    1. Public Function HideProgramsShowingInTaskBar()
    2.     Dim FindClass As Long, FindClass2 As Long, Parent As Long, Handle As Long
    3.    
    4.     FindClass& = FindWindow("Shell_TrayWnd", "")
    5.     FindClass2& = FindWindowEx(FindClass&, 0, "ReBarWindow32", vbNullString)
    6.     Parent& = FindWindowEx(FindClass2&, 0, "MSTaskSwWClass", vbNullString)
    7.     Handle& = FindWindowEx(Parent&, 0, "[B]ToolbarWindow32[/B]", vbNullString)
    8.     ShowWindow Handle&, 0
    9. End Function
    10.  
    11. Public Function ShowProgramsShowingInTaskBar()
    12.     Dim FindClass As Long, FindClass2 As Long, Parent As Long, Handle As Long
    13.    
    14.     FindClass& = FindWindow("Shell_TrayWnd", "")
    15.     FindClass2& = FindWindowEx(FindClass&, 0, "ReBarWindow32", vbNullString)
    16.     Parent& = FindWindowEx(FindClass2&, 0, "MSTaskSwWClass", vbNullString)
    17.     Handle& = FindWindowEx(Parent&, 0, "[B]ToolbarWindow32[/B]", vbNullString)
    18.     ShowWindow Handle&, 1
    19. End Function

    I accept no responsibility for any damage any code i provide causes to you or to your possessions.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: Hide/Show all open windows

    thanks andrew........but in win98 it shows the programs in the taskbar like the
    original code did in xp.

  12. #12
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Hide/Show all open windows

    Ah, so you want it to work for any version of windows. No probs

    VB Code:
    1. Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
    2. Private Type OSVERSIONINFO
    3.     dwOSVersionInfoSize As Long
    4.     dwMajorVersion As Long
    5.     dwMinorVersion As Long
    6.     dwBuildNumber As Long
    7.     dwPlatformId As Long
    8.     szCSDVersion As String * 128
    9. End Type
    10. Private Sub Form_Load()
    11.     Dim OSInfo As OSVERSIONINFO, PId As String
    12.     OSInfo.dwOSVersionInfoSize = Len(OSInfo)
    13.     Ret& = GetVersionEx(OSInfo)
    14.     If OSInfo.dwPlatformId = 2 Then
    15.         'Win NT or XP
    16.     End If
    17. End Sub

    or

    VB Code:
    1. Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Long
    2. Private Type OSVERSIONINFO
    3.     dwOSVersionInfoSize As Long
    4.     dwMajorVersion As Long
    5.     dwMinorVersion As Long
    6.     dwBuildNumber As Long
    7.     dwPlatformId As Long
    8.     szCSDVersion As String * 128
    9. End Type
    10. Private Enum Enum_OperatingPlatform
    11.   Platform_Windows_32 = 0
    12.   Platform_Windows_95_98_ME = 1
    13.   Platform_Windows_NT_2K_XP = 2
    14. End Enum
    15. Private Enum Enum_OperatingSystem
    16.   System_Windows_32 = 0
    17.   System_Windows_95 = 1
    18.   System_Windows_98 = 2
    19.   System_Windows_ME = 3
    20.   System_Windows_NT = 4
    21.   System_Windows_2K = 5
    22.   System_Windows_XP = 6
    23. End Enum
    24.  
    25.  
    26. Private Sub Form_Load()
    27.     Select Case OperatingSystem
    28.         Case System_Windows_32: msgbox "Windows 32"
    29.         Case System_Windows_95: msgbox  "Windows 95"
    30.         Case System_Windows_98: msgbox "Windows 98"
    31.         Case System_Windows_ME: msgbox "Windows ME"
    32.         Case System_Windows_NT: msgbox  "Windows NT"
    33.         Case System_Windows_2K: msgbox "Windows 2K"
    34.         Case System_Windows_XP: msgbox  "Windows XP"
    35.     End Select
    36. End Sub
    37. Private Function OperatingSystem() As Enum_OperatingSystem
    38.     Dim lpVersionInformation As OSVERSIONINFO
    39.     lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
    40.     Call GetVersionExA(lpVersionInformation)
    41.     If (lpVersionInformation.dwPlatformId = Platform_Windows_32) Then
    42.         OperatingSystem = System_Windows_32
    43.     ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 0) Then
    44.         OperatingSystem = System_Windows_95
    45.     ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 10) Then
    46.         OperatingSystem = System_Windows_98
    47.     ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_95_98_ME) And (lpVersionInformation.dwMinorVersion = 90) Then
    48.         OperatingSystem = System_Windows_ME
    49.     ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion < 5) Then
    50.         OperatingSystem = System_Windows_NT
    51.     ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 5) And (lpVersionInformation.dwMinorVersion = 0) Then
    52.         OperatingSystem = System_Windows_2K
    53.     ElseIf (lpVersionInformation.dwPlatformId = Platform_Windows_NT_2K_XP) And (lpVersionInformation.dwMajorVersion = 5) And (lpVersionInformation.dwMinorVersion = 1) Then
    54.         OperatingSystem = System_Windows_XP
    55.     End If
    56. End Function
    Is a bit more accurate

    Gets the version of windows. In you code, you need to set a public bolean to check if its XP, and if it is then use the code i modified, if it isn't then use the original code.
    Last edited by Andrew G; Dec 21st, 2005 at 08:15 PM.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: Hide/Show all open windows

    Here is some code I use to hide/show all IE windows.

    VB Code:
    1. Option Explicit
    2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    3. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    4.  
    5. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    6. (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal _
    7. lpsz2 As String) As Long
    8.  
    9. Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
    10. ByVal nCmdShow As Long) As Long
    11.  
    12. Private Function HideAllIEWindows()
    13.     Dim l As Long
    14.  
    15.     l = FindWindow("IEFrame", vbNullString)
    16.    
    17.    
    18.     If l <> 0 Then
    19.         ShowWindow l, 0
    20.     End If
    21.    
    22.     Do Until l = 0
    23.         l = FindWindowEx(0, l, "IEFrame", vbNullString)
    24.        
    25.        
    26.         If l <> 0 Then
    27.             ShowWindow l, 0
    28.         End If
    29.     Loop
    30.  
    31. End Function
    32.  
    33. Private Function ShowAllIEWindows()
    34.     Dim l As Long
    35.  
    36.     l = FindWindow("IEFrame", vbNullString)
    37.    
    38.    
    39.     If l <> 0 Then
    40.         ShowWindow l, 1
    41.     End If
    42.    
    43.     Do Until l = 0
    44.         l = FindWindowEx(0, l, "IEFrame", vbNullString)
    45.                
    46.         If l <> 0 Then
    47.             ShowWindow l, 1
    48.         End If
    49.     Loop
    50.  
    51. End Function
    52.  
    53. Private Sub Command1_Click()
    54.     Call HideAllIEWindows
    55. End Sub
    56.  
    57. Private Sub Command2_Click()
    58.     Call ShowAllIEWindows
    59. End Sub

    Is there some way to loop through all open programs and get the name
    of each program, and replace the "IEFrame" each time it loops?

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: Hide/Show all open windows

    hey andrew, I appreciate the help, but I wish I could find a way to do this
    like the code I just posted (cannot be seen with alt + tab).

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: Hide/Show all open windows

    Hey... I just found this in a search at VB Helper

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetTopWindow Lib "user32" (ByVal hwnd As Long) As Long
    4. Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
    5. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    6. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    7. Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
    8. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    9. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    10.  
    11. Private Const GW_HWNDFIRST = 0
    12. Private Const GW_HWNDNEXT = 2
    13. Private Const GWL_STYLE = (-16)
    14. Private Const GWL_HWNDPARENT = (-8)
    15. Private Const WS_OVERLAPPED = &H0&
    16. Private Const WS_BORDER = &H800000
    17. Private Const WS_DLGFRAME = &H400000
    18. Private Const WS_CAPTION = WS_BORDER Or WS_DLGFRAME
    19. Private Const WS_SYSMENU = &H80000
    20. Private Const WS_THICKFRAME = &H40000
    21. Private Const WS_MINIMIZEBOX = &H20000
    22. Private Const WS_MAXIMIZEBOX = &H10000
    23. Private Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
    24. ' Return information about this window.
    25. Private Sub GetWindowInfo(ByVal app_hwnd As Long, ByRef app_parent As Long, ByRef app_owner As Long, ByRef app_visible As Boolean, ByRef app_style As Long, ByRef app_text As String, ByRef app_class As String)
    26. Const MAX_LENGTH = 1024
    27.  
    28. Dim buf As String * MAX_LENGTH
    29. Dim length As Long
    30.  
    31.     app_parent = GetParent(app_hwnd)
    32.     app_owner = GetWindowLong(app_hwnd, GWL_HWNDPARENT)
    33.     app_visible = IsWindowVisible(app_hwnd)
    34.     app_style = GetWindowLong(app_hwnd, GWL_STYLE)
    35.  
    36.     length = GetWindowText(app_hwnd, buf, MAX_LENGTH)
    37.     app_text = Left$(buf, length)
    38.  
    39.     length = GetClassName(app_hwnd, buf, MAX_LENGTH)
    40.     app_class = Left$(buf, length)
    41. End Sub
    42. Private Sub Form_Load()
    43. Dim app_hwnd As Long
    44. Dim app_parent As Long
    45. Dim app_owner As Long
    46. Dim app_visible As Boolean
    47. Dim app_style As Long
    48. Dim app_text As String
    49. Dim app_class As String
    50. Dim wid As Single
    51. Dim col_wid() As Single
    52. Dim r As Integer
    53. Dim c As Integer
    54.  
    55.     MSFlexGrid1.FixedRows = 1
    56.     MSFlexGrid1.FixedCols = 0
    57.     MSFlexGrid1.Rows = 1
    58.     MSFlexGrid1.Cols = 3
    59.     MSFlexGrid1.TextMatrix(0, 0) = "hWnd"
    60.     MSFlexGrid1.TextMatrix(0, 1) = "Text"
    61.     MSFlexGrid1.TextMatrix(0, 2) = "Class"
    62.         GetWindowInfo app_hwnd, app_parent, app_owner, _
    63.             app_visible, app_style, app_text, app_class
    64.  
    65.     app_hwnd = GetTopWindow(0)
    66.     r = 1
    67.     Do While app_hwnd <> 0
    68.         ' Get information about this window.
    69.         GetWindowInfo app_hwnd, app_parent, app_owner, _
    70.             app_visible, app_style, app_text, app_class
    71.  
    72.         ' See if this window is interesting.
    73.         If app_visible And _
    74.             app_parent = 0 And _
    75.             app_owner = 0 And _
    76.             Len(app_text) > 0 And _
    77.             Left$(app_text, 8) <> "VBBubble" And _
    78.             (Left$(app_class, 7) <> "Progman" Or _
    79.                 (app_style And WS_OVERLAPPEDWINDOW) <> 0) _
    80.         Then
    81.             MSFlexGrid1.Rows = r + 1
    82.             MSFlexGrid1.TextMatrix(r, 0) = app_hwnd
    83.             MSFlexGrid1.TextMatrix(r, 1) = app_text
    84.             MSFlexGrid1.TextMatrix(r, 2) = app_class
    85.             r = r + 1
    86.         End If
    87.  
    88.         app_hwnd = GetNextWindow(app_hwnd, GW_HWNDNEXT)
    89.     Loop
    90.  
    91.     ' Size the columns.
    92.     ReDim col_wid(0 To MSFlexGrid1.Cols - 1)
    93.     For r = 0 To MSFlexGrid1.Rows - 1
    94.         For c = 0 To MSFlexGrid1.Cols - 1
    95.             wid = TextWidth(MSFlexGrid1.TextMatrix(r, c)) + 240
    96.             If col_wid(c) < wid Then col_wid(c) = wid
    97.         Next c
    98.     Next r
    99.  
    100.     For c = 0 To MSFlexGrid1.Cols - 1
    101.         MSFlexGrid1.ColWidth(c) = col_wid(c)
    102.     Next c
    103. End Sub
    104. Private Sub Form_Resize()
    105.     MSFlexGrid1.Move 0, 0, ScaleWidth, ScaleHeight
    106. End Sub

    Now, this works well in Win98. Could someone would check to see if this works
    in XP?

    If it does, then I still would have to figure out how to use a Listbox
    instead of a MSFlexGrid, and then implement it into the "IEFrame" code (loop)
    above.

    Am I even making any sense...my little pea brain is tired! thanks guys

  16. #16
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Hide/Show all open windows

    Quote Originally Posted by rdcody
    thanks penagate...but I get a syntax error on line 79

    VB Code:
    1. Public Property Get HWNDs() As Long()

    I'm using VB5
    Delete that property routine then. The ability to return an array from a function was introduced in VB6.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: Hide/Show all open windows

    Hey fellers...I may have figured it out...try this please

    works in win98
    Attached Files Attached Files

  18. #18
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: Hide/Show all open windows

    Quote Originally Posted by RobDog888
    How about using my codebank example?

    http://www.vbforums.com/showthread.php?t=360571
    lol once again theres a MUCH easier way to do it
    add in a ms shell and automation control and put thise code

    VB Code:
    1. dim b as new shell
    2. b.MinimizeAll

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Hide/Show all open windows

    Yes, I remembered that but couldnt remember exactly where or how.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width