Hi everyone! It's been a wile
...
I'm currently working on an application that should implement multiple desktops. I have a treeview that I fill with the existing desktops and under each desktop i add child nodes representing the windows. No problem so far, but I would like to add to each node that represents a window the icon of that window (like in TaskBar). Can anyone help me with this, please?
I'm trying to handle this by using LoadIcon API, but I can't get it to work. Following is my code (I've removed the declarations part, to be short):
-In a form with a treeview:
Private Sub Form_Load()
tvWindows.Nodes.Add , , "Primary Desktop", "Primary Desktop"
EnumWindows AddressOf EnumVisibleWindowsProc, ByVal 0&
tvWindows.Nodes.Item("Primary Desktop").Expanded = True
End Sub
- in a module:
Public Function EnumVisibleWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
Dim MyNode As Node
Dim MyIcon As Long
Dim strTextFereastra As String, Ret As Long, MyClassName As String
Ret = GetWindowTextLength(hWnd)
strTextFereastra = Space(Ret)
GetWindowText hWnd, strTextFereastra, Ret + 1
MyClassName = Space(256)
GetClassName hWnd, MyClassName, 256
If strTextFereastra <> "" And IsWindowVisible(hWnd) <> 0 Then
MyIcon = LoadIcon(hWnd, IDI_APPLICATION)
'Form1.ImageList1.ListImages.Add , , LoadIcon(hWnd, IDI_APPLICATION)
Set MyNode = Form1.tvWindows.Nodes.Add("Primary Desktop", tvwChild, "a" & hWnd, strTextFereastra, MyIcon)
End If
EnumVisibleWindowsProc = True
End Function
Notice the use of LoadIcon, but it doesn't work. It always returns "0".
Thanks!
Hope I've been helpful,
Bogdan Muresan.
I'm currently working on an application that should implement multiple desktops. I have a treeview that I fill with the existing desktops and under each desktop i add child nodes representing the windows. No problem so far, but I would like to add to each node that represents a window the icon of that window (like in TaskBar). Can anyone help me with this, please?
I'm trying to handle this by using LoadIcon API, but I can't get it to work. Following is my code (I've removed the declarations part, to be short):
-In a form with a treeview:
Private Sub Form_Load()
tvWindows.Nodes.Add , , "Primary Desktop", "Primary Desktop"
EnumWindows AddressOf EnumVisibleWindowsProc, ByVal 0&
tvWindows.Nodes.Item("Primary Desktop").Expanded = True
End Sub
- in a module:
Public Function EnumVisibleWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
Dim MyNode As Node
Dim MyIcon As Long
Dim strTextFereastra As String, Ret As Long, MyClassName As String
Ret = GetWindowTextLength(hWnd)
strTextFereastra = Space(Ret)
GetWindowText hWnd, strTextFereastra, Ret + 1
MyClassName = Space(256)
GetClassName hWnd, MyClassName, 256
If strTextFereastra <> "" And IsWindowVisible(hWnd) <> 0 Then
MyIcon = LoadIcon(hWnd, IDI_APPLICATION)
'Form1.ImageList1.ListImages.Add , , LoadIcon(hWnd, IDI_APPLICATION)
Set MyNode = Form1.tvWindows.Nodes.Add("Primary Desktop", tvwChild, "a" & hWnd, strTextFereastra, MyIcon)
End If
EnumVisibleWindowsProc = True
End Function
Notice the use of LoadIcon, but it doesn't work. It always returns "0".
Thanks!
Hope I've been helpful,
Bogdan Muresan.