Ask Question Forum:
C
O
M
P
U
T
E
R
2
8
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Y-position of the mouse cursor
Attachment:===
How to know other handles in one window in VBA

For example, in IE windows, there is so many handles shown by SPY++,, and I us
IE.hwnd to get IEframe handle id, how about other handles in the process could we list it
out. Please help provide direction and function code. I tried Enumwindow fucntion before
from one webiste tutorial at http://www.thescarms.com/vbasic/EnumWindows.aspx there is three files need
to be downloaded, EnumWndw.vps, Form1.frm & module1.bas
but I could not let Form1 working Excell 2003 VBA editor, please comment how to ocnvert it into VBA
Editore. And moudles.bas I could directly copy into my module in VBA, but what is EnumWnd.vps for ?
Please advise
Thanks
Duncan
**************EnumWndw.vps****************Type=ExeForm=Form1.frmReference=*G{00020430-0000-0000-C000-000000000046}#2.0#0#....windowsSYSTEMStdOle2.Tlb#OLE AutomationModule=Module1; Module1.basIconForm="Form1"Startup="Form1"HelpFile=""Title="EnumWndw"ExeName32="EnumWndw.exe"Command32=""Name="EnumWnd"HelpContextID="0"Description="Enumerate all Top Level Windows"CompatibleMode="0"MajorVer=1MinorVer=0RevisionVer=0AutoIncrementVer=0ServerSupportFiles=0VersionComments="Written by Dave Scarmozzino"VersionCompanyName="www.TheScarms.com"VersionFileDescription="Enumerate all Top Level Windows"VersionLegalCopyright="If you use this code, please mention www.TheScarms.com"CompilationType=0OptimizationType=0FavorPentiumPro(tm)=0CodeViewDebugInfo=0NoAliasing=0BoundsCheck=0OverflowCheck=0FlPointCheck=0FDIVCheck=0UnroundedFP=0StartMode=0Unattended=0Retained=0ThreadPerObject=0MaxNumberOfThreads=1
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:
***********Module1.bas*****************Option ExplicitPublic Const LB_SETTABSTOPS = &"H192Public Const MAX_PATH = 260Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongDeclare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongDeclare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongDeclare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As LongDim lResult As LongDim lThreadId As LongDim lProcessId As LongDim sWndName As StringDim sClassName As String'' This callback function is called by Windows (from the EnumWindows' API call) for EVERY window that exists. It populates the aWindowList' array with a list of windows that we are interested in.'fEnumWindowsCallBack = 1sClassName = Space$(MAX_PATH)sWndName = Space$(MAX_PATH)lResult = GetClassName(hwnd, sClassName, MAX_PATH)sClassName = Left$(sClassName, lResult)lResult = GetWindowText(hwnd, sWndName, MAX_PATH)sWndName = Left$(sWndName, lResult)lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)Form1.lstWindows.AddItem CStr(hwnd) &" vbTab &" sClassName &" _ vbTab &" CStr(lProcessId) &" vbTab &" CStr(lThreadId) &" _ vbTab &" sWndNameEnd FunctionPublic Function fEnumWindows() As BooleanDim hwnd As Long'' The EnumWindows function enumerates all top-level windows' on the screen by passing the handle of each window, in turn,' to an application-defined callback function. EnumWindows' continues until the last top-level window is enumerated or' the callback function returns FALSE.'Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)End Function
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:
************Form1.frm***************VERSION 5.00Begin VB.Form Form1 BorderStyle = 1 'Fixed Single Caption = "Enumerate All Top Level Windows" ClientHeight = 3855 ClientLeft = 1650 ClientTop = 2100 ClientWidth = 10575 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 3855 ScaleWidth = 10575 StartUpPosition = 2 'CenterScreen Begin VB.CommandButton cmdEnum Caption = "&"Enumerate" Height = 375 Left = 7980 TabIndex = 2 Top = 3360 Width = 1215 End Begin VB.CommandButton cmdQuit Caption = "&"Quit" Height = 375 Left = 9300 TabIndex = 1 Top = 3360 Width = 1215 End Begin VB.ListBox lstWindows Height = 2790 Left = 120 TabIndex = 0 TabStop = 0 'False Top = 480 Width = 10335 End Begin VB.Label lblCount Caption = "Windows Found: " Height = 255 Left = 120 TabIndex = 8 Top = 3360 Width = 1935 End Begin VB.Label Label1 Caption = "Window Caption" Height = 255 Index = 4 Left = 5880 TabIndex = 7 Top = 240 Width = 1575 End Begin VB.Label Label1 Caption = "Thread Id" Height = 255 Index = 3 Left = 4800 TabIndex = 6 Top = 240 Width = 855 End Begin VB.Label Label1 Caption = "Process Id" Height = 255 Index = 2 Left = 3840 TabIndex = 5 Top = 240 Width = 855 End Begin VB.Label Label1 Caption = "Class Name" Height = 255 Index = 1 Left = 840 TabIndex = 4 Top = 240 Width = 1095 End Begin VB.Label Label1 Caption = "Handle" Height = 255 Index = 0 Left = 120 TabIndex = 3 Top = 240 Width = 615 EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption ExplicitPrivate Sub cmdEnum_Click()lstWindows.ClearCall fEnumWindowslblCount = "Windows Found: " &" lstWindows.ListCountEnd SubPrivate Sub cmdQuit_Click()Unload MeEnd SubPrivate Sub Form_Load()ReDim aTabs(4) As Long'' Set up a listbox with TAB delimited columns.' Add the desired tabstops to an array.'' NOTE: tabstops are defined in terms of "dialog units". While the' GetDialogBaseUnits function combined with a simple calculation' can be used to convert between dialog units and pixels, the' easiest way to set tabstops where you want is by trial and error.'aTabs(0) = 30aTabs(1) = 165aTabs(2) = 210aTabs(3) = 255'Clear any existing tabs.Call SendMessageArray(lstWindows.hwnd, LB_SETTABSTOPS, 0&", 0&")'Set the tabs.Call SendMessageArray(lstWindows.hwnd, LB_SETTABSTOPS, 4&", aTabs(0))End Sub
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:62:63:64:65:66:67:68:69:70:71:72:73:74:75:76:77:78:79:80:81:82:83:84:85:86:87:88:89:90:91:92:93:94:95:96:97:98:99:100:101:102:103:104:105:106:107:108:109:110:111:112:113:114:115:116:117:118:119:120:121:122:123:124:125:126:127:128:129:
As well as EnumWindows you need EnumChildWindows for threads EnumnThreads and EnumChildThreads.
(Those might not be the exact names - don't have VBA to hand right now).
Even with those functions you still won't get data from the windows - I've tried doing it just for things like the formula bar in Excel.
I can't get the handle for the formulabar and for it's child windows but I can't get any data from them apart from Class and Window text.
In theory you should be able to use the SendMessage to get (or set) the data but when I tried it I just ended up having to abort the code eventually because nothing was happening.
As for getting data from Java, that's going to be even harder.
Java code runs in/on/with the Java Virtual Machine, which is a sort of machine within windows.
Dear,
Finally I know what is the function of Enumwindow and fEunWindowsCall back and that is
just output system all data such as classname, title, id, thread ,hwnd , I put it in the excel sheet instead of form. SInce I don't knwo how to use it in VB. It output all system hwn and information around 1000 items. But that is not I want. For my window application, I just find its hwnd and no other handles in the same window in the list . WHen I use SPY++/WINID we can see we can find all hwnds within one window application. FOr example, if you open one www.yahoo.com windows you will find a lot of other handles within such yahoo IE window by SPY++. Why there is no API function can do that as SPY++ does. Next I might use Enumchildwindow function to find other handles within the same window
THe questions:
1- I don't understand what is child and parent process and handles ?
2- What it is thread and threadID for ? Why people will use it >
3- IN Unix, process handles and id is same but not in window.
Please advise
Thanks
Duncan
Option ExplicitPublic Const LB_SETTABSTOPS = &H192Public Const MAX_PATH = 260Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongDeclare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongDeclare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongDeclare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As LongDim lResult As LongDim lThreadId As LongDim lProcessId As LongDim sWndName As StringDim sClassName As StringDim lastrow As IntegerWorksheets(1).Select'' This callback function is called by Windows (from the EnumWindows' API call) for EVERY window that exists. It populates the aWindowList' array with a list of windows that we are interested in.lastrow = Range("A60000").End(xlUp).Row 'fEnumWindowsCallBack = 1sClassName = Space$(MAX_PATH)sWndName = Space$(MAX_PATH)lResult = GetClassName(hwnd, sClassName, MAX_PATH)sClassName = Left$(sClassName, lResult)lResult = GetWindowText(hwnd, sWndName, MAX_PATH)sWndName = Left$(sWndName, lResult)lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)'Debug.Print CStr(hwnd), vbTab & sClassName, vbTab & CStr(lProcessId), vbTab & CStr(lThreadId), vbTab & sWndNameRange("A" & lastrow + 1) = (Hex(hwnd))Range("B" & lastrow + 1) = ((hwnd))Range("C" & lastrow + 1) = sClassNameRange("D" & lastrow + 1) = (Hex(lProcessId))Range("E" & lastrow + 1) = (Hex(lThreadId))Range("F" & lastrow + 1) = sWndName'Form1.lstWindows.AddItem CStr(hwnd) & vbTab & sClassName & ' vbTab & CStr(lProcessId) & vbTab & CStr(lThreadId) & _ ' vbTab & sWndNameEnd FunctionPublic Function fEnumWindows() As BooleanDim hwnd As Long'' The EnumWindows function enumerates all top-level windows' on the screen by passing the handle of each window, in turn,' to an application-defined callback function. EnumWindows' continues until the last top-level window is enumerated or' the callback function returns FALSE.'Worksheets(1).SelectRange("A1:E4000").SelectSelection.Clear'hwnd = &H220590Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)End Function
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:
Dear,
Finally I know what is the function of Enumwindow and fEunWindowsCall back and that is
just output system all data such as classname, title, id, thread ,hwnd , I put it in the excel sheet instead of form. SInce I don't knwo how to use it in VB. It output all system hwn and information around 1000 items. But that is not I want. For my window application, I just find its hwnd and no other handles in the same window in the list . WHen I use SPY++/WINID we can see we can find all hwnds within one window application. FOr example, if you open one www.yahoo.com windows you will find a lot of other handles within such yahoo IE window by SPY++. Why there is no API function can do that as SPY++ does. Next I might use Enumchildwindow function to find other handles within the same window
THe questions:
1- I don't understand what is child and parent process and handles ?
2- What it is thread and threadID for ? Why people will use it >
3- IN Unix, process handles and id is same but not in window.
Please advise
Thanks
Duncan
Option ExplicitPublic Const LB_SETTABSTOPS = &H192Public Const MAX_PATH = 260Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongDeclare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongDeclare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongDeclare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As LongDim lResult As LongDim lThreadId As LongDim lProcessId As LongDim sWndName As StringDim sClassName As StringDim lastrow As IntegerWorksheets(1).Select'' This callback function is called by Windows (from the EnumWindows' API call) for EVERY window that exists. It populates the aWindowList' array with a list of windows that we are interested in.lastrow = Range("A60000").End(xlUp).Row 'fEnumWindowsCallBack = 1sClassName = Space$(MAX_PATH)sWndName = Space$(MAX_PATH)lResult = GetClassName(hwnd, sClassName, MAX_PATH)sClassName = Left$(sClassName, lResult)lResult = GetWindowText(hwnd, sWndName, MAX_PATH)sWndName = Left$(sWndName, lResult)lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)'Debug.Print CStr(hwnd), vbTab & sClassName, vbTab & CStr(lProcessId), vbTab & CStr(lThreadId), vbTab & sWndNameRange("A" & lastrow + 1) = (Hex(hwnd))Range("B" & lastrow + 1) = ((hwnd))Range("C" & lastrow + 1) = sClassNameRange("D" & lastrow + 1) = (Hex(lProcessId))Range("E" & lastrow + 1) = (Hex(lThreadId))Range("F" & lastrow + 1) = sWndName'Form1.lstWindows.AddItem CStr(hwnd) & vbTab & sClassName & ' vbTab & CStr(lProcessId) & vbTab & CStr(lThreadId) & _ ' vbTab & sWndNameEnd FunctionPublic Function fEnumWindows() As BooleanDim hwnd As Long'' The EnumWindows function enumerates all top-level windows' on the screen by passing the handle of each window, in turn,' to an application-defined callback function. EnumWindows' continues until the last top-level window is enumerated or' the callback function returns FALSE.'Worksheets(1).SelectRange("A1:E4000").SelectSelection.Clear'hwnd = &H220590Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)End Function
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:
Dear,
Finally I know what is the function of Enumwindow and fEunWindowsCall back and that is
just output system all data such as classname, title, id, thread ,hwnd , I put it in the excel sheet instead of form. SInce I don't knwo how to use it in VB. It output all system hwn and information around 1000 items. But that is not I want. For my window application, I just find its hwnd and no other handles in the same window in the list . WHen I use SPY++/WINID we can see we can find all hwnds within one window application. FOr example, if you open one www.yahoo.com windows you will find a lot of other handles within such yahoo IE window by SPY++. Why there is no API function can do that as SPY++ does. Next I might use Enumchildwindow function to find other handles within the same window
THe questions:
1- I don't understand what is child and parent process and handles ?
2- What it is thread and threadID for ? Why people will use it >
3- IN Unix, process handles and id is same but not in window.
Please advise
Thanks
Duncan
Option ExplicitPublic Const LB_SETTABSTOPS = &H192Public Const MAX_PATH = 260Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongDeclare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongDeclare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongDeclare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As LongDim lResult As LongDim lThreadId As LongDim lProcessId As LongDim sWndName As StringDim sClassName As StringDim lastrow As IntegerWorksheets(1).Select'' This callback function is called by Windows (from the EnumWindows' API call) for EVERY window that exists. It populates the aWindowList' array with a list of windows that we are interested in.lastrow = Range("A60000").End(xlUp).Row 'fEnumWindowsCallBack = 1sClassName = Space$(MAX_PATH)sWndName = Space$(MAX_PATH)lResult = GetClassName(hwnd, sClassName, MAX_PATH)sClassName = Left$(sClassName, lResult)lResult = GetWindowText(hwnd, sWndName, MAX_PATH)sWndName = Left$(sWndName, lResult)lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)'Debug.Print CStr(hwnd), vbTab & sClassName, vbTab & CStr(lProcessId), vbTab & CStr(lThreadId), vbTab & sWndNameRange("A" & lastrow + 1) = (Hex(hwnd))Range("B" & lastrow + 1) = ((hwnd))Range("C" & lastrow + 1) = sClassNameRange("D" & lastrow + 1) = (Hex(lProcessId))Range("E" & lastrow + 1) = (Hex(lThreadId))Range("F" & lastrow + 1) = sWndName'Form1.lstWindows.AddItem CStr(hwnd) & vbTab & sClassName & ' vbTab & CStr(lProcessId) & vbTab & CStr(lThreadId) & _ ' vbTab & sWndNameEnd FunctionPublic Function fEnumWindows() As BooleanDim hwnd As Long'' The EnumWindows function enumerates all top-level windows' on the screen by passing the handle of each window, in turn,' to an application-defined callback function. EnumWindows' continues until the last top-level window is enumerated or' the callback function returns FALSE.'Worksheets(1).SelectRange("A1:E4000").SelectSelection.Clear'hwnd = &H220590Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)End Function
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:
Dear,
Finally I know what is the function of Enumwindow and fEunWindowsCall back and that is
just output system all data such as classname, title, id, thread ,hwnd , I put it in the excel sheet instead of form. SInce I don't knwo how to use it in VB. It output all system hwn and information around 1000 items. But that is not I want. For my window application, I just find its hwnd and no other handles in the same window in the list . WHen I use SPY++/WINID we can see we can find all hwnds within one window application. FOr example, if you open one www.yahoo.com windows you will find a lot of other handles within such yahoo IE window by SPY++. Why there is no API function can do that as SPY++ does. Next I might use Enumchildwindow function to find other handles within the same window
THe questions:
1- I don't understand what is child and parent process and handles ?
2- What it is thread and threadID for ? Why people will use it >
3- IN Unix, process handles and id is same but not in window.
Please advise
Thanks
Duncan
Option ExplicitPublic Const LB_SETTABSTOPS = &H192Public Const MAX_PATH = 260Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongDeclare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongDeclare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongDeclare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As LongDim lResult As LongDim lThreadId As LongDim lProcessId As LongDim sWndName As StringDim sClassName As StringDim lastrow As IntegerWorksheets(1).Select'' This callback function is called by Windows (from the EnumWindows' API call) for EVERY window that exists. It populates the aWindowList' array with a list of windows that we are interested in.lastrow = Range("A60000").End(xlUp).Row 'fEnumWindowsCallBack = 1sClassName = Space$(MAX_PATH)sWndName = Space$(MAX_PATH)lResult = GetClassName(hwnd, sClassName, MAX_PATH)sClassName = Left$(sClassName, lResult)lResult = GetWindowText(hwnd, sWndName, MAX_PATH)sWndName = Left$(sWndName, lResult)lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)'Debug.Print CStr(hwnd), vbTab & sClassName, vbTab & CStr(lProcessId), vbTab & CStr(lThreadId), vbTab & sWndNameRange("A" & lastrow + 1) = (Hex(hwnd))Range("B" & lastrow + 1) = ((hwnd))Range("C" & lastrow + 1) = sClassNameRange("D" & lastrow + 1) = (Hex(lProcessId))Range("E" & lastrow + 1) = (Hex(lThreadId))Range("F" & lastrow + 1) = sWndName'Form1.lstWindows.AddItem CStr(hwnd) & vbTab & sClassName & ' vbTab & CStr(lProcessId) & vbTab & CStr(lThreadId) & _ ' vbTab & sWndNameEnd FunctionPublic Function fEnumWindows() As BooleanDim hwnd As Long'' The EnumWindows function enumerates all top-level windows' on the screen by passing the handle of each window, in turn,' to an application-defined callback function. EnumWindows' continues until the last top-level window is enumerated or' the callback function returns FALSE.'Worksheets(1).SelectRange("A1:E4000").SelectSelection.Clear'hwnd = &H220590Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)End Function
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:
Dear,
Finally I know what is the function of Enumwindow and fEunWindowsCall back and that is
just output system all data such as classname, title, id, thread ,hwnd , I put it in the excel sheet instead of form. SInce I don't knwo how to use it in VB. It output all system hwn and information around 1000 items. But that is not I want. For my window application, I just find its hwnd and no other handles in the same window in the list . WHen I use SPY++/WINID we can see we can find all hwnds within one window application. FOr example, if you open one www.yahoo.com windows you will find a lot of other handles within such yahoo IE window by SPY++. Why there is no API function can do that as SPY++ does. Next I might use Enumchildwindow function to find other handles within the same window
THe questions:
1- I don't understand what is child and parent process and handles ?
2- What it is thread and threadID for ? Why people will use it >
3- IN Unix, process handles and id is same but not in window.
Please advise
Thanks
Duncan
Option ExplicitPublic Const LB_SETTABSTOPS = &H192Public Const MAX_PATH = 260Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongDeclare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongDeclare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongDeclare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As LongDim lResult As LongDim lThreadId As LongDim lProcessId As LongDim sWndName As StringDim sClassName As StringDim lastrow As IntegerWorksheets(1).Select'' This callback function is called by Windows (from the EnumWindows' API call) for EVERY window that exists. It populates the aWindowList' array with a list of windows that we are interested in.lastrow = Range("A60000").End(xlUp).Row 'fEnumWindowsCallBack = 1sClassName = Space$(MAX_PATH)sWndName = Space$(MAX_PATH)lResult = GetClassName(hwnd, sClassName, MAX_PATH)sClassName = Left$(sClassName, lResult)lResult = GetWindowText(hwnd, sWndName, MAX_PATH)sWndName = Left$(sWndName, lResult)lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)'Debug.Print CStr(hwnd), vbTab & sClassName, vbTab & CStr(lProcessId), vbTab & CStr(lThreadId), vbTab & sWndNameRange("A" & lastrow + 1) = (Hex(hwnd))Range("B" & lastrow + 1) = ((hwnd))Range("C" & lastrow + 1) = sClassNameRange("D" & lastrow + 1) = (Hex(lProcessId))Range("E" & lastrow + 1) = (Hex(lThreadId))Range("F" & lastrow + 1) = sWndName'Form1.lstWindows.AddItem CStr(hwnd) & vbTab & sClassName & ' vbTab & CStr(lProcessId) & vbTab & CStr(lThreadId) & _ ' vbTab & sWndNameEnd FunctionPublic Function fEnumWindows() As BooleanDim hwnd As Long'' The EnumWindows function enumerates all top-level windows' on the screen by passing the handle of each window, in turn,' to an application-defined callback function. EnumWindows' continues until the last top-level window is enumerated or' the callback function returns FALSE.'Worksheets(1).SelectRange("A1:E4000").SelectSelection.Clear'hwnd = &H220590Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)End Function
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:
Dear,
Finally I know what is the function of Enumwindow and fEunWindowsCall back and that is
just output system all data such as classname, title, id, thread ,hwnd , I put it in the excel sheet instead of form. SInce I don't knwo how to use it in VB. It output all system hwn and information around 1000 items. But that is not I want. For my window application, I just find its hwnd and no other handles in the same window in the list . WHen I use SPY++/WINID we can see we can find all hwnds within one window application. FOr example, if you open one www.yahoo.com windows you will find a lot of other handles within such yahoo IE window by SPY++. Why there is no API function can do that as SPY++ does. Next I might use Enumchildwindow function to find other handles within the same window
THe questions:
1- I don't understand what is child and parent process and handles ?
2- What it is thread and threadID for ? Why people will use it >
3- IN Unix, process handles and id is same but not in window.
Please advise
Thanks
Duncan
Option ExplicitPublic Const LB_SETTABSTOPS = &H192Public Const MAX_PATH = 260Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongDeclare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongDeclare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongDeclare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As LongDim lResult As LongDim lThreadId As LongDim lProcessId As LongDim sWndName As StringDim sClassName As StringDim lastrow As IntegerWorksheets(1).Select'' This callback function is called by Windows (from the EnumWindows' API call) for EVERY window that exists. It populates the aWindowList' array with a list of windows that we are interested in.lastrow = Range("A60000").End(xlUp).Row 'fEnumWindowsCallBack = 1sClassName = Space$(MAX_PATH)sWndName = Space$(MAX_PATH)lResult = GetClassName(hwnd, sClassName, MAX_PATH)sClassName = Left$(sClassName, lResult)lResult = GetWindowText(hwnd, sWndName, MAX_PATH)sWndName = Left$(sWndName, lResult)lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)'Debug.Print CStr(hwnd), vbTab & sClassName, vbTab & CStr(lProcessId), vbTab & CStr(lThreadId), vbTab & sWndNameRange("A" & lastrow + 1) = (Hex(hwnd))Range("B" & lastrow + 1) = ((hwnd))Range("C" & lastrow + 1) = sClassNameRange("D" & lastrow + 1) = (Hex(lProcessId))Range("E" & lastrow + 1) = (Hex(lThreadId))Range("F" & lastrow + 1) = sWndName'Form1.lstWindows.AddItem CStr(hwnd) & vbTab & sClassName & ' vbTab & CStr(lProcessId) & vbTab & CStr(lThreadId) & _ ' vbTab & sWndNameEnd FunctionPublic Function fEnumWindows() As BooleanDim hwnd As Long'' The EnumWindows function enumerates all top-level windows' on the screen by passing the handle of each window, in turn,' to an application-defined callback function. EnumWindows' continues until the last top-level window is enumerated or' the callback function returns FALSE.'Worksheets(1).SelectRange("A1:E4000").SelectSelection.Clear'hwnd = &H220590Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)End Function
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:
Dear,
Finally I know what is the function of Enumwindow and fEunWindowsCall back and that is
just output system all data such as classname, title, id, thread ,hwnd , I put it in the excel sheet instead of form. SInce I don't knwo how to use it in VB. It output all system hwn and information around 1000 items. But that is not I want. For my window application, I just find its hwnd and no other handles in the same window in the list . WHen I use SPY++/WINID we can see we can find all hwnds within one window application. FOr example, if you open one www.yahoo.com windows you will find a lot of other handles within such yahoo IE window by SPY++. Why there is no API function can do that as SPY++ does. Next I might use Enumchildwindow function to find other handles within the same window
THe questions:
1- I don't understand what is child and parent process and handles ?
2- What it is thread and threadID for ? Why people will use it >
3- IN Unix, process handles and id is same but not in window.
Please advise
Thanks
Duncan
Option ExplicitPublic Const LB_SETTABSTOPS = &H192Public Const MAX_PATH = 260Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongDeclare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongDeclare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As LongDeclare Function SendMessageArray Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lpData As Long) As LongDim lResult As LongDim lThreadId As LongDim lProcessId As LongDim sWndName As StringDim sClassName As StringDim lastrow As IntegerWorksheets(1).Select'' This callback function is called by Windows (from the EnumWindows' API call) for EVERY window that exists. It populates the aWindowList' array with a list of windows that we are interested in.lastrow = Range("A60000").End(xlUp).Row 'fEnumWindowsCallBack = 1sClassName = Space$(MAX_PATH)sWndName = Space$(MAX_PATH)lResult = GetClassName(hwnd, sClassName, MAX_PATH)sClassName = Left$(sClassName, lResult)lResult = GetWindowText(hwnd, sWndName, MAX_PATH)sWndName = Left$(sWndName, lResult)lThreadId = GetWindowThreadProcessId(hwnd, lProcessId)'Debug.Print CStr(hwnd), vbTab & sClassName, vbTab & CStr(lProcessId), vbTab & CStr(lThreadId), vbTab & sWndNameRange("A" & lastrow + 1) = (Hex(hwnd))Range("B" & lastrow + 1) = ((hwnd))Range("C" & lastrow + 1) = sClassNameRange("D" & lastrow + 1) = (Hex(lProcessId))Range("E" & lastrow + 1) = (Hex(lThreadId))Range("F" & lastrow + 1) = sWndName'Form1.lstWindows.AddItem CStr(hwnd) & vbTab & sClassName & ' vbTab & CStr(lProcessId) & vbTab & CStr(lThreadId) & _ ' vbTab & sWndNameEnd FunctionPublic Function fEnumWindows() As BooleanDim hwnd As Long'' The EnumWindows function enumerates all top-level windows' on the screen by passing the handle of each window, in turn,' to an application-defined callback function. EnumWindows' continues until the last top-level window is enumerated or' the callback function returns FALSE.'Worksheets(1).SelectRange("A1:E4000").SelectSelection.Clear'hwnd = &H220590Call EnumWindows(AddressOf fEnumWindowsCallBack, hwnd)End Function
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61: