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 getClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const GWL_EXSTYLE = (-20)
Public Const WM_CHAR = &H102
Public Const WM_SETTEXT = &HC
Public Const ES_READONLY = &H800&
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 Sub Console(cgCmd As String)
Dim MohCons As Long
Dim ParentWindow As Long
Dim ActualConsole As Long
ParentWindow = FindWindowEx(0, 0, vbNullString, "Medal of Honor Allied Assault")
If ParentWindow Then
MohCons = FindWindowEx(ParentWindow, MohCons, vbNullString, "Mohaa Console")
Do
ActualConsole = FindWindowEx(MohCons, actualwindow, vbNullString, vbNullString)
If UCase(getClassNameFromHwnd(MohCons)) = UCase("Edit") Or (ES_READONLY And GetWindowLong(actualwindow, GWL_STYLE)) Then
Else
SendMessage ActualConsole, WM_SETTEXT, 0, cgCmd
SendMessage ActualConsole, WM_CHAR, 13, 0
End If
Loop While ActualConsole <> 0
End If
End Sub
Public Function getNameFromHwnd(Hwnd As Long) As String
Dim title As String * 255
Dim tLen As Long
tLen = GetWindowTextLength(Hwnd)
GetWindowText Hwnd, title, 255
getNameFromHwnd = Left(title, tLen)
End Function
Public Function getClassNameFromHwnd(Hwnd As Long) As String
Dim ClassName As String * 1024
getClassName Hwnd, ClassName, 1024
getClassNameFromHwnd = Left(ClassName, InStr(1, ClassName, Chr(0)) - 1)
End Function