LCCWIN32 Guide

xiaoxiao2021-03-06  20

LCC-Win32 Small Guide By Daniel Guerrero Miralles Translation: PigPrince ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------

Declare that this article does not have any clear or implicit expression. This article is completely correct. It is not responsible for any result produced by the content of this article. Please forgive this article in the use of language and grammar, this person is shallow, which is inevitable. If you feel that you feel uncomfortable, please contact PigPrince, thank you first.

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

LCC-Win32 introduces that LCC-Win32 is originally a free Win32 compiler that contains a good use of IDE, which is very cool, but the nearest version is to pay (40 cubes). See the official website of the LCC-Win32 for details. Its free version can be obtained in China, and you will gain something to get to the Yunfeng Studio.

Directory Introduction Compiler Some basic concepts of LCC-Win32 write a small program! Using Engineering Management First Windows Programs Generate Wizard Use WeditRes to create resources to add other types of resources to use non-specific resource static libraries and dynamic libraries

Introduction In fact, the so-called profile This part of the content trend depends on the author. But some guidelines I have read are started by a "introduction". This part of the content is usually repeated readers will be seen below, but some profiles are just some of the author's ideas. Think carefully, in fact, this introduction is not a simple thing. First of all, if you want to open the door to the top theme, this is impolite, and the web-based guide should not have a large introduction, should not let the reader waste time and money at this thing.

It seems that my nonsense is enough, let us cut into the topic.

This guide is a single page. It is recommended that you wait for the browser to download a copy to read it offline.

The installation compiler of the compiler is simple, just run the file you downloaded, you should not encounter any problems. But pay attention to the final compiling library file installed, it may take some time, depending on your machine speed.

Some basic concepts of the LCC-Win32 LCC-Win32 compilation system are made up of multiple files. Their common tasks are binary formats that can run the source code of the text format. Excellent important documents are compiler (LCC.exe) and connectors (LCCLNK.exe). The compiler is used to translate your text to translate the format that can be performed by the text you write. Connector is used to convert the two-credit generated by the compiler (typically called the target file), and add an operating system to transfer the program to memory and execute it. It can link multiple target files to a separate program. This allows you to split the code document of a program into several modules, which is important when you develop large programs.

Although these sound seem to be very simple, it is actually not this. The editor and linker requires you to type all the information you want to build in the command line mode, which will require you to remember a lot of command line parameters and a wide variety of switches, then you need IDE-integrated development. The environment (Wedit.exe) is convenient.

The basic function of IDE is to edit text, you can edit the source code of the program in this environment, but far more than this feature. It also provides you with a simple way to call compilers and linkers, so you don't have to remember so many command line parameters when you compile.

You can simply imagine WEDIT as your console, where you can control all the processes. Ok! Now you can use your mouse to click the "Start" button, look for "LCC-Win32" in the submenu of the program item, okay? Now you are ready to write your first program in LCC-Win32.

Write a small program! do you know? Since the first C compiler (maybe earlibody), there is a practice that is "Hello World" written for this compiler, I have written all the compilers I have, now Let's write one. The first step is to create a source code file. Select the "New" item in the "File" menu, and then enter "Hello.c" in the dialog that appears and click "OK".

Now you see a blank window titled "Hello.c", enter the following code:

#include

Void main (void) {Printf ("Hello World from LCC-Win32! / N");

Save our applet and select the "Save" item in the "File" menu.

Now we can compile this program. Select the "Compile Hello.c" call compiler in the "Compiler" menu. At this time, a new window will appear at the bottom of the IDE, this is the information window, when the compiler processing is complete, "Hello.exe Build SuccessFully." Will be displayed, if the compilation error, the error message will also be displayed it's here.

If the compilation is wrong, double-click the information display at the information window. In the edit window, the high brightness is displayed, and the programs you write are carefully checked, the same thing you wrote, here I need to pay attention to the C language is Significantly sensitive programming, which means "Printf" and "Printf" are different for compilers.

Now that you have compiled this program, press [CTRL] [F5] to run, the result is right?

Using Engineering Management Now you have compiled your first program, you may want to know - Where is the execution file? The answer is: I don't know! This may sound is stupid (indeed), but this is what you look at the default directory when you compiler, so you should search for a file called "Hello.exe" in your hard drive.

You will definitely not want to search for a hard drive every time you develop a program, you will use the project.

The project is the information required for some compilers to know. This includes program source files, compiling the storage location of files, to compile why type executables, a good idea is to establish a project for each program.

In fact, there is still a project for our "HelloWorld" program, and LCC = Win32 will establish a default project for programs without projects. Select the "ERASE ..." item of the "Project" menu, Wedit will display a list of projects, you will see a project called "Hello", now we don't leave it without your removal.

Unlike other compilers, the engineering information of the LCC-Win32 is not stored on the hard disk, but stored in the registry key of Windows. This allows WEDIT to "remember" all the projects, even on different disks. But the advantage We also need to clear the project we are no longer used, in which case we can export engineering information to disk and remove it in the IDE. Look at the "Project" menu option, you will understand.

Now you can try to create a "Hello" project.

The first Windows program You may have noticed that hello.exe looks like a DOS program, but it is not, it is a real Windows program, but this type of program is called the Windows console program, that is, in text The Windows program running in the mode. If you don't believe, you can try to run in the pure DOS environment of Windows, you will get a line of information: "This Program Cannot Be Run in Dos Mode". Writing a real Windows version of the "HelloWorld" program is not much difficult than the console. First create a new project, select "Windows Executable" instead of "console application", after point OK, LCC-Win32 will ask you to create a Wizard (Generate Wizard) Create Program Framework, answer no. #include

Int WinApi Winmain (Hinstance Hinstance, LPSTANCE HPREVINSTANCE, LPSTANCE HPCMDLINE, INT NCMDSHOW) {MessageBox (Null, "Hello World from LCC-Win32!", "Hello", MB_OK; Return 0;}

Compile and run this program, you will see a window that displays Hello information, point OK to close exit.

Unfortunately, in addition to such a small Windows program, the Windows program is very complicated in general, now you already know how to create projects and compilers, if you are a Windows programming novice, go find some related The book is to see the necessary foundation, some of Windows programming knowledge is necessary.

If you are a new hand of C language, then learn this guide again for a while!

The program generation wizard Windows program is better than the text in text, but the sky will not drop the pie, you want to get the Windows function support, such as: Tailor board, multitasking, etc. To pay a lot Complex code. But there are always some ways to make things simple. For a long time, programmers have found that some code segments are always in each program, so the Windows programmer usually uses templates to generate this part of code. That is to say that the source file generally uses it once, you can use it in any new program. Only the changed part is the different parts of each program, apparent that these should be automatic.

This is the work that generates the wizard to complete. You can quickly generate the application's framework with its help. This framework is actually a complete program that is not available, maybe it is just to display an empty form because it makes the program to complete the specific function is your job.

Let's take a look at the process of using the wizard to establish the simplest application.

Often, the first step is to create program code and establish a project. In the use of the wizard mode, you don't need to write a line of code, the wizard will create it for you, and we directly see the various steps of the establishment of the project.

In the "Project" menu, select the "create" item, give the project name and path, select the engine type "Windows Executable", when Wedit is asked if you want to use the Wizard, answer "Yes", so that you enter the wizard mode.

The wizard will display a dialog called: "Application Characteristics", which is the basic feature of the wizard will be included in the application, you can choose one of the following: single window, multi-window and DLL (dynamic link library), now we To create a very simple single-window appler, select a single window type and make sure all feature check press New more unchecked, click on "OK" to process. Now the wizard will prompt you to enter the information set "class", "Class" and C in "Class" and C are different. It is a structure stored in memory in memory, which is used to store the correct display window. Information. The most important thing is the name of the "Reply Function" (hereinafter specifically described), now just simply accept the default attribute value, click "Next" to process.

This "Generate Code for the Main Window Creation" dialog is used to set the information of the corresponding window. This information is transmitted to the corresponding window when the main form is created. Here you can change the display of the title bar of the window, then click "Finish".

The wizard is to complete, the next engineering creation work is some of the usual settings for compilers, linkers, and debuggers, as long as you accept the default options.

After the above steps, complete all the works of the wizard, you can see two windows in IDE, one is the source program editing window, and one is the script for defining the main menu of the application.

As you have just said, this program framework is full-featured, you can use a window with a menu by compiling and running. The only action that can be performed is the "EXIT" item of the "File" menu, you can use this menu item to close this simple window, or use [Ctrl] [Q] to complete the same operation.

Now you can look at the source code of this program, you will notice this program is more complicated than that "Hello World!" Program, I can tell you a tip - start reading from the end of the source code, because usually there It is the location of some functional functions.

Using Weditres Creating resources In the development of Windows programs, resources are important parts, menus, dialogs, and other user interface portions are written as written like writing programs, which can be simply included in the process. If the LCC-Win32 does not provide a resource editor, the LCC-Win32 will not be a complete Win32 compiler, and the resource editor provided by the LCC-Win32 is called Weditres, which is in the "LCC / BIN /" path.

Indeed, Weditres is still in the process of continuous improvement, that is, not yet developed. However, it can be edited some of the resources that are difficult to complete, such as menus and dialogs, and more. Add WEDITRES to IDE and select the "Resources" item under the "Compiler" menu.

If the program you are developing is generated by the wizard, then a resource file is generated, at least menu resources, and Weditres will open this resource file, but it won't find the corresponding header file, you should be it Refers to the path of the header file. Usually the last level directory of the current working path of the WeditRES. The files you want to find are usually called PrjNameWiz.h, and the prjName here is the name of the project you specify. After this step, you can modify the resources used in the project.

If your program is not generated by the wizard, Weditres will prompt you to enter the file name of the resource file. After entering a name, click "OK", then Weditres will say that you can't open this resource file, there is no relationship, this is because this directory It is indeed no resource file, or click "OK" in this dialog, then select "New" item in the "File" menu, which will create a new resource project for your project, type a project name Generally, the same is the same as the application's engineering name, then click "Validate", now you need to add this resource file manually to add this resource file (generally "res" as an extension). Try here - we create a "About" dialog resource for programs created above.

After running WEDITRES, enter the path to the header file, select the "New Dialog" item of the "Objects" menu, then Weditres displays a dialog, the title bar is "Dialog Box Parameters", the title of the changing dialog is "About this application" Or anything else, then type something you like, such as "DLG_About", select the "Validate" option in the "Standard Buttons" menu and click on "OK" to close dialog box .

You should see a new dialog and a floating toolbar at this time. You should also have a button in the dialog. You can drag it with your mouse to re-specify its location, if you want to change Press the text displayed on the button - Double-click it to open the property dialog, or first select it, then change the display text under the floating tool strip.

Below we add a static text tag, select the text tool on the toolbar, the cursor shape becomes a pointer surrounded by a rectangle, click on the form of the dialog, a rectangular meeting containing text - "Text" - In the place you click, you can change the size of this text box by mouse drag, and you can also change the location of the displayed text and text box.

We can also add other devices in this dialog. Empty square boxes, solid square boxes, and component boxes, etc., you can make some simple decorations on this dialog. If you want to delete a device, select it and press [Ctrl] [x], or select the "CUT" item "edit" menu. You can also select the "Test" item of the "Options" menu to test the appearance of this dialog. There is a button in the toolbar that is the same, that is, it looks like a switch, if you want to continue to edit this dialog, just select the above option again.

After the editing is complete, select the replication in the "File" menu, then close the weditres, where we must include the corresponding code in the program.

Look for "oncommand" statement, where one of the conditions that there is a Switch statement is one of the menu commands "exit" (idm_exit), now we add a new CASE condition for our new dialog, enter the following code:

Case IDM_About: DialogBox (HinSt, MakeintResource (DGL_ABOUT), HWND, ABOTDLGPROC; Break;

We also need to write a dialog function.

Bool Callback AboutdlgProc (HWND HWND, UINT MSG, WPARAM WPARAM, LPARAM LPARAM) {Switch (MSG) {CASE WM_COMMAND: IF (WPARAM == idok) {enddialog (hwnd, 0); return;} Return False;} You should already understand that it is necessary to generate a code from the wizard! Compile, link this program, then run it, select the "Execute Prj.exe" item in "Compiler", and the dialog we created will be displayed on the screen.

Adding other types of resources You also need to know how to add other resources, such as icons, and more. In fact, Weditres can't edit icon files, the author is doing this work. So you might want to use other tools to complete the work of the icon editing.

After the resource creation, you have to add it to the project's resource description file. If you are an engineering created using the wizard. You only need to open the same * .rc file as the engineering name.

If you don't use the wizard, you can only create an RC file. If you are using the resources created by Weditres, some things when building a resource description file is what you have to know - must contain the WeditRes resources, and you don't use any resources created by Weditres, you are fully likely to work in subsequent work. Used, I suggest that any case should be done below.

Weditres is usually to build three files: a * .dlg file, a * .h header file and a * .res binary resource file. The DLG file describes the definition of resources created by WeditRes (such as resource strings, menus, and dialogs, etc.), the H file is the definition of the symbolic name of all resources, the RES file is the compiled binary resource file, this file will be linked In the executable of the final generated program.

The resource description file (* .rc) file name must be the same as the file name of the Res file, and the original RES file will be overwritten when the LCC-WIN32 resource compiler is compiled. You can create a resource description file in the WEDIT, as follows:

#include #include "resources.h" #include "resources.dlg"

The first line is used to include the standard Windows header function, define the information required for the resource compiler in this header.

The second line contains the header file of the symbolic name generated by the resource generated by Weditres, I am here to assume that your resource project is called "resurces", which can be changed to the name you defined. The third line is the resource description file generated by Weditres, which will not lose the resources you have created.

Below you can add resources to your resource description file, here is an example:

IDI_MYICON ICON Myiconfile.ico

This line defines the icon resource. Before using, you must define the symbol name of the icon. For example, in the "prjwiz.h" file (or "resource.h", if you don't use the wizard), if you don't define this symbol name, the compiler will think it is a string name.

The steps to add cursors or bitmap resources are the same, as long as the keyword is changed to "Bitmap" or "Cursor".

The following is to include the resource description file in the list of project files. When you compile the project, the resource compiler will also compile this resource description file and connect the generated binary link to the execution file.

This allows you to add icons, cursors, and bitmap resources. For other types of resources, you can use the RCData resource to add to the resource file, which is a series of numerical information separated by commas, which allows LCC-Win32 resources to compile resources. Resources that are not supported are added to the resource file, such as a WAV file, etc. Various types of resources, such as dialogs, menus, icons, etc., but it cannot use other non-specific resources such as multimedia files (WAV, MID, etc.). You may think that other resource compilers such as Microsoft provide resource compilers provided in Win32 SDK, or something else.

But the trouble here is LCClink, because it does not know these resources, so it is impossible to link these resources to your executette, this is really a big problem, you may have to use other linkers, this It means that other types of entrance libraries may be needed.

I think this is not a good solution. The main reason is that WEDIT is not designed to use other linkers. You will have to compile your program in the command, giving all the advantages provided by LCC-Win32 IDE.

But here still have a optional solution, - Fortunately, the LRC supports the RCData resource type. This resource type is used to include the binary data type, using a series of digital lists.

The following is a specific implementation method:

First you need to convert the binary you want to use to a series of text files with comma-divided value representation, LRC default thinks these data is 16-bit long, it also supports integers of 32-bit lengths, as long as the value Add "L" characters.

You can plant converters that do these work from here:

BIN2TXT: Developer: Josef Planeta. Very flexible and convenient; Textit: This article is developed, and multiple files can be converted once. Both tools have source code, developed using LCC-Win32.

Then you must include these integer lists in the resource data, if your resource file does not use the resource description file, if you don't use the wizard, it is very possible. You must establish a resource description file, usually this:

#include // Basic Windows header file #include "resources.h" // resource Identifiers (generated by weditres) #include "resources.dlg" // resource scripts (generated by weditres)

MySound Rcdata Begin #include "mysound.txt" end

In this example, we contain a file called "mysound.txt", which is a data file converted by a WAV file.

Note that the current version of the LRC (V981126) is limited in the size of the RCData resource. If any of the data files are greater than 70KB, you may get an overflow information (Overflow In Resource Data), there may be in the future version. The improvement is improved, but this situation may only have other resource compilers.

Defining resources using RCData means that you cannot specify Plays directly to play these resources because the types are different.

The solution is to manually read these data into memory. The following code illustrates what is going on in Plays:

BOOL PlayRcSound (HINSTANCE hInst, LPCTSTR lpszSndName) {HRSRC hr; HGLOBAL hg; LPVOID lpSndData; hr = FindResource (hInst, lpszSndName, RT_RCDATA); if (hr = NULL!) {Hg = LoadResource (hInst, hr); if (hg ! = Null) {LPSNDDATA = LockResource (HG); if (lpsnddata! = Null) {Return Plays ((LPCTSTSTR) LPSNDDATA, NULL, SND_MEMORY); / * We do not need to unlock or unload the resource, * / / * Windows Will Take Care of this * /}}} Return False;

If your resource defines an identifier in the header file, it is called: id_mysound, then the way the call function should be:

Playrcsound (Hinst, makeintResource) and (ID_MYSOUND);

Also, if you give a string name, such as: MySound, function call as follows:

PlayrcSound (HinSt, "MySound");

Static libraries and dynamic libraries may like to like to like to be probiotic, and the concept of library is an example. It is used to store code that may be used in many programs, or part of a very professional code, as long as you write once Yes, even from other people you write, this code is used to completely do not need to care for specific implementation details. Like other Windows compilers, LCC-Win32 also supports two libraries - dynamic libraries and static libraries.

The code containing the static library will be added in the executable when compiling the link, which is called a "static" library because once it is linked to the executable, it will not change (unless the entire program is recompiled).

The dynamic link library will not be linked by the compiler to the executable, but is linked by the operating system at runtime, so even if you change this library, it will not make the entire executable to recompile.

The preparation of the static library is simple. Just create a new project with "Static Library", add the original information you want to use in this static library - functions, data, etc., will get one after compiling Lib file, this file includes all the functions and data you specify. If you want to use these functions or data, specify a static library name in the "The" Linker "item in the" Configuration "table in the" Linker "table in the" Configuration "dialog, the notification the compiler links this static library link to the project, but millions Don't forget to put your static library to the location where the linker can find, such as the "/ LCC / LIB" path.

The dynamic link library is a bit troublesome, you want to use two files instead of a file: dynamic library itself - DLL file and associated entry library --Lib file. The entry library is to use it to the linker, simply it is used to scam, and it also contains information that makes Windows in the corresponding dynamic library in the respective dynamic library.

Moreover, the functionality of the dynamic library can be more powerful, it has a libmain () function, and the program will be initialized every time the program calls it every time it calls it.

To create a dynamic link library, you have to create a DLL project, then you can use the wizard to generate the libmain () function. Add the functions and data you want to use, after compiling this project, you can get the DLL library and interface library files. If you want to use a dynamic link library, like using a static library, put the interface library in the "/ LCC / LIB" path, add this interface library in the "Options" dialog. At the same time, it is also necessary to place the DLL file in the path that Windows can search, the default directory of the Windows Search Dynamic Link Library is "/ Windows / System /" and the starting directory of the application, place the dynamic link library in these two It is ok in the directory.

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

New Post(0)