Results 1 to 25 of 25

Thread: [RESOLVED] Find all open windows to close

Hybrid View

  1. #1
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Find all open windows to close

    you already are - that is what EnumWindows does.

  2. #2
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Find all open windows to close

    see post #11 .. title = Window Name of Every Open window ..

  3. #3

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking Re: Find all open windows to close

    Hmmmm... That code works perfectly, except for one crucial thing: it lists like 60 things, processes and hidden windows and all sorts of useless crap, I just want to 4-9 windws I have open - i.e. anything I can see, or anything in the task bar. Any way to mod that code toonly shot that which is in the task bar? Any suggestions greatly appreciated!
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  4. #4

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking Re: Find all open windows to close

    Never mind people, I got some code my self.

    VB Code:
    1. Option Explicit
    2.  
    3. Global qwerty As Integer
    4.  
    5. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    6.     ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    7.    
    8. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    9.     ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    10.    
    11. ' Process And Memory
    12. Private Declare Function GetWindowThreadProcessId Lib "user32" ( _
    13.     ByVal hWnd As Long, lpdwProcessId As Long) As Long
    14.    
    15. Private Declare Function OpenProcess Lib "kernel32" ( _
    16.     ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    17.    
    18. Private Declare Function CloseHandle Lib "kernel32" ( _
    19.     ByVal hObject As Long) As Long
    20.    
    21. Private Declare Function VirtualFreeEx Lib "kernel32" ( _
    22.     ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal dwFreeType As Long) As Long
    23.    
    24. Private Declare Function VirtualAllocEx Lib "kernel32" ( _
    25.     ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal flAllocationType As Long, _
    26.     ByVal flProtect As Long) As Long
    27.    
    28. Private Declare Function ReadProcessMemory Lib "kernel32" ( _
    29.     ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, _
    30.     Optional lpNumberOfBytesWritten As Long) As Long
    31.  
    32. Const PROCESS_VM_READ = (&H10)
    33. Const PROCESS_VM_WRITE = (&H20)
    34. Const PROCESS_VM_OPERATION = (&H8)
    35. Const MEM_COMMIT = &H1000
    36. Const MEM_RESERVE = &H2000
    37. Const MEM_RELEASE = &H8000
    38. Const PAGE_READWRITE = &H4
    39.  
    40. Const WM_USER = &H400
    41. Const TB_ISBUTTONHIDDEN = (WM_USER + 12)
    42. Const TB_BUTTONCOUNT = (WM_USER + 24)
    43. Const TB_GETBUTTONTEXTA = (WM_USER + 45)
    44.  
    45. Public Sub ShowOpenWindows()
    46.     Dim hTaskBar As Long, pID As Long, hProcess As Long
    47.     Dim N As Long, lCount As Long, lNum As Long, lLen As Long
    48.     Dim sCaption As String * 128, lpCaption As Long
    49.      
    50.     hTaskBar = GetNotificationWindow
    51.     GetWindowThreadProcessId hTaskBar, pID
    52.     hProcess = OpenProcess(PROCESS_VM_READ Or PROCESS_VM_WRITE Or PROCESS_VM_OPERATION, 0, pID)
    53.    
    54.     lpCaption = VirtualAllocEx(hProcess, ByVal 0&, Len(sCaption), MEM_COMMIT Or MEM_RESERVE, PAGE_READWRITE)
    55.     lNum = SendMessage(hTaskBar, TB_BUTTONCOUNT, 0, ByVal 0&)
    56.    
    57.     Do Until lCount = lNum
    58.         lLen = SendMessage(hTaskBar, TB_GETBUTTONTEXTA, N, ByVal lpCaption)
    59.         If lLen > -1 Then
    60.             If SendMessage(hTaskBar, TB_ISBUTTONHIDDEN, N, 0&) = 0 Then
    61.                 ReadProcessMemory hProcess, ByVal lpCaption, ByVal sCaption, Len(sCaption)
    62.                   For qwerty = 0 To 5
    63.                      Form1.lstwindows(qwerty).AddItem Left$(sCaption, InStr(sCaption, vbNullChar) - 1)
    64.                   Next qwerty
    65.             End If
    66.             lCount = lCount + 1
    67.         End If
    68.         N = N + 1
    69.     Loop
    70.        
    71.     VirtualFreeEx 0, lpCaption, 0, MEM_RELEASE
    72.     CloseHandle hProcess
    73. End Sub
    74.  
    75. Private Function GetNotificationWindow() As Long
    76.     Dim lhWnd As Long
    77.     lhWnd = FindWindowEx(0&, 0&, "Shell_TrayWnd", vbNullString)
    78.     lhWnd = FindWindowEx(lhWnd, 0&, "ReBarWindow32", vbNullString)
    79.     lhWnd = FindWindowEx(lhWnd, 0&, "MSTaskSwWClass", vbNullString)
    80.     GetNotificationWindow = FindWindowEx(lhWnd, 0&, "ToolbarWindow32", vbNullString)
    81. End Function

    Don't recoall now where I got it, but if I got it from VBForums, and it was yours, let me know so I can reputate and thank you.
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

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