Difficult Question for the programmers out there

Getting count of icons on desktop "broken" by "Fences"

This is really a question that only programmers (.NET programmers) may be able to answer.

I have written the following code, designed to ascertain the number of icons on the main desktop.
It works provided the icons are not stored in a "Fence" placed on the desktop via the program "Fences". 

Does anyone know how to change the code so that the number of icons
(both positioned in different Fences and "floating" outside of a fence) is returned? 

The reason for the code? Under Windows 10, if you place more than 51 items on your desktop (including shortcuts/folders stored directly into a desktop folder) the functionality of the "Browse" window when creating shortcuts is "broken". (See my video: https://youtu.be/kqhk-jH2b8U)

I do not expect anyone will be able to answer this, but I keep my fingers crossed.
(The code is VB.NET by the way)  

==================================================================================================

Imports System.Windows.Forms

Module IconCount

   Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, _
                                                                                                                ByVal lParam As Integer) As Integer
   Private Declare Function GetDesktopWindow Lib "user32" () As IntPtr
   Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
   Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
                                                                                                                  ByVal lpsz2 As String) As Integer
   Private Const LVM_FIRST As Int32 = &H1000S
   Private Const LVM_GETITEMCOUNT As Int32 = (LVM_FIRST + 4)
   Public Const LVM_GETITEMPOSITION As Int32 = (LVM_FIRST + 16)


   Public Sub Main()
      Dim _desktopHandle As Integer = GetSysLVHwnd()
      Dim numberOfIcons As Integer = SendMessage(_desktopHandle, LVM_GETITEMCOUNT, 0, 0)  ' <<===This is the line that returns "0"
      Dim IconFile As String = (numberOfIcons + 1).ToString                                                        '             It is not picking up the icons stored in          
      For Each ctl In Form1.Controls                                                                                            '             "Fences". If I move an icon out of a fence  
         If TypeOf ctl Is PictureBox Then                                                                                       '              it returns "1" and as I move more and more  
            If ctl.Name = "pb" & IconFile Then                                                                                '              icons out of fences, the "numberofIcons" keeps
               Dim opb As PictureBox = ctl                                                                                      '              increasing (by 1 each time). How do I get the
               Form1.Icon = My.Resources.ResourceManager.GetObject("Icon" & IconFile)                  '             number of icons both on desktop and in the fences? 
            End If
         End If
     Next
  End Sub

  Private Function GetSysLVHwnd() As Integer
     Dim lHandle As Long
     lHandle = FindWindowEx(vbNull, vbNull, "Progman", "Program Manager")
     lHandle = FindWindowEx(lHandle, 0, "SHELLDLL_defVIEW", vbNullString)
     Return FindWindowEx(lHandle, 0, "SysListView32", vbNullString)
   End Function

End Module


4,616 views 1 replies
Reply #1 Top

I found this online.  Maybe it will help.

LVM_FIRST :=0x1000 
LVM_GETITEMCOUNT :=(LVM_FIRST +4)
SendMessage,4100,0,0,SysListView321,ProgramManager ahk_class ProgmanMsgBox,%ErrorLevel