Two ways to create an installer

zhaozj2021-02-11  204

Two ways to create an installer

● Peng Jin Zhao Hao

Creating an installation of the installation is one of the questions that the program is often encountered. This article only explores the two methods of creating an installation (SETUP) program on Windows platform.

First, use Visual C to apply to SETUP program

The most straightforward method for generating SETUP program is now the program. For Windows platform, there is no better development tool than Visual C (the original is very simple, who can solve the Windows platform than Microsoft?). The next step is to compile with Visual C 5.0.

The SETUP program is to proceed to two questions:

(1) User interface. When evaluating the advantages of a setup program, the user's view is an important factor in it. In addition, through the interactive interface should also be able to obtain the relevant information of the user (such as a target directory).

(2) The generation of document copy and program group. That is, based on the information input by the user, it is generated into a corresponding directory and is completed into file copying function (this should be involved in the decompression problem). In general, it should also include adding icons that can be filed files to the specified program group.

1, set back to the setup program

The setup of the setup program is the Lord with the dialog box, and there is not little color to have a beautiful appearance. You can select a suitable BMP file, insert it into the Project, and display the onpaint () function of the reload main window class. What is worth noting is that the back view film should not be too dazzling, and if there will be a sense of. For example, the ID number of the BMP file to be added is IDB_bit. The next function should be added to on OnPaint ().

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);

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 full screen effect

The general main window has border, if you appreciate the full-screen effect in the DOS interface, it is best to keep the default value of CS.Style when you overload CWnd :: PrecreateWindow (CreateStruct & Cs), and create the main window. when using 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, save public parameters

With the dialog box, you can exchange information with the owner. Then, what will be required when the program is required (such as an installation directory)? Of course, it can be generated into a configuration document, and the work that is not more professional is to store the correlation information into the system in INI. If the opening platform is Windows 95, it will be very simple, because you are the Win.ini file, this file is in the Windows directory. Visual C provides a set of functions to operate this document.

(1) CWINAPP :: getprofilestring

CSTRING GETPROFISTRING (LPCTSTR LPSZSECTION, LPCTSTSTR LPSZENTRY, LPCTSTR LPSZDEFAULT = NULL);

Used to read the LPSZENTRY parameters in the LPSZSECTION area, the default is LPSZDEFAULT.

(2) CWINAPP :: WriteProfileString

Bool WriteProfileString (LPCTSTSTR LPSZSECTION, LPCTSTR LPSZENTRY, LPCTSTR LPSZVALUE);

Use to write LPSZENTRY parameters in the LPSZSECTION area, which is LPSZVALUE.

If your opening platform is Winnt, you have to bother. If your variable is saved in E: //winnt/sdi.ini, it must be called before the above function is used:

Free ((void *) m_pszprofilename);

m_pszprofilename = _tcsdup (_t ("e: //winnt//sdi.ini)))));

If there are not many variables to be accommodated, they can also be stored in the Registry Key. If your variable is saved in the Moon Registration keyword (the name of your company), it must be called before the above function is used:

Free (void *) m_pszregistryKey;

m_pszregistryKey = _TCSDUP (_t ("HKEY_CURRENT_ USER // Software // Moon"));

4. Copy and decompression of files

If your installation is a needle for a soft disk, the storage space is a question that must be considered. The original seal is not allowed to copy the application program. It is not too stupid, and the method is compressed in a soft disk, and then decompresses the abbreviated target. Visual C provides a function of the LZ opening function, uses a file with a compress command to be compressed: You can use lzopenfile () to open the original document and the target file, then use lzcopy () to decompress the copy. This group function calls the Windows system's LZEXPAND.DLL dynamic link library, and you must add the header LZEXPAND.H with the compiling chain to pick up the header LZ32.lib. There is also a simpler way, first compress the original program with shared compressed programs like Arj.exe, then call System ("Arj ..." to complete the decompression, the entire decompression process is done in the background. Users will not know what method you are using.

5, display copy progress

Many professional installations will display the progress bar when copying the document, and even have a moving painting. What is this effect? The Method is to create a Modeless dialog box at the same time. This type of dialog is created with a create () function, and the class seems to have created a new thread with the main thread. This can display copy progress in the dialog box at the same time of the copy file. Visual C provides two very useful controls, namely CanImateCtrl and CProgressCtrl. These two controls can be drawn in the dialog box and add the corresponding classes with ClassWizard. Among them, can IIMATECTRL is used to display the .avi file, use it to start a "small paper flying" after the copy of each file; CProgressCtrl is used to display copy progress, and the representation is made after each copy is successful The blue strip proceeds to the appropriate location.

6, the generation of program group and program item

The birth of the program group is actually in line DDE conversation with the Program Manager responsible for the rule of the management rule, and you can add the corresponding program group and the application program. At the same time, the conversation is one-way, and the Callback () function that is responsible for the feedback message does not work. The sources and their usage are given under the lower surface.

HDDedata Callback DDECALLBACK (uint utype, // transaction TYPE

UINT UFMT, // Clipboard Data Format

HCONV HCONV, // Handle To The Conversation

HSZ HSZ1, // Handle to A String

HSZ HSZ2,

// Handle to a stringhddedata 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 HCONV;

HDDedata hexecdata;

UI = DDEINITIALIZE ((unsigned long *) & dwddeinst, ddecallback, cbf_fail_allsvrxactions, 0L);

IF (ui! = DMLERR_NO_ERROR)

{Return False;}

HSZSERVICE = DDECREATESTRINGLE ((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

DDEFREESTRINGLE ((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) 1,0, NULL, 0, 0);

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 join a program that is called "demo", it contains a program item name "Test", and performs C: /Demo/test.exe, you can use the Test.ico icon, you can press Call this function as follows:

SenddDecmd ("[CreateGroup (Demo)] [AddItem (C: /Demo/test.exe, Test, C: /Demo/test.ico)")

Second, use tools to create an installation process

The use of Visual C programming energy enough to generate a strong SETUP program. Can't, if you are more happy to use the ready-made tool, you will not try the tools for creating an installation. The software is provided with a class of Basic's programming, clear and easy. When you create a new installation process, you can start from Project Wizard. The first start is a Welcome dialog box, which includes the following content:

(1) Application Name (Edit Box)

In this dialog box, enter the name of the application you want to install, installshield will use the name to log back and generate your program group.

(2) Development Environment (list box)

Select the environment (such as Visual C ) that is issued.

(3) Application Type (List Box)

Select the category of your application.

(4) Application Version (Edit Box)

Select the version of your application program.

(5) Application Executable (Edit Box)

Transport the main running document of the application, or click ...

(6) Single click "Next", SELECT DIALOGS

Choose the dialog boxes you need for your installation, if you can't confirm it, you can press the Preview key to prepare.

(7) Summary "Next", select the operation system platform for this application. You can select Win 95, Winnt 3.x or WinNT4.0.

(8) Summary "Next" and select the language of the installation. In this free version, the only choice you can do is "English".

(9) If you want to include multiple installation type selection in your installation, click "Next". The start-up dialog box provides superior features, from which you can choose Compact, Typical, Custom, and Network and other installation types.

(10) Single click "Next", select the component you want to install, the different set of groups of these components is that you choose the same installation type.

(11) Click "Next" to select the file group you want to create, the file group is a logical group including the file in your application, which is a component that should be on the upper part.

(12) Click "Next", including (ie "Summary") you entered the information. If it is not satisfactory, it can also be modified; if it is full, press the "completed" button, the frame of a security program is greatly. A process document for making the installation of installment.

In fact, Project Wizard has made a large part of work. In order to create a complete installation, first we must clarify the relationship between the various items in the works. This is going to say from File Group. File Group is a logical group for the application program file. There is a link item in each folder. Use the right to click this bit, select the insert item, you can apply your application file to the appropriate group. Each file group contains a dry attribute value, and click this property to modify it. For example, for the Compress item, you can choose whether or not the file under the file group is compressed. Several File Groups can belong to a Component, and you can distinguish between the division in the division. Each Component also has several properties: where the Destination item is for you to select the target directory to be installed; installation items for your choice of processing mode when you encounter the same file name; SetupType items to choose different installation types installed Component. Next, you will enter the Script Files item, it is your schedule of your installation. If you just want to create a standard installation, you only need to make small changes to it. Since the system does not generate a part of the creation program group, you must manually modify the function setupfolders () function. In DialogShowsDselectFolder (), the installation script has stored the target program group to be generated into the variable SVDefgroup, so you only need to setupfolders. () Add a few of the following contents (assuming that you want to join a "demo" item, execute the C: /Demo.exe file, the icon used is "c: /demo.ico", the work directory is "C: / TEST ", with" Ctrl Alt 1 "as a hotkey, and the program item will be used as the first item of the program group, which will be maximized when executed).

String szprogram = "c: /demo.exe"

String szparam = ""

LongpathToquote (Szprogram, True);

Longpathtoshortpath (SZPARAM); String Szcommandline = SZPROGRAM "" Szparam;

AddFoldericon (Svdefgroup, "Demo", SZCommandline, "C: / Test", "C: /Demo.ico", 0, "Ctrl Alt 1", Replace | Run_Maximized);

Now modify the resource item, String Table stores is displayed in the various character variables in the dialog box. For example, Folder_Name is the default name of your program group. Product_Key is the running file of your program item. Product_name is the name of your program item, and title_captionbar will display in the upper box of your installer background window, title_main will display On your installer background window. For WIN 95, WINNT 4.0, uninst_display_name will display the "Add / Remove Program" of the control panel.

In Setup file, you can modify the graphics that is retrieved when the installation is started, just insert the edited file into the language independent of Splash Screen and change it to setup.bmp.

If you have been properly added as mentioned above, the things you have to do next is to open the Media Build Wizard to select the Media Build Wizard in it to create the material storage structure of the application program. If you choose a soft disk, you can automatically generate a target program that is divided according to the DISK. At this point, the process of creating an assembly of the installation of installs with tools.

转载请注明原文地址:https://www.9cbs.com/read-4004.html

New Post(0)