Parent Win class name is "#32770" and several buttons' class names are "afxwnd42s" (the only thing differentiating these buttons are the text). Anyone ever been in this situation? I just want to get the text of the buttons for now. Thanks
Printable View
Parent Win class name is "#32770" and several buttons' class names are "afxwnd42s" (the only thing differentiating these buttons are the text). Anyone ever been in this situation? I just want to get the text of the buttons for now. Thanks
You should be able to do a FindWindow for the dialog window #32770. Then do a FindWindowEx passing
the buttons classname and caption. Then you will have the handle to the button.
I'm having trouble finding the parent window, since it's one of those funky #32770 class names. My API Spy says the parent is returning a text, but doesn't have a parent class name or handle.
Which Spy utility are you using? I only have M$ Spy++. If your getting the #32770 window, it should have a caption title?
A useful tool is the API Spy at www.patorjk.com :)
here, i think this will help you find the form name easier:
VB Code:
Option Explicit 'Functions, constants and types for the hook Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" ( _ ByVal idHook As Long, _ ByVal lpfn As Long, _ ByVal hmod As Long, _ ByVal dwThreadId As Long _ ) As Long Private Declare Function UnhookWindowsHookEx Lib "user32" ( _ ByVal hHook As Long _ ) As Long Private Declare Function CallNextHookEx Lib "user32" ( _ ByVal hHook As Long, _ ByVal ncode As Long, _ ByVal wParam As Long, _ lParam As Any _ ) As Long Public Const WH_MOUSE_LL = 14 Public Type POINTAPI x As Long y As Long End Type Public Type MSLLHOOKSTRUCT pt As POINTAPI mouseData As Long flags As Long time As Long dwExtraInfo As Long End Type Private hHook As Long Public IsHooked As Boolean 'functions for getting windows properties Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _ ByVal hwnd As Long, _ ByVal lpString As String, _ ByVal cch As Long _ ) 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 WindowFromPoint Lib "user32" ( _ ByVal xPoint As Long, _ ByVal yPoint As Long _ ) As Long Sub GetWindowData(x As Long, y As Long) Dim hWndFrm As Long Dim lpClassName As String, lpString As String lpClassName = Space(100) lpString = Space(100) 'get handle to window hWndFrm = WindowFromPoint(CLng(x), CLng(y)) If hWndFrm = 0 Then Exit Sub 'get window text (caption) Call GetWindowText(hWndFrm, lpString, Len(lpString)) 'get window class name Call GetClassName(hWndFrm, lpClassName, Len(lpClassName)) With Form1 .txthandle = Hex(hWndFrm) .txtCaption = lpString .txtClassName = lpClassName End With End Sub Public Sub SetMouseHook() If IsHooked Then MsgBox "Don't hook the MOUSE_LL hook twice or you'll be sorry." Else 'This has to be set up as a system-wide hook hHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, App.hInstance, 0) IsHooked = True End If End Sub Public Sub RemoveMouseHook() Dim temp As Long temp = UnhookWindowsHookEx(hHook) IsHooked = False End Sub Public Function MouseProc(ByVal uCode As Long, ByVal wParam As Long, lParam As MSLLHOOKSTRUCT) As Long If uCode >= 0 Then Call GetWindowData(lParam.pt.x, lParam.pt.y) End If MouseProc = CallNextHookEx(hHook, uCode, wParam, lParam) End Function Added this to a form: visual basic code:Option Explicit 'Always on top stuff Private Const HWND_TOPMOST = -1 Private Const SWP_NOSIZE = &H1 Private Const SWP_NOMOVE = &H2 Private Const SWP_NOACTIVATE = &H10 Private Const SWP_SHOWWINDOW = &H40 Private 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 _ ) Private Sub cmdStart_Click() 'make window always on top SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or _ SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE 'set the system-wide low level mouse hook Call SetMouseHook End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Call RemoveMouseHook End Sub
you need three textboxes named txthandle, txtCaption, txtClassName
and a cmd button named cmdStart
--
Now, im having a similar problem. On the form there are 2 textboxes with teh same classname and caption, so i dont know how to send a message to one of them (it wont work just sending it)
I'm using PatorJK's API Spy. Weird thing is I can "Apply code" with it and it will click a button or whatever but the code itself is useless.Quote:
Originally Posted by RobDog888
Can you post your code?
Handle = FindWindow("#32770", vbNullString)
B1 = FindWindowEx(Handle, 0&, "afxwnd42s", vbNullString)
B2 = FindWindowEx(B1, 0&, "afxwnd42s", vbNullString)
B3 = FindWindowEx(B2, 0&, "afxwnd42s", vbNullString)
afxwnds = FindWindowEx(B3, 0&, "afxwnd42s", vbNullString)
Call SendMessageLong(afxwnds, WM_LBUTTONDOWN, 0&, 0&)
Call SendMessageLong(afxwnds, WM_LBUTTONUP, 0&, 0&)
You can also try using the PostMessage API with the BM_Click message instead of the SendMessageLong.
Why not add the window caption in the parameters for the FindWindowEx? If they are buttons then they
wont have any childern windows?
Is that correct for the window class for the buttons (afxwnd42s)???
Shouldnt the buttons class be "Button"?