Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 Get Path from ShortCut (.Ink)

$
0
0
Hey guys, Im new here and I need help. Im making a Drag-n-Drop application for Windows 7. You simply drag a Shortcut or a Program and the PictureBox shows it icon, and when you click it, it opens the target. But I ran Into a problem, when I use a ShortCut, I can not extract the Icon from it, as from .exe. So I would need you to give me some suggestion what code or what modification I should do In my program.

The IconExtract code is here: (Thats pretty much everything you need to see. If not, tell me and I will post the whole code, with a screenshot of the form)

Code:

Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Integer, ByRef phiconLarge As Integer, ByRef phiconSmall As Integer, ByVal nIcons As Integer) As Integer

 Dim PictureBox1Path As String

    Private Function ReturnIcon(ByVal Path As String, ByVal Index As Integer, Optional ByVal small As Boolean = False) As Icon
        Dim bigIcon As Integer
        Dim smallIcon As Integer
        ExtractIcon(Path, Index, bigIcon, smallIcon, 1)

        If bigIcon = 0 Then
            ExtractIcon(Path, 0, bigIcon, smallIcon, 1)
        End If

        If bigIcon <> 0 Then
            If small = False Then
                Return Icon.FromHandle(bigIcon)
            Else
                Return Icon.FromHandle(smallIcon)
            End If
        Else
            Return Nothing
        End If

    End Function


'The Picture box Drag-n-Drop code:

    Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
        If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub

    Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
        PictureBox1Path = e.Data.GetData(DataFormats.FileDrop)(0)
        PictureBox1.BackgroundImage = ReturnIcon(PictureBox1Path, 0).ToBitmap 'Error Part
    End Sub

'The Picture box Click code:

 Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        If PictureBox1Path <> Nothing Then
            Process.Start(PictureBox1Path)
        End If
    End Sub

Error:
"NullReferenceException was unhandled by user code:
Object reference not set to an instance of an object."

NOTE: I have 16 Picture Boxes, In this example I extracted only one of them.

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>