Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Topmost VB form name - active form

Status
Not open for further replies.

b1724

Industrial
May 11, 2002
1
How do I find out the name of the topmost form
in a VB6 program.
I can determine the hWind but I do not know
how to find out the VB name of the form.

b1724@110.net
 
Replies continue below

Recommended for you

As you can get the windows handle the following should suffice.

First place the following API functions in a module:

Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
(ByVal hWnd As Long, _
ByVal lpString As String, _
ByVal nMaxCount As Long) As Long

Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" _
(ByVal hWnd As Long) As Long


Create a Label control and name it 'lblWindowText'
Then insert the following code (enough here for you to have a play around with!) in say, the click event of a command button:

Dim intWinTextLength As Long
dim lngResult as Long
Dim strWinText As String ' receives the copied text from the target window

'Get the space required for the window title
intWinTextLength = GetWindowTextLength(hwndWin) + 1 'add one for null character
lblWindowTextLength = CStr(intWinTextLength - 1)

'Get Window text
' First, determine how much space is necessary for the buffer.
' (1 is added for the terminating null character.)
intWinTextLength = SendMessage(hwndWin, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1
' Make enough room in the buffer to receive the text.
strWinText = Space(intWinTextLength)
' Copy the target window's text into the buffer.
lngResult = SendMessage(hwndWin, WM_GETTEXT, ByVal intWinTextLength, ByVal strWinText)
' Remove the terminating null and extra space from the buffer.
strWinText = Left(strWinText, lngResult)
' Display the result.
lblWindowText = strWinText


Have fun
Derrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor