locked
Mouse over to get properties of a folder on the desktop

    Question

  •  

    I wish to be able to mouseover a folder on my desktop and get a list of the contents. any ideas
    Saturday, December 22, 2007 11:16 AM

Answers

  • Hi Oyeter,

     

    Based on your post, you need to know the information about the desktop's item.

     

    If your application loses the focus, it can't receive the mouse message. In this scenario your application can't get the item's information in the desktop. I recommend that you directly get the desktop's items information from your application. We can use Environment.GetFolderPath(Environment.SpecialFolder.Desktop) to get the folder path and use Directory.GetFiles and Directory.GetDirectories method to get all nonsystem items. Now we can get the information about these items. If the item is a shortcut(the extension is .ink), we can use Windows Scripting Host Object Model to get this shortcut object and use TargetPath property to know that the shortcut points to folder or file. Also read this thread about getting desktop's icon information. Hope this helps. Here is the simple code example to get the information about nonsystem items.  You need to add a Reference to the Windows Scripting Library.  You do this by right-clicking on the References folder in the Solution Explorer.  Select the Add Reference menu.  From the Add Reference dialog, click the Com Tab and select the Windows Scripting Host Object Model and click the Add button.

    Code Block

    Imports System.IO

    Imports IWshRuntimeLibrary

    Public Class Form3

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

    Dim files() As String = Directory.GetFiles(path)

    Dim dirctories() As String = Directory.GetDirectories(path)

    Dim ws As New WshShell

    Dim shortCut As IWshRuntimeLibrary.IWshShortcut

    For Each fi As String In files

    If (fi.Substring(fi.Length - 4, 4).Equals(".lnk")) Then

    shortCut = CType(ws.CreateShortcut(fi), IWshRuntimeLibrary.IWshShortcut)

    MessageBox.Show(shortCut.TargetPath)

    End If

    Next

    For Each di As String In dirctories

    MessageBox.Show(di.ToString)

    Next

    End Sub

    End Class

     

     

     

    Best regards,

    Riquel

     

    Monday, December 24, 2007 8:07 AM
  • I don't suppose you know where the locations of the where desktop icons are stored do you ? For example if I move a desktop icon quit windows and restart it the icon is at the same location but where does windows store that info .

     

    Monday, December 24, 2007 8:55 AM

All replies

  • Hi Oyeter,

     

    Based on your post, you need to know the information about the desktop's item.

     

    If your application loses the focus, it can't receive the mouse message. In this scenario your application can't get the item's information in the desktop. I recommend that you directly get the desktop's items information from your application. We can use Environment.GetFolderPath(Environment.SpecialFolder.Desktop) to get the folder path and use Directory.GetFiles and Directory.GetDirectories method to get all nonsystem items. Now we can get the information about these items. If the item is a shortcut(the extension is .ink), we can use Windows Scripting Host Object Model to get this shortcut object and use TargetPath property to know that the shortcut points to folder or file. Also read this thread about getting desktop's icon information. Hope this helps. Here is the simple code example to get the information about nonsystem items.  You need to add a Reference to the Windows Scripting Library.  You do this by right-clicking on the References folder in the Solution Explorer.  Select the Add Reference menu.  From the Add Reference dialog, click the Com Tab and select the Windows Scripting Host Object Model and click the Add button.

    Code Block

    Imports System.IO

    Imports IWshRuntimeLibrary

    Public Class Form3

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

    Dim files() As String = Directory.GetFiles(path)

    Dim dirctories() As String = Directory.GetDirectories(path)

    Dim ws As New WshShell

    Dim shortCut As IWshRuntimeLibrary.IWshShortcut

    For Each fi As String In files

    If (fi.Substring(fi.Length - 4, 4).Equals(".lnk")) Then

    shortCut = CType(ws.CreateShortcut(fi), IWshRuntimeLibrary.IWshShortcut)

    MessageBox.Show(shortCut.TargetPath)

    End If

    Next

    For Each di As String In dirctories

    MessageBox.Show(di.ToString)

    Next

    End Sub

    End Class

     

     

     

    Best regards,

    Riquel

     

    Monday, December 24, 2007 8:07 AM
  • I don't suppose you know where the locations of the where desktop icons are stored do you ? For example if I move a desktop icon quit windows and restart it the icon is at the same location but where does windows store that info .

     

    Monday, December 24, 2007 8:55 AM
  • thannx  Riquel, excellent work ...will implement now ... good stuff!
    Tuesday, December 25, 2007 10:36 PM