×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Topmost VB form name - active form

Topmost VB form name - active form

Topmost VB form name - active form

(OP)
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

RE: Topmost VB form name - active form

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources