|
-
Jun 26th, 2003, 03:33 AM
#1
Thread Starter
New Member
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
-
Jul 14th, 2003, 07:23 AM
#2
Thread Starter
New Member
somebody help
I just can't believe that there is nobody in this forum with a solution. Somebody should be there. Please help
-
Jul 14th, 2003, 09:43 AM
#3
See my response in this thread.
-
Jul 15th, 2003, 07:18 AM
#4
Thread Starter
New Member
Thanks MartinLiss for your reply.
The code given in the link u've supplied worked fine. But my problem is somwhat different.
In the code, u have used FindWindow API. One of the parameters of the function is the caption of the window. But if I don't know the caption of the window.
Actually what I'm trying is to make an application, which is going to catch all the messages displayed by msgbox of any other running application. So I may not know the caption of all the msgboxes.
Thanks and hope to get a quick reply
Pradipta
-
Jul 15th, 2003, 12:15 PM
#5
If you change the strCaption to a NULL value, all MsgBox captions will match, so you could program some kind of loop and view them all.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|