Announcement

Collapse
No announcement yet.

shortcut on desktop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • shortcut on desktop

    september 7th ian wrote "i would like to ... create a shortcut
    for my program onto the windows desktop adding a shortcut
    key to it at the same time". the answer (given by pat?) refers to

    but i got "error processing ssi file" only. does anyone remember the topic?

    thanks for help!
    hanns.

  • #2
    Hans, perhaps this is following code, which you try to find (I downloaded it from Forum or www.basicguru.com - don't remember)
    Of course, you should modify in CreateShortcut the second (catalog), the third (name of exe without .Exe) and fourth parameter (name of shortcut)

    $Register None
    DefInt a-Z
    $Include "WIN32API.INC"

    TYPE strEMID
    cb As Long
    abID As Byte
    End TYPE

    TYPE ITEMIDLIST
    mkid As strEMID
    End TYPE

    Declare Sub SHAddToRecentDocs Lib "shell32.dll" Alias "SHAddToRecentDocs" _
    (ByVal dwFlags As Long, pv As Asciiz)
    Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
    (ByVal pidl As Long, lpszPath As Asciiz) As Long
    Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" Alias "SHGetSpecialFolderLocation" _
    (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Any) As Long

    %CSIDL_BITBUCKET = &HA
    %CSIDL_CONTROLS = &H3
    %CSIDL_DESKTOP = &H0
    %CSIDL_DESKTOPDIRECTORY = &H10 ' On Desktop
    %CSIDL_DRIVES = &H11
    %CSIDL_FAVORITES = &H6 ' In Favorites
    %CSIDL_FONTS = &H14
    %CSIDL_NETHOOD = &H13
    %CDISL_NETWORK = &H12
    %CSIDL_PERSONAL = &H5 ' In Personal folder
    %CSIDL_PRINTERS = &H4
    %CSIDL_PROGRAMS = &H2 ' In Start Menu Programs folder
    %CSIDL_RECENT = &H8 ' Recent Documents list
    %CSIDL_SENDTO = &H9 ' Send To menu (handy)
    %CSIDL_STARTMENU = &HB ' Start Menu (on top)
    %CSIDL_STARTUP = &H7 ' Startup group
    %CSIDL_TEMPLATES = &H15

    %SHARD_PATH = &H2&

    Function CreateShortcut(hWnd As Long, szPath1 As Asciiz, szName As Asciiz, Title As Asciiz, lWhere As Long) As Long
    Dim lResult As Long
    Dim szPathWhere As Asciiz * %MAX_PATH
    Dim lpidlWhere As ITEMIDLIST Ptr
    Dim szPathRecent As Asciiz * %MAX_PATH
    Dim lpidlRecent As Long
    Dim szTarget As Asciiz * %MAX_PATH
    Dim t&
    Dim szPath As Asciiz * %MAX_PATH

    SzPath = szPath1 + "\" + szName + ".exe"

    On Error Resume Next

    Replace "." With "_" In szName
    Replace " " With "" In szName

    lResult = SHGetSpecialFolderLocation(hWnd, lWhere, lpidlWhere)
    If IsTrue lResult Then Exit Function

    Reset szPathWhere
    lResult = SHGetPathFromIDList(lpidlWhere, szPathWhere)
    If IsFalse lResult Then Exit Function

    lResult = SHGetSpecialFolderLocation(hWnd, %CSIDL_RECENT, lpidlRecent)
    If IsTrue lResult Then Exit Function

    Reset szPathRecent
    lResult = SHGetPathFromIDList(lpidlRecent, szPathRecent)
    If IsFalse lResult Then Exit Function

    SHAddToRecentDocs %SHARD_PATH, szPath

    ' If not a RECENT file link, move it to the final position
    If lWhere <> %CSIDL_RECENT Then
    'Wait until file is there to copy
    t& = Timer
    Do
    Sleep 0
    Loop Until Len(Dir$(szPathRecent & "\" & szName & ".lnk")) Or t& + 3 < Timer
    If t& + 3 < Timer Then Exit Function
    FileCopy szPathRecent & "\" & szName & ".lnk", szPathWhere & "\" & Title & ".lnk"
    Kill szPathRecent & "\" & szName & ".lnk"
    End If
    Function = -1
    End Function

    Function WinMain(ByVal hCurInstance As Long, _
    ByVal hPrevInstance As Long, _
    lpszCmdLine As Asciiz Ptr, _
    ByVal nCmdShow As Long) Export As Long

    lResult& = CreateShortcut(0, "D:\Ltr.99\Bas32", "Ltr32", "NameOfShortCut(Change me !)", %CSIDL_DESKTOPDIRECTORY)
    Print lResult&: WaitKey$

    End Function

    Comment


    • #3
      Hi Semen,

      thank you for promptly relpying. I'm out of town now for some days and in a
      hurry, but I think/hope your code will do his job. Thanks!

      Greetings,
      Hanns.

      Comment


      • #4

        Semen,

        changing %max_path=256 and sleep 0 to sleep 10, substituting
        ".lnk" by ".exe.lnk" (???), FileCopy by API-CopyFile and Reset szP to
        szP="", your code is perfectly working (I used PB5).

        Many thanks!
        Hanns.

        Comment


        • #5
          Hanns, sorry for delay, I was in business trip.
          This code (without any changes) works perfect for me in PB/CC 2.0.
          Also there is another way to create a Shortcut (like Internet Explorer' URL). If it's interesting to you I can find it on my computer, but it seems to me that a method, mentioned above, is better.

          Comment


          • #6
            Semen,

            thank you for offering another way to create an icon, but your
            code does his job. The only problem I had was ".exe.lnk" and
            ".lnk", respectively. I guess that Win95 uses ".lnk", but NT
            uses ".exe.lnk" in ..\Recent. I checked this using different
            PC's. Now my program asks for both ".exe.lnk" and ".lnk", but I
            think I must confirm this. (By the way, did I forget to say
            that I'm using PB5, not PB/CC?)

            Thanks again, greetings,
            Hanns

            Comment


            • #7
              the original code posting and discussions is available at

              -------------
              lance
              powerbasic support
              ( mailto:[email protected][email protected]</a> )
              Lance
              mailto:[email protected]

              Comment


              • #8
                Lance,

                thanks for posting your o-code, however, there's the same problem I
                already mentioned above:

                By PB5 and using *W95* (Ver 4.00.1111), SHAddToRecentDocs creates PB5.lnk
                (but not! PB5.exe.lnk, I am using your example) in \Recent, and filecopy
                fails because of expecting PB5.exe.lnk. Using NT, the program correctly
                creates PB5.exe.lnk and filecopy is successful. I think, inserting a line
                of code asking for both PB5.exe.lnk and PB5.lnk helps. That's the only
                problem.

                Hanns.

                Comment


                • #9
                  Hanns --
                  You can avoid a question to user, if you will recognize OS by, for example, following function

                  Function IsNT&()
                  Local os As OSVERSIONINFO
                  os.dwOSVersionInfoSize = SizeOf(os)
                  GetVersionEx ByVal VarPtr(os)
                  Function = (os.dwPlatformId = %VER_PLATFORM_WIN32_NT)
                  End Function

                  If IsTrue(IsNT&) Then "NT4/2000" Else "95/98"

                  But i don't understand a situation with "exe.lnk".
                  On my computer (NT4 + SP5) I don't see that Windows adds it (I see ".lnk" only), and Lance's example with small corrections - because of PB/CC 2.0 - works if to delete ".exe".
                  Which NT release do you have ?



                  [This message has been edited by Semen Matusovski (edited December 03, 1999).]

                  Comment


                  • #10
                    Hi Semen,

                    I thought we had reached the end of the story .... my NT version (German)
                    is 4.00.1381, IE 5 5.00.2014.0216. I do not have any idea about this ...

                    However, I tried the following simple-minded code (PB5, last IF only)
                    without asking for OS, and, evidently, it works under both W95 and NT
                    (or should I say, NT's?).


                    If lWhere <> %CSIDL_RECENT Then
                    'Wait until file is there to copy
                    t& = Timer
                    Do
                    Sleep 10 : szFile1="" : szFile2=""
                    szFile1=Dir$(szPathRecent & "\" & szName & ".lnk") ' Win95???
                    szFile2=Dir$(szPathRecent & "\" & szName & ".exe.lnk") ' WinNT???
                    Loop Until Len(szFile1) Or LEN(szFile2) Or t&+10 < Timer
                    If t&+10 < Timer Then Exit Function
                    If LEN(szFile1) then
                    szNameE=szName
                    Else
                    szNameE=szName+".exe"
                    End If
                    CopyFile szPathRecent & "\" & szNameE & ".lnk", szPathWhere & "\" & Title & ".lnk" , 0
                    Kill szPathRecent & "\" & szNameE & ".lnk"
                    End If

                    Regards,
                    Hanns.

                    Comment


                    • #11
                      Hello, Hanns ! I fully agree with your decision (not necessary to think).

                      Comment


                      • #12
                        I am using PBCC 2.0 and windows 98.

                        I took code posted by Semen and modified as per Hanns comments.
                        When I compile and run the code, it does not create a shortcut.

                        SHGetPathFromIDList function works ok and returns szPathWhere and
                        szPathRecent correctly. SHAddToRecentDocs does not seem to create
                        file in \windows\recent subdirectory.

                        I will appreciate any help.

                        Thanks.

                        Here is the code:

                        Code:
                              #COMPILE EXE
                              #REGISTER NONE
                              #DIM ALL
                        
                              #INCLUDE "WIN32API.INC"
                        
                              TYPE strEMID
                                 cb AS LONG
                                 abID AS BYTE
                              END TYPE
                        
                              TYPE ITEMIDLIST
                                mkid AS strEMID
                              END TYPE
                        
                              DECLARE SUB SHAddToRecentDocs LIB "shell32.dll" ALIAS "SHAddToRecentDocs" _
                                 (BYVAL dwFlags AS LONG, pv AS ASCIIZ)
                              DECLARE FUNCTION SHGetPathFromIDList LIB "shell32.dll" ALIAS "SHGetPathFromIDListA" _
                                 (BYVAL pidl AS LONG, lpszPath AS ASCIIZ) AS LONG
                              DECLARE FUNCTION SHGetSpecialFolderLocation LIB "shell32.dll" ALIAS "SHGetSpecialFolderLocation" _
                                 (BYVAL hwndOwner AS LONG, BYVAL nFolder AS LONG, pidl AS ANY) AS LONG
                        
                              %CSIDL_BITBUCKET        = &HA
                              %CSIDL_CONTROLS         = &H3
                              %CSIDL_DESKTOP          = &H0
                              %CSIDL_DESKTOPDIRECTORY = &H10    ' On Desktop
                              %CSIDL_DRIVES           = &H11
                              %CSIDL_FAVORITES        = &H6     ' In Favorites
                              %CSIDL_FONTS            = &H14
                              %CSIDL_NETHOOD          = &H13
                              %CDISL_NETWORK          = &H12
                              %CSIDL_PERSONAL         = &H5     ' In Personal folder
                              %CSIDL_PRINTERS         = &H4
                              %CSIDL_PROGRAMS         = &H2     ' In Start Menu Programs folder
                              %CSIDL_RECENT           = &H8     ' Recent Documents list
                              %CSIDL_SENDTO           = &H9     ' Send To menu (handy)
                              %CSIDL_STARTMENU        = &HB     ' Start Menu (on top)
                              %CSIDL_STARTUP          = &H7     ' Startup group
                              %CSIDL_TEMPLATES        = &H15
                        
                              %SHARD_PATH = &H2&
                        
                           FUNCTION CreateShortcut(hWnd AS LONG, szPath1 AS ASCIIZ, szName AS ASCIIZ, Title AS ASCIIZ, lWhere AS LONG) AS LONG
                              DIM lResult AS LONG
                              DIM szPathWhere AS ASCIIZ * 256
                              DIM lpidlWhere AS ITEMIDLIST PTR
                              DIM szPathRecent AS ASCIIZ * 256
                              DIM lpidlRecent AS LONG
                              DIM szTarget AS ASCIIZ * 256
                              DIM t&
                              DIM szPath AS ASCIIZ * 256
                        
                              LOCAL szFile1 AS STRING
                              LOCAL szFile2 AS STRING
                              LOCAL  szNameE AS STRING
                        
                              SzPath = szPath1 + "\" + szName + ".exe"
                        
                              ON ERROR RESUME NEXT
                        
                              REPLACE "." WITH "_" IN szName
                              REPLACE " " WITH "" IN szName
                        
                              lResult = SHGetSpecialFolderLocation(hWnd, lWhere, lpidlWhere)
                              IF ISTRUE lResult THEN EXIT FUNCTION
                        
                              szPathWhere=""
                              lResult = SHGetPathFromIDList(lpidlWhere, szPathWhere)
                              IF ISFALSE lResult THEN EXIT FUNCTION
                        
                              lResult = SHGetSpecialFolderLocation(hWnd, %CSIDL_RECENT, lpidlRecent)
                              IF ISTRUE lResult THEN EXIT FUNCTION
                        
                              szPathRecent=""
                              lResult = SHGetPathFromIDList(lpidlRecent, szPathRecent)
                              IF ISFALSE lResult THEN EXIT FUNCTION
                        
                              SHAddToRecentDocs %SHARD_PATH, szPath
                        
                              ' If not a RECENT file link, move it to the final position
                              IF lWhere <> %CSIDL_RECENT THEN
                                 'Wait until file is there to copy
                                 t& = TIMER
                                 DO
                                    SLEEP 10
                                    szFile1=""
                                    szFile2=""
                        
                                    szFile1=DIR$(szPathRecent & "\" & szName & ".lnk") ' Win95???
                                    szFile2=DIR$(szPathRecent & "\" & szName & ".exe.lnk") ' WinNT???
                                 LOOP UNTIL LEN(szFile1) OR LEN(szFile2) OR t&+10 < TIMER
                        
                                 IF t&+10 < TIMER THEN EXIT FUNCTION
                        
                                 IF LEN(szFile1) THEN
                                    szNameE=szName
                                 ELSE
                                    szNameE=szName+".exe"
                                 END IF
                        
                                 CopyFile szPathRecent & "\" & szNameE & ".lnk", szPathWhere & "\" & Title & ".lnk" , 0
                                 KILL szPathRecent & "\" & szNameE & ".lnk"
                              END IF
                              FUNCTION = -1
                           END FUNCTION
                        
                           FUNCTION WINMAIN(BYVAL hCurInstance AS LONG, _
                                         BYVAL hPrevInstance AS LONG, _
                                         lpszCmdLine         AS ASCIIZ PTR, _
                                         BYVAL nCmdShow      AS LONG) EXPORT AS LONG
                        
                              LOCAL lResult&
                              
                        '      lResult& = CreateShortcut(0, "D:\Ltr.99\Bas32", "Ltr32", "NameOfShortCut(Change me !)", %CSIDL_DESKTOPDIRECTORY)
                              lResult& = CreateShortcut(0, "C:\fmap80", "fmap801m", "fma", %CSIDL_DESKTOPDIRECTORY)
                        
                        '      MSGBOX STR$(lResult&)
                              PRINT lResult&
                              WAITKEY$
                        
                           END FUNCTION

                        ------------------
                        Gajanan Raje

                        Comment


                        • #13
                          gajanan --
                          forget this code.
                          download latest inc files from http://www.powerbasic.com/files/pub/pbwin/ and use http://www.powerbasic.com/support/pb...ad.php?t=24977
                          (replace msgbox to print; it's enough)


                          ------------------
                          e-mail: [email protected]

                          Comment


                          • #14
                            Semen,

                            Thanks a lot. Your code works like a charm.

                            I appreciate your valuable contribution to this forum.

                            Gajanan

                            ------------------
                            Gajanan Raje

                            Comment


                            • #15
                              Semen, Gajanan,

                              me and my users (of course, as far as I know) never had a problem with the
                              CreateShortcut-function (OSs Win95/98/98SE/NT4, lots of PCs), however, I'm
                              exclusively using PB6, but *not* PBCC as Gajanan ... ?

                              Regards, Hanns.


                              ------------------




                              [This message has been edited by Hanns Ackermann (edited November 10, 2000).]

                              Comment


                              • #16
                                Haans,

                                I tried it with PBDLL 6.0 also, and it did not work. I am using
                                windows 98. It is possible that I may be having different version
                                of Shell32.dll.

                                Semen's new code works well, so now I am using that.

                                Gajanan

                                ------------------
                                Gajanan Raje

                                Comment


                                • #17
                                  Hanns --
                                  I don't remember serious problems with Lance code, but this method is WORKAROUND.
                                  IShellLink interface is direct and more powerful way, because allows to fill all fields and so on.

                                  ------------------
                                  E-MAIL: [email protected]

                                  Comment


                                  • #18
                                    Convinced now ... Thanks Semen and Gajanan!
                                    Regards, Hanns.

                                    ------------------

                                    Comment

                                    Working...
                                    X