Two methods for creating an installer
● Peng Jin Zhao Xin
Creating an installation sequence is one of the frequently asked questions of the programmers. In this article, we only discuss two methods for creating setup procedures on Windows platforms.
1. Use Visual C ++ to compile a setup procedure
The method for generating the most direct setup procedure is implemented through the programming procedure. For Windows platforms, there are no better tools than visual C ++ (because the ticket is simple, who can better solve Windows platforms than Microsoft ?). The following example is compiled and translated using Visual C ++ 5.0.
The setup procedure mainly deals with two questions:
(1) user interface. When evaluating the advantages and disadvantages of a setup procedure, whether the user interface is beautiful is one of the important factors. In addition, the intercommunication interface should be able to obtain the user's related information (such as the object category ).
(2) generate a copy of the document and a sequence. It is also based on the information input by the user, generate the appropriate contents and complete the copy function (this involves solving the pressure reduction problem ). In general, it should also include adding the diagrams of executable files to the specified sequence group.
1. Set background for setup
The user interface of the setup procedure is centered on the conversation box. If there is a beautiful background, it will increase the color of your procedure. You can select an appropriate BMP file and insert it into the project, it is displayed by the onpaint () function of the main window class that has been reloaded. It is worth noting that the back-view image should not be too dizzy, or it will have the feeling of winning the master. For example, the ID of the BMP file to be added is idb_bit. The number of letters that should be added to onpaint () in the lower part.
Void background (CDC * PDC)
{CDC * pmem;
Cbitmap * pback;
Cbitmap * pold;
Bitmap ff;
Pmem = new CDC;
Pbit = new cbitmap;
Pbit-> loadbitmap (idb_bit );
Pmem-> createcompatibledc (PDC );
Pold = (cbitmap *) pmem-> SelectObject (pbit );
Pbit-> GetObject (sizeof (ff), & ff );
PDC-> bitblt (0, 0, BM. bmwidth, BM. bmheight, pmem, 0, 0, mergecopy );
Delete pmem-> SelectObject (pold );
Delete pmem;
Return;
}
2. display the Full Screen Effect
Generally, the main window has a border (Border). If you are more interested in the full screen effect of the DOS interface, it is best to re-load cwnd :: CS is maintained during precreatewindow (createstruct & CS. the style parameter value is missing, and createex (ws_ex_to pmost, afxregisterwndclass (cs_vredraw), null, ws_visible | ws_popup, 0, 0, (getsystemmetrics (sm_cxscreen), (getsystemmetrics (sm_cyscreen), hwnd_desktop, 0 );.
3. Storage public Parameters
You can exchange messages with the user through the peer dialog box. Then, how can we save the required parameters (such as installation and installation) during the sequential operation? However, you can generate a configuration file, and save the relevant information into the system's INI file. For example, if the platform is Windows 95, all the switches will be simplified, because win is the correct one. INI file, which is in the Windows directory. Visual c ++ provides a set of letters as follows to operate the file.
(1) cwinapp: getprofilestring
Cstring getprofilestring (maid, maid, maid );
Used to read the lpszentry parameter in the lpszsection. The missing value is lpszdefault.
(2) cwinapp: writeprofilestring
Bool writeprofilestring (maid, maid, maid );
Used to write the number of lpszentry parameters in the lpszsection field. The value is lpszvalue.
If your development platform is WINNT, it will be annoying. If your changes are stored in E: // winnt/SDI. ini, you must call them before using them:
Free (void *) m_pszprofilename );
M_pszprofilename = _ tcsdup (_ T ("E: // winnt // SDI. ini "));
If there are not many changes to be saved, you can store them in the registry key. Assume that your changes are stored in the moon registration key (the name of your company, then it must be called before using the letter:
Free (void *) m_pszregistrykey );
M_pszregistrykey = _ tcsdup (_ T ("hkey_current _ User // software // moon "));
4. Copy and decompress the file
If your installation sequence is Pin-to-soft disk, the storage space becomes a question that must be considered. It is too silly to copy the shell in the process sequence without interrupting the original seal. The more appropriate method is to compress the application in the soft disk in the process sequence, during installation, decompress the package to the corresponding category. Visual c ++ provides a set of letters starting with LZ, which can be used to compress compressed files: You can use lzopenfile () open the source file and the target file, and then use lzcopy () to decompress the copy shell. Call lzexpand in windows. DLL dynamic link library. When compiling and translating links, you must add the header file lzexpand. h, and insert the access library lz32.lib.
There is also a simpler way to do this, that is, first use the common pressure reduction sequence like arj.exe to scale down the original process, then call system ("ARJ... ") to complete the decompression and contraction, the whole decompression process is on the backend. the user will not know what method you are using at the bottom.
5. display the progress of the copy Shell
Many specialized installation procedures are displayed in the Level bar when you copy files, even with animations. How can this effect be achieved? The method is to create a modeless dialog box when copying shells. This pair of phone boxes is created using the CREATE () function. It is similar to creating a new line that is independent from the main line. In this way, the copy-to-bay progress can be displayed in the dialog box when the copy-to-bay file is the same. Visual c ++ provides two very useful controls, canimatectrl and cprogressctrl. You can draw these two controls in the dialog box and add the corresponding class with classwizard. Canimatectrl is used for display. the AVI file can be used to initiate a "flying small paper" file after each file copy is completed; cprogressctrl is used to show the progress of the copy shell. When each copy is successful, the blue bars of the table shows the progress are placed in the proper position.
6. Generate a sequence group and a sequence item
In practice, the production of a sort group is compared with the program manager of the responsible manager group, you can use this pair to add the corresponding sequence group and the graph of the expected sequence. At the same time, this pair of calls is unidirectional, and the number of callback () functions that are responsible for anti-feedback are not handled. The following shows the source sequence and its usage.
Hddedata callback ddecallback (uint utype, // transaction type
Uint UFMT, // Clipboard data format
Hconv, // handle to the conversation
Hsz hsz1, // handle to a string
Hsz hsz2,
// Handle to a string
Hddedata hdata, // handle to a global Memory Object
DWORD dwdata1,
// Transaction-specific data
DWORD dwdata2
// Transaction-specific data
)
{Return NULL ;}
Sendddecmd (lpstr cmd)
{
Lpdword dwddeinst = 0l;
Uint UI;
Hsz hszservice, hsztopic, hszitem;
Hconv;
Hddedata hexecdata;
Ui = ddeinitialize (unsigned long *) & dwddeinst, ddecallback, cbf_fail_allsvrxactions, 0l );
If (ui! = Dmlerr_no_error)
{Return false ;}
Hszservice = ddecreatestringhandle (DWORD) dwddeinst, "progman", cp_winansi );
Hsztopic = ddecreatestringhandle (DWORD) dwddeinst, "progman", cp_winansi );
Hszitem = ddecreatestringhandle (DWORD) dwddeinst, "group", cp_winansi );
Hconv = ddeconnect (DWORD) dwddeinst, hszservice, hsztopic, null );
Ddefreestringhandle (unsigned long) dwddeinst, hszservice );
Ddefreestringhandle (unsigned long) dwddeinst, hsztopic );
Ddefreestringhandle (unsigned long) dwddeinst, hszitem );
If (! Hconv)
Return false;
Hexecdata = ddecreatedatahandle (DWORD) dwddeinst, (unsigned char *) cmd, lstrlen (CMD) +, null );
Ddeclienttransaction (unsigned char *) hexecdata, (DWORD)-1, hconv, null, 0, xtyp_execute, 1000, null );
Ddedisconnect (hconv );
Ddeuninitialize (unsigned long) dwddeinst );
Return true;
}
If you want to add a program group named "Demo", the package contains a program item named "test" and runs C: /demo/test.exe, which uses "test. ICO, you can use this function as follows:
Sendddecmd ("[creategroup (DEMO)] [additem (C:/demo/test.exe, test, C:/demo/test. ico)]")
Ii. Create an installation sequence by using hardware software
The use of Visual C ++ programming can generate a strong setup procedure. No. If you prefer to use the existing tools, you may try to use the software installshield5 Free Edition for creating the installation program. This software provides a programming language similar to basic, which is easy to understand.
When creating a new installation sequence, you can start with Project Wizard. The first start is a welcome dialog box, it includes the following content:
(1) Application name (edit box)
Enter the name of the program you want to install in this peer box, installShield will use this word to register and generate your sequence group.
(2) Development Environment (list box)
Select the environment (such as Visual C ++) where the application is to be sent ).
(3) Application Type (list box)
Select the type of the program that you want to use.
(4) application version (edit box)
Select your expected version.
(5) application executable (edit box)
Enter the main running part of the program, or click... to find the file.
(6) Click "Next Step" and select dialogs
Select the dialog box REQUIRED for the installation process. If you cannot confirm it, You can preview it by pressing the preview key.
(7) single-click "Next Step" and select the system platform suitable for this application. You can choose Win 95, winnt 3.x, or winnt4.0.
(8) Click "Next Step" and select the language used for installation. In this free version, the only choice you can make is "English ".
(9) If you want to include multiple installation types in your installation sequence, click "Next Step ". The activation dialog box provides the above functions. You can choose among the following security class types: compact, typical, M m, and network.
(10) Click "Next Step" and select the group you want to install, these components are not in the same group, that is, they are different from the installation type you selected on the top.
(11) Click "Next Step" and select the file group you want to create, this file group is the collection of documents that should be included in the program sequence.
(12) single-click "Next Step" to include the information you entered (that is, "summary. If it is not full, you can modify it. If it is full, press the "complete" key, the frame of an installation procedure is successful.
The following describes the process documents used for installation.
In practice, Project Wizard has done a lot of work for you. In order to create a complete installation sequence, you must first clear the relationship between each item in the work flow document. This should start with file group. A file group is a collection of optional parts of the program. There is a link under each file folder. You can use the right key to single-click the position, if you select the insert item, you can add your text to the group. Each file group contains a dry property value. If you click this property, you can modify it. For example, for compress items, you can choose whether to perform compression on the files in the file group. Several file groups can belong to the same component. By dividing the component, you can install different operators in different regions. Each component also has a dry nature: in it, the destination item is for you to select the object to which the component will be installed; the installation item is used to select the processing method when the same file name is used; the setuptype item is used to select components installed by different security classes ). Next, you will enter the script files item, which is the script of your installation procedure, if you only want to create a standard installation sequence, you only need to make minor changes to it. Because the system does not have a part for you to create a sequence group, you must manually modify the number of function setupfolders () functions in dialogshowsdselectfolder, the installation script has already saved the project sequence group to the variable svdefgroup, so you only need to go to setupfolders () (If you want to add an item named "Demo", execute the C:/demo.exe file, the image used is marked as "C:/demo. ICO, the job is recorded as "C:/test", with "CTRL + ALT + 1" as the hot key, and the sort item will be the first in the SORT group, and the sort item will be maximized when it is executed ).
String szprogram = "C:/demo.exe"
String szparam = ""
Longpathtoquote (szprogram, true );
Longpathtow.path (szparam );
String szcommandline = szprogram + "" + szparam;
Addfoldericon (svdefgroup, "Demo", szcommandline, "C:/test", "C:/demo. ICO ", 0," CTRL + ALT + 1 ", replace | run_maximized );
Currently, the resource item is being modified. In this case, the string table stores all types of characters displayed in the text box. For example, folder_name is the province name missing from your project order group, product_key is the transportation file of your project order items, and product_name is the name of your project order items, title_captionbar will be displayed in the upper side box of your installation procedure Background window, And title_main will be displayed in your installation procedure Background window. For users in Windows 95 and WinNT 4.0, uninst_display_name is displayed in the column table "Add/delete process" of the control panel.
In the setup file option, you can specify the image that is displayed when the installation process is started, you only need to insert the compiled file to the language independent of the splash screen and change it to setup.bmp.
If you have already added content as described above, in this case, the following media item is opened, right-click the media item, and select the media build wizard in it to create the object storage in the process sequence. structure. If you choose a soft disk, the auto-generated sequence is in the descending order of the disk. At this point, we recommend that you use the software InstallShield to create the end of the installation process.