Create shortcuts in your app
Read 164 1 Introduction In Windows 3.x, the software installer typically uses dynamic data exchange (DDE) to create a program group in Program Manager (Program " Group). With the tremendous improvement of Windows95 / 98 / NT these 32 operating systems on the system kernel and user interface, this method is no longer applicable. Now, almost all installers add new menu items in the Start menu, or create a new shortcut on the desktop (sometimes establish the corresponding menu group or folder to contain multiple menus. Items or shortcuts) so that the software is quickly quickly and easily when the user is used. Establishing these menu items or shortcuts by manual operation is not complicated, in the general Windows manual, I believe everyone is familiar, and will not be described here. On the basis of the information, the author finds the method of completing the above work in the application. This is exactly necessary to develop the installation program. 2 The shortcuts of shortcuts is actually a data file with extension LNK, which contains all objects for accessing Windows (ie all objects you can browse in the Explorer, including files, folders. , Drives and printers, etc.), such as the path and name, working directory, command line parameters of the target object, initial display status, icon and shortcut keys, etc. of the runtime. These properties of this shortcut can be observed by clicking the right mouse button on the shortcut and selecting "Properties" in the pop-up menu. Shortcut data file If you are stored in a C: / Windows / Desktop subdirectory, this shortcut is displayed on the desktop, and if you are stored in the C: / Windows / "Start Menu" / Programs subdirectory, this shortcut It will appear as a menu item for the "Start" menu. The menu group on the desktop and the "Start" menu is the performance of the subdirectories in the above two subdirectories. 3 Programming WINDOWS Case (Shell) is designed based on the OLE technology component object model COM (Component ObjectModal). With the COM model, an application can call some of the functions of another application. Please refer to the relevant literature for technical details. After understanding the above basic principles, it is easy to create a shortcut to create a Windows. First use OLE to create an IID_IDLLLINK instance by calling the cocreateInstance () function, and getting its interface pointer at the same time. Use this interface pointer to set it. In order to save this information in a shortcut data file (* .Lnk) format, it is also necessary to get its IID_IPERSISTFILE interface pointer from the IID_ISHELLLINK object to facilitate calling its member function save () saves the previous settings. As for how to delete shortcuts and create and delete folders, you only need to simply call file operation functions shfileOperation (). Also, it should be noted that after completing the above operation, call the shchangenotify () function to inform the Windows housing to make it updated in time. 4 Application Example In order to specifically demonstrate the method of use of the above ideas, we have prepared the following example programs (as shown below) with MS VC 5.0. The sample program is a dialog-based application, two circular buttons are used to set the location where to create / delete folders or shortcuts, the following four buttons are used to perform different operations. In addition, the program also requires a simple dialog that enters the name of the folder or shortcut you want to create.
The following is the code you need to add (in the box): // sortcut.cpp: bool csortcutapp :: InitInstance () {... Coinitialize (null); csortcutdlg DLG; m_pmainwnd = & dlg ;. ..... counted false;} // sortcutdlg.cpp: #include "stdafx.h" #include "sortcut.h" #include "sortcutdlg.h" #include "namedlg.h" #IFDEF _Debug #define new DEBUG_NEW # undef THIS_FILEstatic char THIS_FILE [] = __FILE __; # endif file: // PIDLint nBeginAt starting folder = CSIDL_DESKTOPDIRECTORY; ...... /// browse folders BOOL BrowseForFolder (LPITEMIDLIST pidlRoot, // browsing at the beginning of PIDLLPITEMIDLIST * ppidlDestination, file: // when browsing the end of the selected PIDLLPCSTR lpszTitle) // Browse prompt text dialog {BROWSEINFO BrInfo; ZeroMemory (& BrInfo, sizeof (BrInfo)); BrInfo.hwndOwner = HWND_DESKTOP; BrInfo.pidlRoot = pidlRoot; BrInfo.lpszTitle = lpszTitle; file: // Browse for folder * ppidlDestination = SHBrowseForFolder (& BrInfo); file: // user selects a cancel button if (NULL == * ppidlDestination) return FALSE; return TRUE; } File: // Target Application of Shortcuts Name SelectMenuItem (LPSTR SZFileName) {OpenFileName OFN; Static Char Szfilter [] = "Programs / 0 * .exe / 0"; ZeromeMory (& OFN, SIZEOF (Open FILENAME)); ofn.lStructSize = sizeof (OPENFILENAME); ofn.hwndOwner = HWND_DESKTOP; ofn.lpstrFilter = szFilter; ofn.nFilterIndex = 0; ofn.nMaxFile = MAX_PATH; ofn.lpstrTitle = "Please select the target application:"; ofn.lpstrFile = szFileName; ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER; file: // file browser if (GetOpenFileName (& ofn)!) // select the cancel button return FALSE; return TRUE;} file: // made you want to create Shortcut's name Bool getShortcutcrt (lpstr szpath) {LPITEMIDLIST PIDLBEGINAT, PIDLDESTINATION; // Get the PIDLSHGETSPECIALLDERLOCATION (hwnd_desktop, nbeginat, & pidlbeginat) of the start menu or desktop.