Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

WinAPI Help (GetWindowText, GetWindowTextLength, GetClassName)

Status
Not open for further replies.

dllCoRupT626

Programmer
Oct 15, 2002
12
0
0
US
Right to the point... I'm trying to List all of the Top LvL Window's, Everything works fine until it try's to get the ClassName of the Window and the Window Text (Title Bar).

This is all in a module:

'Declare's


Public Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Integer

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

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

Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Integer) As Boolean

'Function's


Public Function fGetTopLvLWindowsEnumProc(hWnd As Long, ByVal lParam As Long) As Boolean
Dim tmpWinLen, tmpClassLen As Long
On Error GoTo error_Handler

If topWindowNames(1) <> &quot;¬ÑÉÑáѦÖÑä¬&quot; Then
ReDim Preserve topWindowNames((UBound(topWindowNames) + 1))
End If
If topWindowClassNames(1) <> &quot;¬ÑÉÑáѦÖÑä¬&quot; Then
ReDim Preserve topWindowClassNames((UBound(topWindowClassNames) + 1))
End If
If topWindowHandles(1) <> 0 Then
ReDim Preserve topWindowHandles((UBound(topWindowHandles) + 1))
End If

tmpWinLen = GetWindowTextLength(hWnd)
Call GetWindowText(hWnd, topWindowNames(UBound(topWindowNames)), tmpWinLen + 1)
topWindowHandles(UBound(topWindowHandles)) = hWnd
tmpClassLen = GetClassName(hWnd, topWindowClassNames(UBound(topWindowClassNames)), 151)

If topWindowNames(UBound(topWindowNames)) = &quot;&quot; Then topWindowNames(UBound(topWindowNames)) = &quot;No-Name&quot;
frmMain.View1.ListItems.Add , , hWnd
frmMain.View1.ListItems.Item(I).SubItems(1) = topWindowClassNames(UBound(topWindowClassNames))
frmMain.View1.ListItems.Item(I).SubItems(2) = topWindowNames(UBound(topWindowNames))
I = I + 1

fGetTopLvLWindowsEnumProc = True 'Tell's EnumWindows to continue
Exit Function

error_Handler:
fGetTopLvLWindowsEnumProc = False 'Tell's EnumWindows to stop
End Function

Public Function fGetTopLvLWindows() As Boolean
On Error GoTo error_Handler

fGetTopLvLWindows = True
ReDim topWindowNames(1) 'Clear's the array
ReDim topWindowClassNames(1) 'Clear's the array
ReDim topWindowHandles(1) 'Clear's the array
topWindowNames(1) = &quot;¬ÑÉÑáѦÖÑä¬&quot;
topWindowClassNames(1) = &quot;¬ÑÉÑáѦÖÑä¬&quot;
topWindowHandles(1) = 0

I = 1
frmMain.View1.ColumnHeaders.Add , , &quot;Handle&quot;, ((frmMain.View1.Width / 3) - 110)
frmMain.View1.ColumnHeaders.Add , , &quot;Class Name&quot;, ((frmMain.View1.Width / 3) - 110)
frmMain.View1.ColumnHeaders.Add , , &quot;Window&quot;, ((frmMain.View1.Width / 3) - 110)

EnumWindows AddressOf fGetTopLvLWindowsEnumProc, False

'Take this code out, and add the windows to the text queue
'I = 1
'Dim window
'frmMain.View1.ColumnHeaders.Add , , &quot;Handle&quot;, ((frmMain.View1.Width / 3) - 110)
'frmMain.View1.ColumnHeaders.Add , , &quot;Class Name&quot;, ((frmMain.View1.Width / 3) - 110)
'frmMain.View1.ColumnHeaders.Add , , &quot;Window&quot;, ((frmMain.View1.Width / 3) - 110)
'For Each window In topWindowNames
' If window = &quot;&quot; Then window = &quot;No-Name&quot;
' frmMain.View1.ListItems.Add , , topWindowHandles(I)
' frmMain.View1.ListItems.Item(I).SubItems(1) = topWindowClassNames(I)
' frmMain.View1.ListItems.Item(I).SubItems(2) = window
' I = I + 1
'Next window

Exit Function

error_Handler:
fGetTopLvLWindows = False
End Function



Everything actually work's but GetClassName put's NULL in topWindowClassNames(UBound(topWindowClassNames)) even though i put nMaxCount to 151, GetWindowText put's NULL in topWindowNames(UBound(topWindowNames)) to, and GetWindowTextLength Return's 0.

That never change's :(
And i know the Handle to the window is right cause i checked it with another program.

Plz help
 
Double post. Respond in thread222-473961. Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top