Results 1 to 5 of 5

Thread: Problem in retrieving message portion from a message box

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Location
    India
    Posts
    11

    Question 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

  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Location
    India
    Posts
    11

    Lightbulb somebody help

    I just can't believe that there is nobody in this forum with a solution. Somebody should be there. Please help

  3. #3

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Location
    India
    Posts
    11
    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

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width