Results 1 to 8 of 8

Thread: read external message box caption

  1. #1

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    read external message box caption

    hey all i was wondering if its possible to read a external message box's caption and if it contains certin words do an action like as a very simple example if windows generates an error the program reads the caption and looks for the word "error" if it finds it then does somthing i assume this would need some findwindow apis or somthing on that lines but not sure

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: read external message box caption

    To my knowledge the findwindow API does work with External message boxes. Though i have never officially tested it.

  3. #3
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: read external message box caption

    The text of the message is drawn onto the window's form. It is not possible to acquire the text through API or by any other means.

  4. #4

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: read external message box caption

    hmm so there is no way then ? damn

  5. #5
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: read external message box caption

    Quote Originally Posted by Logophobic
    The text of the message is drawn onto the window's form. It is not possible to acquire the text through API or by any other means.
    Have you tested it? Not being rude just asking

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: read external message box caption

    Quote Originally Posted by Logophobic
    The text of the message is drawn onto the window's form. It is not possible to acquire the text through API or by any other means.
    The standard windows Message Box is written in C not VB, the 'labels' on it are not VB labels but Static class windows which have a hWnd and can be manipulated with API.

    @dark_shadow: it depends on what caption you are talking about (windows caption or MsgBox prompt) but what you're trying to should be possible. Use FindWindowEx to get the right the hWnd, and then read the text using GetWindowText (or SendMessage in combination with WM_GETTEXT)

  7. #7

    Thread Starter
    Fanatic Member dark_shadow's Avatar
    Join Date
    Feb 2005
    Location
    Igloo
    Posts
    900

    Re: read external message box caption

    thanks bush what i mean is the actual message of the box not the caption of the bar at the top

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: read external message box caption

    something like:
    VB Code:
    1. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    2.     ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    3.    
    4. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    5.     ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    6.    
    7. Private Const WM_GETTEXT = &HD
    8. Private Const WM_GETTEXTLENGTH = &HE
    9.  
    10. Private Sub Command1_Click()
    11.     Dim lhWnd As Long, sText As String
    12.    
    13.     lhWnd = FindWindowEx(0&, 0&, "#32770", vbNullString)
    14.     lhWnd = FindWindowEx(lhWnd, 0&, "Static", vbNullString)
    15.    
    16.     sText = Space$(SendMessage(lhWnd, WM_GETTEXTLENGTH, 0&, 0&))
    17.    
    18.     SendMessage lhWnd, WM_GETTEXT, ByVal Len(sText) + 1, ByVal sText
    19.    
    20.     Debug.Print sText
    21. End Sub

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