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
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.
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.
Re: read external message box caption
hmm so there is no way then ? damn
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
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)
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
Re: read external message box caption
something like:
VB Code:
Private 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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Sub Command1_Click()
Dim lhWnd As Long, sText As String
lhWnd = FindWindowEx(0&, 0&, "#32770", vbNullString)
lhWnd = FindWindowEx(lhWnd, 0&, "Static", vbNullString)
sText = Space$(SendMessage(lhWnd, WM_GETTEXTLENGTH, 0&, 0&))
SendMessage lhWnd, WM_GETTEXT, ByVal Len(sText) + 1, ByVal sText
Debug.Print sText
End Sub