A while back, I had shared a module (mdlGetHnd.vb) I created to make finding handles a bit easier. Well I will now share a more compact, cleaner module I have developed to do the same thing. To use it, add the module to you VB 2008 project and then call into it. It has 3 public functions:
- FindMainWindow(wndclass, title)
GetChild(MainClass, MainCaption, ChildClass, ChildIndex)
GetChild(ParentHandle, ChildClass, ChildIndex)
For demonstration purposes, if you wanted to find the "Edit" window of NotePad, you could do it this way:
- Code: Select all
Dim sClass As String = "Notepad"
Dim sCaption As String = "- Notepad"
Dim sSubClass As String = "Edit"
Dim iSubIndex As Integer = 1
Dim wHnd As IntPtr = mdlHnd.GetChild(sClass, sCaption, sSubClass, iSubIndex)
Or you can split it like this:
- Code: Select all
Dim sClass As String = "Notepad"
Dim sCaption As String = "- Notepad"
Dim sSubClass As String = "Edit"
Dim iSubIndex As Integer = 1
Dim wHndParent As IntPtr = mdlHnd.FindMainWindow(sClass, sCaption)
Dim wHnd As IntPtr = mdlHnd.GetChild(wHndParent, sSubClass, iSubIndex)
So those who have used my mdlGetHnd should be used to the needed variables.




