Problem in retrieving message portion from a message box
I am trying to retrieve the message displayed in the message box in some different application form my own application.
Here is the code I've used:
I've a form where I've used a commandbutton Command1
code of the click event
Private Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
I've used a module and the code is as follows:
__________________________
Option Explicit
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
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 Any) 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 WM_GETTEXTLENGTH = &HE
Public Const WM_GETTEXT = &HD
Dim Proc_Name_Prn As String
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long, lpClassName As String, cpret As Long, RetVal As String
Ret = GetWindowTextLength(hwnd)
sSave = Space(Ret)
GetWindowText hwnd, sSave, Ret + 1
lpClassName = Space(256)
RetVal = GetClassName(hwnd, lpClassName, 256)
lpClassName = Left$(lpClassName, RetVal)
If lpClassName = "#32770" Then
'#32770 is the class corresponding to message box
cpret = EnumChildWindows(hwnd, AddressOf WndEnumChildProc, ByVal 0&)
End If
'continue enumeration
EnumWindowsProc = True
End Function
Public Function WndEnumChildProc(ByVal cWnd As Long, ByVal lParam As String) As Long
Dim bRet As Long
Dim myStr As String * 50
bRet = GetClassName(cWnd, myStr, 50)
If Left$(myStr, 6) = "Static" Then
' Static is the class corresponding to the message portion of the message box
lParam = GetTheText(cWnd)
End If
End Function
Public Function GetTheText(Ihwnd As Long) As String
Dim Textlen As Long
Dim Text As String
Textlen = SendMessage(Ihwnd, WM_GETTEXTLENGTH, 0, 0)
Textlen = Textlen + 1
Text = Space$(Textlen)
Textlen = SendMessage(Ihwnd, WM_GETTEXT, Textlen, ByVal Text)
GetTheText = Left$(Text, Textlen)
Proc_Name_Prn = GetTheText
MsgBox Proc_Name_Prn
End Function
___________________________________________________
now I've run this application, after running some other application which shows a messagebox
my project can get the handle of the messagebox and the handle of the message portion of the message box but unable to retrieve the message.
Please help asap
Pradipta