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

Setting Desktop Icons 3

Status
Not open for further replies.

Gazzza

Programmer
Dec 21, 2000
16
AU
I do have one other problem that I'm having some trouble with. In this VB program i'm working on, I create a icon on the desktop using the fCreateShellLink function.

ie.
lReturn = fCreateShellLink("\" & MENU_NAME, "TCS - " & strCompanyName, strPath1, strArgs, -1, "$(Programs)")

Now this creates a icon with the following path;

"c:\program files\microsoft office\office\msaccess.exe" "c:\program files\IceRidge\tcs.mde" /runtime

This path opens the access program via Access 2000 runtime.

This shortcuts icon is the default Access icon. Is there any was in my code that i can assign an icon i have created for this shortcut?

If you have any suggestions i would much appreciate it.

Thanks

Garry
 
Maybe this will help. Use fCreateShellLink to create the link and then use brute force to modify it to use either an icon file on a disk or one stored in a DLL....

(BTW: This uses SHGetSpecialFolderLocation to determine the path to the desktop, where the link is created. You might also want to programmatically determine the paths to your application and chosen icons, rather than hard-coding them, as I have done here.)
[tt]
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$ = "D:\Windows\Vb\Icons\Computer\Disk09.ICO"
IconIndex = 0
Retval = CreateLink

'----- OR -----
' Use an Icon from a DLL
IconFile$ = "D:\Windows\Moricons.DLL"
IconIndex = 8
Retval = CreateLink
End Sub
[/tt]

VCA.gif
 
RE: SHGetSpecialFolderLocation
...Another user chiming in...

My need was only to get the path to the Desktop.

And I found the way in Alt255's code, in an API. To get it to compile (within VBA of Access97, with Option Explicit set), I had to declare Path$ and declare NOERROR, which I suspect -- but can't confirm at this moment -- are native to VB. I used:
Code:
'----declared by me; I don't have
'----full-blown VB here to check these
'
Dim Path$  '...modeling other declarations
           'It is probably a native function in
           'full-blown VB.
Const NOERROR = 0  '... reasoning that an
                   'undeclared variable would
                   'be 0 (since it is compared
                   'to a variable declared as a
                   'long).  It is probably a
                   'native constant in
                   'full-blown VB.
'----end declared by me.

It worked on my Win NT 4.0 machine! Off to test on others. This is **MUCH** sought-after functionality, if it works on multiple platforms! I found several threads asking for this, without answer, and with only the WiSH suggested as an answer.

... off testing ... [laser][hammer] ... okay, I'm back![pipe]

It works on a Windows 2000 Professional PC and on a Windows 98 PC, and on another couple of Windows NT machines! I pronounce it good. I'm so happy, I could just [cry].

And I'm going to post new FAQs, "Get the Desktop Path in multiple Windows systems!" and, "Map network drives and Unmap network drives in multiple Windows systems!" in Access, VB, and this forum! I'll give the info I found and my code for each. Share the wealth. I love this place! -- C Vigil =)
(Before becoming a member, I also signed on several posts as
"JustPassingThru" and "QuickieBoy" -- as in "Giving Quick Answers")
 
... Haven't written or posted the FAQs just yet, but I still intend to; gotta get the free time away from the work to do it ;-) ... -- C Vigil =)
(Before becoming a member, I also signed on several posts as
"JustPassingThru" and "QuickieBoy" -- as in "Giving Quick Answers")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top