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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create icons on desktop

Status
Not open for further replies.

vpraveenkumar

Programmer
Aug 26, 2001
2
0
0
IN
I want to create icon on desktop? how to create icons on desktop using visual basic application
 
This will place a shortcut on the desktop with the icon of your choice:
[/code]
Private Declare Function fCreateShellLink _
Lib "VB5STKIT.DLL" _
(ByVal lpstrFolderName As String, _
ByVal lpstrLinkName As String, _
ByVal lpstrLinkPath As String, _
ByVal lpstrLinkArgs As String) As Long
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Private Declare Function SHGetSpecialFolderLocation _
Lib "shell32.dll" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
pidl As ITEMIDLIST) As Long
Private Declare Function SHGetPathFromIDList _
Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long
Dim DeskTop$
Dim LinkName$
Dim AppLoc$
Dim IconFile$
Dim IconIndex As Integer

Private Function GetSpecialfolder(CSIDL As Long) As String
Dim r As Long
Dim IDL As ITEMIDLIST
r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If r = NOERROR Then
Path$ = Space$(512)
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
Exit Function
End If
GetSpecialfolder = ""
End Function

Private Function CreateLink()
Retval = fCreateShellLink("..\..\Desktop", LinkName$, AppLoc$, "")
DoEvents
If IconFile$ = "" Then Exit Function
LinkFile$ = DeskTop$ & "\" & LinkName$ & ".LNK"
ff = FreeFile
Open LinkFile$ For Binary As #ff
Fbuffer$ = String$(LOF(ff) + Len(IconFile$) + 2, 0)
Get #ff, 1, Fbuffer$
Mid$(Fbuffer$, 21, 1) = Chr$(87)
Mid$(Fbuffer$, 57, 1) = Chr$(IconIndex)
Eloc = InStrRev(Fbuffer$, ":")
Mid$(Fbuffer$, Eloc + 1, Len(IconFile$) + 2) = _
Chr$(39) & Chr$(0) & IconFile$
Put #ff, 1, Fbuffer$
Close #ff
End Function

Private Sub Command1_Click()
DeskTop$ = GetSpecialfolder(0)
LinkName$ = "My Desktop Link"
AppLoc$ = "C:\MyApp.exe"
' Get the Icon from an Icon file
IconFile$ = "C:\Windows\Icons\Disk09.ICO"
IconIndex = 0
Retval = CreateLink
'----- OR -----
' Use an Icon from a DLL:
' specify the icon index
'IconFile$ = "C:\Windows\Moricons.DLL"
'IconIndex = 8
'Retval = CreateLink
End Sub

Code:
I seem to remember a better way to do this using only the API but, at the moment, I can't locate the code. I'll dig around.

See also: thread204-123788

 [center][img]http://www.vorpalcom.com/images/VCA.gif[/img]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top