getting tittle bar text

  • Thread starter Thread starter shalender verma
  • Start date Start date
S

shalender verma

i want to get the text written in the tittle bar of the
window of any other application which apperars on the back
of the form.

e.g i created a form and minimized that form and then i
opened a ms-word window now i again activated that vb form
i created. now i want the text in the tittle bar of the
word window which appears at the back of my vb form

plase give me the solution
 
Hi Shalender,

I don't think it is easy from what I understand that you want to do, quess
you open 10 word windows, which one you want in that opened form from you.

I think it is easier (not easy) to take the other approach and start a vb
application and than start a word application with it.

I hope this helps a little bit,

Cor
 
Hi,

The getwindowtext api will get the text in the title bar. You need
to know the windows handle to use the api call.

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal
hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal
hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer

Here is an example

Dim pWord As Process

Dim strTitleBar As String = Space(200)

Dim iResult As Integer

pWord = Process.Start("winword.exe")

iResult = GetWindowText(pWord.MainWindowHandle, strTitleBar, 200)

If iResult <> 0 Then

Me.Text = strTitleBar

Else

MessageBox.Show("GetWindowText failed!")

End If

Ken
 
* "Ken Tucker said:
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal
hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal
hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer

Here is an example

Dim pWord As Process

Dim strTitleBar As String = Space(200)

Dim iResult As Integer

pWord = Process.Start("winword.exe")

iResult = GetWindowText(pWord.MainWindowHandle, strTitleBar, 200)

It the OP wants to get the text whenever the application looses/gets
focus, he/she should override the form's 'WndProc' and listen for
'WM_ACTIVATEAPP'. In 'lParam' the handle to the window previously being
the active window or getting active will be passed to 'WndProc'.
 
Back
Top