Avatar of KingSencat
KingSencat

asked on 

Perform a mouse click on a 3rd-party window does not work in a german windows why ? Visual Basic 6.0 ( 500 points )

My attached Visual Basic 6.0 code works just perfect with windows ENGLISH version, but in windows german language for some reason the mouse DOES NOT click on the correct dimension of the 3rd party window "TTMessenger - Logged In as"  like in Windows English version , can you tell me why ? any ideas,suggestions or an extra code will be very very helpfull.
''' MODULE CODE
Public Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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 IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function IsWindowUnicode Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
 
 
Public Const HWND_NOTOPMOST = -2
Public Const HWND_TOPMOST = -1
Public Const MAX_PATH& = 260
Public Const SW_HIDE = 0
Public Const SW_Maximize = 3
Public Const SW_Minimize = 6
Public Const SW_SHOW = 5
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const FLAGS = SWP_NOSIZE Or SWP_NOMOVE
Public Const HTCAPTION = 2
Public Const SW_Normal = 1
Public Const WM_CLOSE = &H10
Public Const WM_GETTEXT = &HD
Public Const TXT_LEN = 100
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const WM_MOUSEMOVE = &H200
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const GW_CHILD = 5
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_NOREDRAW = &H8
Public Const SWP_NOZORDER = &H4
Public Const SWP_HIDEWINDOW = &H80
Public Const WM_SETTEXT = &HC
Public Const WM_CHAR = &H102
Public Const WM_CLEAR = &H303
Public Const EM_SETPASSWORDCHAR = &HCC
Public Const EM_GETPASSWORDCHAR = &HD2
Public Const EN_CHANGE = &H300
Public Const MF_BYPOSITION = &H400&
Public Const MF_ENABLED = &H0&
Public Const MF_DISABLED = &H2&
 
 
Public Function GetWindowTitle(ByVal hwnd As Long) As String
On Error Resume Next
Dim S As String
 
l = GetWindowTextLength(hwnd)
S = Space(l + 1)
 
GetWindowText hwnd, S, l + 1
GetWindowTitle = Left$(S, l)
End Function
 
 
''' DECLARATIONS
 
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As Rect) As Long
 
Private Type Rect
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
 
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, _
    ByVal Y As Long) As Long
 
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, _
    ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, _
    ByVal dwExtraInfo As Long)
 
  Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  Private Const WM_LBUTTONUP = &H202
      Const BM_CLICK As Long = &HF5&
  Private Declare Function 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) As Long
        Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000                  '  WS_BORDER Or WS_DLGFRAME
 
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
 
 
'''' FORM CODE
 
Public Sub LeftMouseClick(ByVal X As Long, ByVal Y As Long)
    SetCursorPos X, Y
    mouse_event MOUSEEVENTF_LEFTDOWN, X, Y, 22, 22
    mouse_event MOUSEEVENTF_LEFTUP, X, Y, 22, 22
End Sub
 
Private sub begin()
Appactivate "TTMessenger - Logged In as"
Dim calcWnd As Long
    Dim r As Rect
    Dim middleX As Long
    Dim middleY As Long
       calcWnd = FindWindow(vbNullString, "TTMessenger - Logged In as")
    Call GetWindowRect(calcWnd, r)
    middleX = r.Left + (r.Right - r.Left) / 2
    middleY = r.Top + (r.Bottom - r.Top) / 2
    Call LeftMouseClick(middleX, middleY)
End sub

Open in new window

Visual Basic ClassicProgramming Languages-Other

Avatar of undefined
Last Comment
Dana Seaman
Avatar of c0ldfyr3
c0ldfyr3
Flag of Ireland image

Change top part to be second part...

The problem is the window caption must be different on german version!
calcWnd = FindWindow(vbNullString, "TTMessenger - Logged In as")
 
CHANGE TO
 
calcWnd = FindWindow(vbNullString, "TTMessenger - Logged In as")
if calccWnd = 0 then
    calcWnd = FindWindow(vbNullString, "INSERT GERMAN WINDOW CAPTION HERE")
end if

Open in new window

Avatar of KingSencat
KingSencat

ASKER

Hi and thanks for your quick response.. however the window caption in german windows its not different than english, both english and german windows shows the same window caption name "TTMessenger - Logged In as" and i am sure about this, i have double checked with Winspy+

Any other suggestions ? maybe something is wrong in my code ?
Avatar of c0ldfyr3
c0ldfyr3
Flag of Ireland image

If you put a breakpoint (F9) on the line after FindWindow is it 0 in the german version?
Avatar of KingSencat
KingSencat

ASKER

The problem is that i dont have windows in german and i can't check, a friend of mine he can just execute the .exe , what you suggest me to do ?
Avatar of c0ldfyr3
c0ldfyr3
Flag of Ireland image

Ok create a new application and paste the code below into Form1 over writing all of it. Once it copies the classname to the clipboard use it as the first argument to FindWindow in your application and vbNullString as the second. Example:

calcWnd = FindWindow("ClasName", vbNullString)


Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 Sub Form_Load()
    Dim calcWnd                 As Long
    Dim sClassName              As String
    Dim sWindowTitle            As String
    
    'sWindowTitle = "TTMessenger - Logged In as"
    
    calcWnd = FindWindow(vbNullString, sWindowTitle)
    sClassName = Space(255)
    Call GetClassName(calcWnd, sClassName, 255)
    sClassName = Left$(sClassName, InStr(1, sClassName, Chr$(0)) - 1)
    
    Clipboard.Clear
    Clipboard.SetText sClassName
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dana Seaman
Dana Seaman
Flag of Brazil image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of c0ldfyr3
c0ldfyr3
Flag of Ireland image

Oops, remove the comment from the sWindowTitle = line before you do anything :P
Avatar of KingSencat
KingSencat

ASKER

danaseaman: how do i make that? can you explain a little bit more please? i enter to control panel, regional language options -> advanced -> and i change from german to enligsh (usa) i restart the system and still not work, what i am doing wrong ?

thanks
Avatar of c0ldfyr3
c0ldfyr3
Flag of Ireland image

KingSenca, if you do as i said it will work for any language, the problem is you are trying to find a window using it's title which is bad practice as a window can have changeable titles. Using the classname will work unless it's a very generic classname or a vb6 application.
Avatar of Dana Seaman
Dana Seaman
Flag of Brazil image

Change your machine from English to German and then try the code on your machine.
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo