|
-
Jun 24th, 2006, 09:24 AM
#1
Re: Find all open windows to close
you already are - that is what EnumWindows does.
-
Jun 24th, 2006, 10:20 AM
#2
PowerPoster
Re: Find all open windows to close
see post #11 .. title = Window Name of Every Open window ..
-
Jun 24th, 2006, 06:28 PM
#3
Thread Starter
Fanatic Member
-
Jun 24th, 2006, 06:39 PM
#4
Thread Starter
Fanatic Member
Re: Find all open windows to close
Never mind people, I got some code my self.
VB Code:
Option Explicit
Global qwerty As Integer
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
' Process And Memory
Private Declare Function GetWindowThreadProcessId Lib "user32" ( _
ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" ( _
ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32" ( _
ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" ( _
ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal flAllocationType As Long, _
ByVal flProtect As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" ( _
ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, _
Optional lpNumberOfBytesWritten As Long) As Long
Const PROCESS_VM_READ = (&H10)
Const PROCESS_VM_WRITE = (&H20)
Const PROCESS_VM_OPERATION = (&H8)
Const MEM_COMMIT = &H1000
Const MEM_RESERVE = &H2000
Const MEM_RELEASE = &H8000
Const PAGE_READWRITE = &H4
Const WM_USER = &H400
Const TB_ISBUTTONHIDDEN = (WM_USER + 12)
Const TB_BUTTONCOUNT = (WM_USER + 24)
Const TB_GETBUTTONTEXTA = (WM_USER + 45)
Public Sub ShowOpenWindows()
Dim hTaskBar As Long, pID As Long, hProcess As Long
Dim N As Long, lCount As Long, lNum As Long, lLen As Long
Dim sCaption As String * 128, lpCaption As Long
hTaskBar = GetNotificationWindow
GetWindowThreadProcessId hTaskBar, pID
hProcess = OpenProcess(PROCESS_VM_READ Or PROCESS_VM_WRITE Or PROCESS_VM_OPERATION, 0, pID)
lpCaption = VirtualAllocEx(hProcess, ByVal 0&, Len(sCaption), MEM_COMMIT Or MEM_RESERVE, PAGE_READWRITE)
lNum = SendMessage(hTaskBar, TB_BUTTONCOUNT, 0, ByVal 0&)
Do Until lCount = lNum
lLen = SendMessage(hTaskBar, TB_GETBUTTONTEXTA, N, ByVal lpCaption)
If lLen > -1 Then
If SendMessage(hTaskBar, TB_ISBUTTONHIDDEN, N, 0&) = 0 Then
ReadProcessMemory hProcess, ByVal lpCaption, ByVal sCaption, Len(sCaption)
For qwerty = 0 To 5
Form1.lstwindows(qwerty).AddItem Left$(sCaption, InStr(sCaption, vbNullChar) - 1)
Next qwerty
End If
lCount = lCount + 1
End If
N = N + 1
Loop
VirtualFreeEx 0, lpCaption, 0, MEM_RELEASE
CloseHandle hProcess
End Sub
Private Function GetNotificationWindow() As Long
Dim lhWnd As Long
lhWnd = FindWindowEx(0&, 0&, "Shell_TrayWnd", vbNullString)
lhWnd = FindWindowEx(lhWnd, 0&, "ReBarWindow32", vbNullString)
lhWnd = FindWindowEx(lhWnd, 0&, "MSTaskSwWClass", vbNullString)
GetNotificationWindow = FindWindowEx(lhWnd, 0&, "ToolbarWindow32", vbNullString)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|