Im looking to find a window, but the caption will never be exactly the same..it will always have the word AIM in it..could anyone tell me how id find it?
And you can use this code to find out the class name for a window (if you know it's title). Only use this once to find out the class name for what you need, then just hardcode it in the FindWindow
VB Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
well, since ive posted ive gotten both to work. But they dont do as i want..The enumwindows will tell me the forms name, not classname. The 2nd one just shows children..
ill check out those two examples. Just to clarify, i want to search thru all the classes open, and if a class is icoPMAim or whatever- then i want to find its hwnd
Yeah, but then you increase the chances of mistaking. If you search for partial (example AOL) it is easy that some other window will have 'aol' in it's name.
So don't search just for AOL, make it more specific You can't really avoid getting a wrong window. You can reduce the chances by checking the classname (I don't know if that is done in the examples)...
Has someone helped you? Then you can Rate their helpful post.
Try the code I modified. When you click refresh, it lists the objects, then loops through them and searches for a class (BaseBar in my example), and diplays their hwnds (if any found)
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Any) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Function WndEnumProc(ByVal hwnd As Long) As Long
Dim WText As String * 512
Dim bRet As Long, WLen As Long
Dim WClass As String * 50
Dim hwnds As Long
WLen = GetWindowTextLength(hwnd)
bRet = GetWindowText(hwnd, WText, WLen + 1)
GetClassName hwnd, WClass, 50
If InStr(WClass, "icoPMsgAIM") Then
Insert hwnd, WText, WClass
End If
WndEnumProc = 1
End Function
Private Sub Insert(iHwnd As Long, iText As String, iClass As String)
This works for my trillian(It finds all the class windows with AIM and shrinks them , then brings them back to original size!)
add a listbox name list, add 2 command buttons.
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Any) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Public Declare Sub SetWindowPos Lib "user32" _
(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public sizeofwin As RECT
Public cat As Long: Public Oleft As Long: Public oTop As Long: Public oRight As Long: Public oBottom As Long
Public Function WndEnumProc(ByVal hWnd As Long) As Long