Announcement

Collapse
No announcement yet.

Adding programs to Start menu...

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

  • Adding programs to Start menu...

    How do you add program icons to the Desktop and Programs Menu?

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

    Thank you,
    Ryan M. Cross
    Head Programmer &
    CEO Retra.net Services
    Thank you,
    Ryan M. Cross

  • #2
    a search the bbs for "shgetspecialfolderlocation" reveals some code that may help. i posted some in the source code forum (it had a small memory leak), and someone used a 3rd-party utility (ja/compb) to create a version that cleaned up correctly after itself. the cleanup is only necessary if you are worried about the very small memory leak, and dont want to add all the overhead to access the com objects correctly.




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

    Comment


    • #3
      Not sure if he answered what you ask or not. How you add shortcuts to the desktop and the start menu is from the folders with those names that are in the windows folder.

      sorry if you know that, or he answered your question.

      Comment


      • #4
        Lance,

        The page you advertise cannot be found. Are you aware of that problem?

        ------------------
        mailto:[email protected][email protected]</A>
        www.basicguru.com/zijlema/

        Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
        http://zijlema.basicguru.eu
        *** Opinions expressed here are not necessarily untrue ***

        Comment


        • #5
          i prefer native method (like windows does - using ishelllink interface): http://www.powerbasic.com/support/pb...ad.php?t=24977

          to place in start up or somewhere wlse, select another %csidl_

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

          Comment


          • #6
            the program involved does not work. i get a param-mismatch error, due to
            the declaration of the 'where'-variable as itemidlist ptr. what else can i declare?
            the winapi32-file is not easy to understand regarding this matter.

            btw: for those who also get a 'not found' error when clicking on 'page 230', the source code can also
            be downloaded from: http://www.powerbasic.com/support/pb...ead.php?t=2914
            where borje hagsten re-posted it on my request.


            ------------------
            mailto:[email protected][email protected]</a>
            www.basicguru.com/zijlema/

            Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
            http://zijlema.basicguru.eu
            *** Opinions expressed here are not necessarily untrue ***

            Comment


            • #7
              [To get it on top again - and may be an answer too)
              The code Lance refers to does not work, most likely due to the ITEMIDLIST PTR declaration.
              What else should I declare to get it running?

              Thanks

              ------------------
              mailto:[email protected][email protected]</A>
              www.basicguru.com/zijlema/

              Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
              http://zijlema.basicguru.eu
              *** Opinions expressed here are not necessarily untrue ***

              Comment


              • #8
                You can also check my helpfile on my site.
                "Create the folder for the shortcuts."

                ------------------
                [email protected]
                hellobasic

                Comment


                • #9
                  egbert,

                  never had a problem with lance' code (same for semen's), but
                  we had a discussion about extensions .lnk and .exe.lnk, resp.
                  http://www.powerbasic.com/support/pb...ad.php?t=17861

                  regards, hanns.

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

                  Comment


                  • #10
                    Ryan,

                    If your question still persists, then maybe the following code for an installer
                    will help. It copies six files into a subfolder of Program Files, and optionally
                    makes shortcuts to the desktop, Start\Programs, and Start\Programs\StartUp.

                    The shortcuts are made using Semen Matusovski's very fine routine, CreateShortcut.
                    To be honest, I don't understand Semen's routine very well, but fortunately, it is
                    very easy to use. Thanks to Semen if this is of any help.


                    Code:
                    #COMPILE EXE
                    #DIM ALL
                    #INCLUDE "win32api.inc"
                    
                    %ID_FolderLabel          = 100
                    %ID_Checkbox1            = 105
                    %ID_Checkbox2            = 110
                    %ID_Checkbox3            = 115
                    %ID_Folder               = 120
                    %ID_Install              = 125
                    %ID_Cancel               = 130
                    %SIZE_KEY = 64
                    %SIZE_VAL = 256
                    
                    DECLARE CALLBACK FUNCTION dlgProc
                    DECLARE SUB CreateShortcut (ln AS STRING, ep AS STRING, wd AS STRING, BYVAL CSIDL AS LONG)
                    DECLARE FUNCTION CoInitialize LIB "ole32.dll" ALIAS "CoInitialize" _
                                    (BYVAL pvReserved AS DWORD) AS DWORD
                    DECLARE FUNCTION CoCreateInstance LIB "ole32.dll" ALIAS "CoCreateInstance" _
                                    (rclsid AS STRING * 16, BYVAL pUnkOuter AS ANY, BYVAL dwClsContext AS DWORD, _
                                     riid AS STRING * 16, ppv AS DWORD) AS DWORD
                    DECLARE SUB CoUninitialize LIB "ole32.dll" ALIAS "CoUninitialize"
                    DECLARE SUB CoTaskMemFree LIB "ole32.dll" ALIAS "CoTaskMemFree" (pv AS DWORD)
                    DECLARE FUNCTION Sub1 (p1 AS ANY) AS DWORD
                    DECLARE FUNCTION Sub2 (p1 AS ANY, p2 AS ANY) AS DWORD
                    DECLARE FUNCTION Sub3 (p1 AS ANY, p2 AS ANY, p3 AS ANY) AS DWORD
                    
                    FUNCTION PBMAIN
                       LOCAL Style AS LONG, hDlg AS LONG
                       Style& = %WS_MINIMIZEBOX + %WS_SYSMENU
                       DIALOG NEW 0, "Install winPam", , ,  245, 177, Style TO hDlg
                       CONTROL ADD CHECKBOX, hDlg, %ID_Checkbox1, "Create shortcut for desktop", 8, 20, 104, 12
                       CONTROL ADD CHECKBOX, hDlg, %ID_Checkbox2, "Create shortcut for Program Menu", 8, 34, 128, 12
                       CONTROL ADD CHECKBOX, hDlg, %ID_Checkbox3, "Include reminders in Startup Menu", 8, 49, 128, 12
                       CONTROL ADD LABEL, hDlg, %ID_FolderLabel, "Folder to Install winPam:",8, 76, 139, 12
                       CONTROL ADD TEXTBOX, hDlg, %ID_Folder, "C:\Program Files\Phone & Address Mgr\", 24, 88, 192, 12
                       CONTROL ADD BUTTON, hDlg, %ID_Install, "&Install", 29, 118, 53, 32
                       CONTROL ADD BUTTON, hDlg, %ID_Cancel, "&Cancel", 101, 118, 53, 32
                       DIALOG SHOW MODAL hDlg, CALL dlgProc
                    END FUNCTION
                    
                    CALLBACK FUNCTION dlgProc()
                       LOCAL ck1 AS LONG, ck2 AS LONG, ck3 AS LONG
                       LOCAL folder AS STRING, path AS STRING
                       LOCAL s AS STRING, i AS INTEGER, nFiles AS INTEGER
                       LOCAL szSubKey AS ASCIIZ * %SIZE_KEY, szValue AS ASCIIZ * %SIZE_VAL
                       LOCAL KeyHandle AS LONG, subKeyHandle AS LONG, dwRetVal AS LONG
                       LOCAL MsgContent AS STRING, valName AS ASCIIZ * %SIZE_KEY
                       STATIC files() AS STRING
                       DIM files(6)
                       SELECT CASE CBMSG
                       CASE %WM_INITDIALOG
                          CONTROL SET CHECK CBHNDL, %ID_Checkbox1, 1
                          CONTROL SET CHECK CBHNDL, %ID_Checkbox2, 1
                          CONTROL SET CHECK CBHNDL, %ID_Checkbox3, 1
                          files(1) = "winPam.exe"
                          files(2) = "winPam.hlp"
                          files(3) = "winPam.cnt"
                          files(4) = "winPam.ico"
                          files(5) = "reminder.exe"
                          files(6) = "uninstall.exe
                       CASE %WM_COMMAND
                          SELECT CASE CBCTL
                             CASE %ID_Install
                                'check for complete set of files
                                path = CURDIR$
                                IF RIGHT$(path, 1) <> "\" THEN path = path + "\"
                                FOR i = 1 TO 6
                                   s = DIR$(path + files(i))
                                   IF LEN(s) THEN INCR nFiles
                                NEXT i
                                IF nFiles < 6 THEN
                                   MSGBOX "Not all install files are present"
                                   DIALOG END CBHNDL: EXIT FUNCTION
                                END IF
                                'copy files to specified folder
                                CONTROL GET TEXT CBHNDL, %ID_Folder TO folder
                                MKDIR folder
                                FOR i = 1 TO 6
                                   FILECOPY path + files(i), folder + files(i)
                                NEXT i
                                'insert registry undelete key and two values
                                szSubKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
                                dwRetVal = RegOpenKey(BYVAL %HKEY_LOCAL_MACHINE, szSubKey, KeyHandle)
                                IF dwRetVal = %ERROR_SUCCESS THEN
                                   szSubKey = "winPam"
                                   RegCreateKey KeyHandle, szSubKey, subKeyHandle
                                   valName = "DisplayName": szValue = "Phone & Addr Mgr"
                                   RegSetValueEx subKeyHandle, valName, 0, %REG_SZ, szValue, %SIZE_VAL
                                   valName = "UninstallString": szValue = "C:\Program Files\Phone & Address Mgr\uninstall.exe"
                                   RegSetValueEx subKeyHandle, valName, 0, %REG_SZ, szValue, %SIZE_VAL
                                END IF
                                'copy selected shortcuts
                                CONTROL GET CHECK CBHNDL, %ID_Checkbox1 TO ck1
                                CONTROL GET CHECK CBHNDL, %ID_Checkbox2 TO ck2
                                CONTROL GET CHECK CBHNDL, %ID_Checkbox3 TO ck3
                                IF ck1 THEN
                                   CreateShortcut "winPam", folder + "winpam.exe", folder, %CSIDL_DESKTOP
                                END IF
                                IF ck2 THEN
                                   CreateShortcut "winPam", folder + "winpam.exe", folder, %CSIDL_PROGRAMS
                                END IF
                                IF ck3 THEN
                                   CreateShortcut "Reminder", folder + "reminder.exe", folder, %CSIDL_STARTUP
                                END IF
                                MSGBOX "winPam successfully installed"
                                DIALOG END CBHNDL
                             CASE %ID_Cancel
                                DIALOG END CBHNDL
                             END SELECT
                       CASE %WM_DESTROY
                       END SELECT
                    END FUNCTION
                    
                    SUB CreateShortcut (ln AS STRING, ep AS STRING, wd AS STRING, BYVAL CSIDL AS LONG)
                       LOCAL LnkName AS ASCIIZ * 32, ExePath AS ASCIIZ * 64, WorkDir AS ASCIIZ * 64
                       LOCAL ShowCmd AS DWORD, Arguments AS ASCIIZ * 1, Comment AS ASCIIZ * 1
                       LOCAL TmpAsciiz AS ASCIIZ * %MAX_PATH, TmpWide AS ASCIIZ * (2 * %MAX_PATH)
                       LOCAL psl AS DWORD PTR, ppf AS DWORD PTR, pp AS DWORD PTR, lResult AS DWORD
                       LOCAL CLSID_ShellLink AS STRING * 16, IID_IShellLink AS STRING * 16
                       LOCAL CLSCTX_INPROC_SERVER AS DWORD, IID_Persist AS STRING * 16
                       LnkName = ln: ExePath = ep: WorkDir = wd
                       Arguments = "": ShowCmd = %SW_NORMAL: Comment = ""
                       CLSID_ShellLink = MKL$(&H00021401) + CHR$(0, 0, 0, 0, &HC0, 0, 0, 0, 0, 0, 0, &H46)
                       IID_IShellLink  = MKL$(&H000214EE) + CHR$(0, 0, 0, 0, &HC0, 0, 0, 0, 0, 0, 0, &H46)
                       IID_Persist     = MKL$(&H0000010B) + CHR$(0, 0, 0, 0, &HC0, 0, 0, 0, 0, 0, 0, &H46)
                       CLSCTX_INPROC_SERVER = 1: CoInitialize %Null
                       IF ISFALSE(CoCreateInstance (CLSID_ShellLink, %Null, CLSCTX_INPROC_SERVER, IID_IShellLink, psl)) THEN
                          pp = @psl + 80: CALL DWORD @pp USING Sub2 (BYVAL psl, ExePath)
                          pp = @psl + 44: CALL DWORD @pp USING Sub2 (BYVAL psl, Arguments)
                          pp = @psl + 36: CALL DWORD @pp USING Sub2 (BYVAL psl, WorkDir)
                          pp = @psl + 60: CALL DWORD @pp USING Sub2 (BYVAL psl, BYVAL ShowCmd)
                          pp = @psl + 28: CALL DWORD @pp USING Sub2 (BYVAL psl, Comment)
                          pp = @psl: CALL DWORD @pp USING Sub3 (BYVAL psl, IID_Persist, ppf) TO lResult
                          IF lResult = 0 THEN
                             DIM pidl AS DWORD
                             TmpAsciiz = CURDIR$
                             IF ISFALSE(SHGetSpecialFolderLocation(BYVAL %HWND_DESKTOP, BYVAL CSIDL, BYVAL VARPTR(pidl))) THEN
                                SHGetPathFromIDList BYVAL pidl, TmpAsciiz
                                CoTaskMemFree BYVAL pidl
                             END IF
                             TmpAsciiz = TmpAsciiz + "\" + LnkName + ".Lnk"
                             MultiByteToWideChar %CP_ACP, 0, TmpAsciiz, -1, TmpWide, %MAX_PATH
                             pp = @ppf + 24: CALL DWORD @pp USING Sub3 (BYVAL ppf, TmpWide, BYVAL %True)
                             pp = @ppf + 8: CALL DWORD @pp USING Sub1 (BYVAL ppf)
                          END IF
                          pp = @psl + 8: CALL DWORD @pp USING Sub1 (BYVAL psl)
                       END IF
                       CoUninitialize
                    END SUB
                    ------------------

                    Comment

                    Working...
                    X