Use of LCC-Win32!

Source: Internet
Author: User
Use of LCC-Win32!
About LCC-Win32
LCC-Win32 is a free open source Win32 compiler, contains a very useful IDE,
It is easy to use, but the source code has recently started to pay (40 US dollars ). For more information, see the LCC-Win32 official website.
Its free version can be obtained in China. You can go to the Yunfeng studio to see what you will get.

Directory

* Introduction
* Compiler Installation
* Some basic concepts of Lcc-Win32
* Write a small program!
* Use Project Management
* The first Windows program
* Program generation wizard
* Use weditres to create resources
* Add other types of resources
* Use non-specification Resources
* Static and dynamic libraries
Introduction
In fact, the content trend of the so-called Introduction Part depends on the author. However, some of the guidelines I have read are
Starting with an introduction, this part of content is usually what readers will see below,
Some introductions are just some of the author's ideas.

Think about it carefully. In fact, this introduction is not a simple task. First
It is not polite to go straight to the topic, and the Web-based guide should not have a large introduction.
Readers waste time and money on this thing.

It seems that I have enough nonsense. Let's get into the question.

This guide is a single page. You are advised to save a copy after the browser downloads it for offline reading.

Compiler Installation
The installation of the compiler is very simple. You only need to run the file you downloaded.
Problem. However, it may take some time to compile the library file at the end of the installation, depending on the speed of your machine.
Some basic concepts of Lcc-Win32
The Lcc-Win32 compilation system consists of multiple files. Their common task is to represent the source of the text format
The binary format that the code compilation bit can run. The key file is the compilation tool (lcc.exe) and the connection
Tool (lcclnk.exe ).

The compiler is a program that translates your written text into a format that can be executed by the processor. Connector for forwarding
For the binary file (usually called the target file) generated by the compiler, and add the operating system to call the program
Store and execute the required information. It can link Multiple Target files into a separate executable program.
This allows you to split the code document of a program into several modules. This capability is used when you develop large programs.
Important.

Although these seem very simple, they are not actually like this. Editor and linker
You need to enter all information about the program you want to create in the command line mode, which requires you to remember a lot of command lines
Idea-integrated development environment (wedit.exe) to provide convenience.

The basic function of IDE is to edit text. You can edit the source code of the program in this environment, but it is far from
This function is available only. It also provides you with a simple method to call the compiler and linker, so that you can compile the program
You don't have to remember so many command line parameters.

You can simply think of wedit as your console, where you can control all the processes.
Okay! Now you can click the start button of windows with your mouse to go to the sub-menu of the program item.
Looking for "lcc-win32", OK? Now you are ready to write your first program in the Lcc-Win32.

Write a small program!
Do you know? Since the first C compiler was created (maybe earlier), there is a convention that
The first program written for this compiler is "Hello world". I have written it for all the compilers I own,
Now let's write one.

The first step is to create the source code file. Select "new" from the "file" menu, and then in the displayed dialog box
Input "Hello. c" and click "OK ".

Now you can see a blank window titled "Hello. c". Enter the following code:

# Include <stdio. h>

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

Save our Applet and select "save" from the "file" menu.
Now we can compile this program. Select "compiler hello. c" from the "compiler" menu"
Call the compiler. A new window appears at the bottom of the IDE. This is the information window. When the compiler completes processing,
In this window, “hello.exe build successfully. "is displayed. If the compilation fails, an error message is displayed.
Information will also be displayed here.

If a compilation error occurs, double-click the row where the information is displayed in the information window, and display the High Brightness in the editing window.
The error code line. Check carefully that the program you wrote is the same as the one I wrote above.
It is a case-sensitive programming language, which means that "printf" and "printf" are different for the compiler.

Now that you have compiled this program, press [CTRL] + [F5] to run it. Is the result correct?

Use Project Management
Now that you have compiled your first program, you may want to know-where is the execution file?

The answer is: I don't know either! This may sound silly (indeed), but it is because you are compiling the program.
The current directory is used to search for a file named "hello.exe" in your hard drive.

You certainly don't want to search hard disks for every program you develop. In this case, you need to use the project.
Engineering is the information required by the compiler to establish a program. This includes the program source file, compiled
A good idea is to create
A project.

In fact, there is still a project for our "helloworld" program.
Specifies the program of the project to create a default project. Select "erase..." in the "project" menu, wedit
A project list is displayed, and you will see a project called "hello". Now we will delete it without mercy.

Unlike other compilers, the engineering information of the Lcc-Win32 is not stored on the hard disk, but stored
In the Windows registry key. This allows wedit to "remember" all the projects, even on different disks.
. However, we also need to clear the projects we no longer use. In this case, we can
And then delete it in IDE. Take a look at the options in the "project" menu and you will understand.

Now you can try to create a "hello" project.
The first Windows program
You can see 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 a Windows console program, that is, in text mode.
Windows program. If you don't believe it, you can try to run it in a Windows pure DOS environment.
The following message is displayed: "This program cannot be run in DOS mode ".

Writing a real Windows version of the "helloworld" program is not much more difficult than the console version. First
Create a new project and select "Windows Executable" instead of "console application". Click OK.
The Lcc-Win32 will ask you if you need to create a program framework by using the wizard and answer no.

# Include <windows. h>

Int winapi winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int ncmdshow)
{
MessageBox (null, "Hello world from Lcc-Win32! "," Hello ", mb_ OK );
Return 0;
}

Compile and run this program. You will see a window showing Hello information. Click OK to close and exit.
Unfortunately, apart from such small and small Windows programs, Windows programs are generally very complicated.
Now you know how to create a project and compile a program. If you are a beginner in Windows programming, go
Find some relevant books to see and obtain the necessary basics. Some windows programming knowledge is required in the following section.
.

If you are a beginner in C language, please take a good look at this guide for a while!

Program Generation wizard
Windows programs are much better than text programs, but they won't fall in the sky.
To get support for Windows functions, such as cropping boards and multitasking, a lot of complicated code is required.

But there are still some ways to make things easier. For a long time, programmers have discovered
Some code segments are always the same in each program, so windows programmers usually use templates to generate
Some code. That is to say, the source file can be used in any new program only once it is generated. Only
The changed part is the different part of each program. Obviously, these parts can be automatically implemented.

This is the task to complete the wizard generation. With its help, you can quickly generate an application framework.
In fact, this framework is a complete program without any functions. It may only be used to display
Empty form, because it is your work to make the program complete specific functions.

Let's take a look at how to use the Wizard to create the simplest application.
Generally, the first step is to create the program code and then create a project. In wizard mode, you do not
You need to write a line of code. The Wizard will create it for you. Let's take a look at the steps for creating the project.

Select "CREATE" under the "project" menu, give the project name and path, and select the project type
"Windows Executable". When wedit asks if you want to use the wizard, it will answer "yes ",
In this way, the wizard mode is entered.

The wizard displays a dialog box called "application characteristics ".
You can select one of the following basic features in an application: Single Window, multi-window, and DLL
To create a simple single-window small application, select the single-window type and confirm
All feature check buttons are not selected. Click "OK" to process them.

Now the Wizard will prompt you to enter information to set the "class" of the main window. Here, the "class" and
Classes are different. It is a structure stored in the memory of windows, used to store the required
Information. The most important thing is the name of the "call back function" (which will be described below). Now you only need to simply accept the default
Attribute Value, click "Next" for processing.
This "generate code for the Main Window Creation" dialog box is used to set the corresponding window
. When the main form is created, the information is transmitted to the corresponding window. Here you can change the window
Click "finish ".

The wizard is complete, and the subsequent project creation work is usually,
Some settings of the debugger. Here, you only need to simply accept the default options.

After the above steps, you have completed all the work of the Wizard. You can see two windows in the IDE, one
The source code editing window, and the script used to define the main menu of the application.

As I just mentioned, this program framework is fully functional and can be compiled and run. You can see
To a window with menus. The only operation that can be performed is the "exit" item in the "file" menu. You can use
You can use [CTRL] + [Q] to close this simple window.

Now you can take a look at the source code of this program. You will notice that this program is better than the "Hello world !"
The program is much more complicated. I can tell you a little trick-read from the end of the source code, because
Is where some functional functions are located.

Use weditres to create resources
In the development of Windows programs, resources are very important.
The user interface can be compiled like a program, and can be easily included as a resource into the program.

If the Lcc-Win32 does not provide a resource editor, the Lcc-Win32 will not be a complete Win32 Compiler
The Lcc-Win32 provides the resource editor called weditres, which is in the "KP/bin/" path.

Indeed, weditres is still in the process of continuous improvement, that is, it has not been developed yet. However, it has
You can edit resources that are hard to complete by hand, such as menus and dialogs. Call in IDE
Weditres: Select resources under the "compiler" menu.

If the program you are developing is generated using a wizard, The Wizard will generate a resource file.
Contains at least menu resources. weditres will open this resource file, but it will not find the corresponding header file,
You should specify the path of the header file for it. It is usually the upper-level directory in the current weditres working path.
Weditres is usually called prjnamewiz. h. The prjname here is
The name of the project. After this step, you can modify the resources used by the project.
If your program is not generated by the wizard, weditres will prompt you to enter the file name of the resource file
Enter a name and click "OK". Then weditres will say that the resource file cannot be opened. It does not matter. This is
Because there is indeed no resource file in this directory, or click "OK" in this dialog box, and then in
Select "new" from the "file" menu to create a new resource project for your project.
Project name, usually the same as the project name of the application, and then click "Validate", now you need
Manually add this resource file in the Application Project List (generally with "res" as the extension ).

Here is an example -- let's create a "about" dialog box resource for the program we created above.

Run weditres, enter the path of the header file, and select "new dialog" in the "objects" menu,
Weditres will display a dialog box with the title bar "Dialog Box Parameters". Change the dialog box.
The title is "about this application" or anything else, and then in "Identity"
(Identifier) enter something you like, such as "dlg_about", in "standard buttons"
Select the "Validate" option in the menu and click "OK" to close the dialog box.

You should be able to see a new dialog box and a floating toolbar at this time.
There is a button, you can drag it with the mouse to re-specify its position, if you want to change the button display
Double-click it to open the Properties dialog box, or select it first, and then change the display text under the floating toolbar.

Next we will add a static text label, select a text tool on the toolbar, And the cursor shape will change from
A pointer surrounded by rectangles. Click on the form in the dialog box to display a rectangle containing the text-"text "-.
You can drag the cursor to change the size of the text box.
The position of the displayed text and text box.
We can also add other devices in this dialog box. Hollow Box, solid box, component box, etc.
Perform some simple decoration on this dialog box. If you want to delete a device, select it and then press
[CTRL] + [X], or select the "cut" item in the "edit" menu. You can also select
"Test" to test the appearance of the dialog box. In the toolbar, there is a button with the same function.
If you want to edit this dialog box, you only need to select the preceding option again.

After editing, select a disk in the "file" menu and close weditres. To display this dialog box
The following code must be included in the program.

Find the "oncommand" statement, where one of the conditions for a switch statement is the menu command.
"Exit" (idm_exit). Now we add a new case condition for our new dialog box, as shown in
Code below:

Case idm_about:
Dialogbox (hinst, makeintresource (dgl_about), hwnd, aboutdlgproc );
Break;

We also need to compile the dialog box function.

Bool callback aboutdlgproc (hwnd, uint MSG, wparam, lparam)
{
Switch (MSG)
{
Case wm_command:
If (loword (wparam) = idok)
{
Enddialog (hwnd, 0 );
Return true;
}
Break;
}
Return false;
}

You should have understood that it is much easier to generate code by the wizard! Compile and link this program now, however
Run it and select "execute prj.exe" in "compiler". The created dialog box is displayed.
On the screen.

Add other types of resources
You also need to know how to add other resources and labels.

In fact, weditres still cannot edit the icon file. The author says it is working on this. So you may want
Use other tools to edit icons.

After a resource is created, add it to the Project Resource Description file. If you are using the wizard
The created Project. You only need to open the *. RC file with the same project name.

If you do not use the wizard, you can create only one new RC file. If you use weditres to create
When creating a resource description file, you must know some things-including weditres resources,
Even if you have not used any resources created by weditres, you may have used them in subsequent work,
I recommend that you do the following in whatever circumstances.

Weditres generally creates three files: A *. DLG file, a *. h header file, and a *. Res file.
Resource file. The DLG file describes the definitions of resources created by weditres (such as resource strings, menus, and dialogs ).
Box), the H file is the definition of the symbol names of all resources, the res file is the compiled binary resource file, this
The file will be linked to the final executable program of the project.

The file name of the Resource Description file (*. Rc) must be the same as the file name of the res file, when the Lcc-Win32
The source compiler (lrc.exe) will overwrite the original res file when compiling resources. You can create a Resource Description in wedit.
The file is as follows:

# Include <windows. h>
# Include "resources. H"
# Include "resources. DLG"

.

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

You can add resources to the Resource Description file. The following is an example:

Idi_myicon icon myiconfile. ICO

This line defines the icon resource. before using it, you must define the symbol name of the icon. For example, in "prjwiz. H"
File (or "resource. H", if you do not use the wizard), if you do not define this symbol name,
The compiler considers it a string name.

The procedure for adding a cursor or bitmap resource is the same. You only need to change the keyword to "bitmap" or
"Cursor ".

The following is to include the resource description file in the project file list. The current time you compile the project, the resource
The compiler will also compile this resource description file and link the generated binary resources to the execution file.

In this way, you can add icons, cursors, and bitmap resources, and use rcdata resources for other types of resources.
Method to add to the resource file, is a series of comma-separated numerical information, this way can make the Lcc-Win32
Resources not supported by the resource compiler can be added to resource files, such as WAV Files.

Use non-specification Resources
The Lcc-win32's resource compiler can use a variety of types of resources, such as dialogs, menus, icons, etc.,
Yes. It cannot use other non-standard resources such as multimedia files (WAV, mid, and so on ).

You may think that using other resource compilers, such as the resource compilers provided by Microsoft in the Win32 SDK, or
Other things.

But the trouble here is lcclink, because it does not know these resources, it is impossible to put these resources
The source is linked to your execution file. This is really a big problem. You may have to use another linker.
This means that other class library may be required.

In my opinion, this is not a good solution because wedit is not designed to be usable.
It's the linker that you will have to compile your program under the command line, giving up the full functionality provided by the Lcc-Win32 ide
Benefits.

However, there is still a solution to choose from. Fortunately, LRC supports the rcdata resource type.
Resource types are used to contain binary data resources, represented by a series of numbers.
The specific implementation method is as follows:

First, you need to convert the binary file you want to use to a series of text files with comma-separated numeric values
By default, LRC considers the data to be 16-bit long. It also supports 32-bit integers as long
Then add the "L" character.

You can download the following converter:

* Bin2txt: developer: Joseph Planeta. Very flexible and convenient;
* Textit: developed by the author of this article. Multiple files can be converted at a time.

Both tools have source code and are developed using Lcc-Win32.

Then you must include these integers in the resource data. If your resource file does not use the resource description
File. If you do not use the Wizard to generate a project, this is very likely. You must create a Resource Description
File, which generally looks like this:
# Include <windows. h> // 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 include a file named "“mysound.txt", which is composed
.

Note that the current version of LRC (v981126) has a limit on the size of rcdata resources.
Data Files larger than 70 KB, you may get an overflow information (overflow in resource data ),
It may be improved in future versions. However, if this happens, only other
Resource compiler.

Using the rcdata type to define resources means you cannot directly specify playsound to play these resources.
The type is different.

The solution is to read the data into the memory manually. The following code describes what to do in playsound:

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 playsound (lpctstr) 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 is defined as an identifier in the header file, called id_mysound, the method of calling the Function
It should be:

Playrcsound (hinst, makeintresource (id_mysound ));

In addition, if you provide a string name, such as mysound, the function call is as follows:

Playrcsound (hinst, "mysound ");

Static library and dynamic library
Maybe programmers like the analogy of class rhetoric. The concept of library is an example. It is used to store
The code that can be used in many programs or some very professional code can be written once.
It is the code written by others for you, so that you can use the code without worrying about the specific implementation details.

Like other Windows compilers, LCC-Win32 also supports two libraries-dynamic and static.

The Code contained in the static library will be added to the executable file during the compilation link. It is called the "static" Library
Because once it is linked to an executable file, it cannot be changed (unless the entire program is re-compiled ).

The dynamic link library is not linked to the executable file by the compiler, but by the operating system at runtime,
In this way, even if you change the library, the entire executable program will not be re-compiled.

Writing static libraries should be simpler. You only need to create a new project of the "static library (LIB)" type,
Add the original data you want to use in this static library-functions, data, etc. After compilation, you will get
Lib file, which contains all the functions and data you specified. If you want to use these functions or
Data, "additional libraries" in the "linker" table in the "configuration" dialog box"
To notify the compiler to link the static library to the project, but do not forget
Put your static library in a location that can be found by the linker, for example, under the "/KP/lib" path.

Dynamic Link Library is a little troublesome. You need to use two files instead of one file: dynamic library itself-DLL
File and associated portal library-lib file. The portal library is used by the linker. In short, it is used to cheat
The linker also contains information that enables Windows to correctly call functions in the corresponding dynamic library.

In addition, the dynamic library function can be more powerful, it has a libmain () function, each time in the program
It is used for initialization when calling it.

To create a dynamic link library, you need to create a DLL project, and then you can use the Wizard to generate libmain ()
Function. Add the functions and data you want to use. After compiling this project, you can get the dll library and interface library.
File.

If you want to use a dynamic link library, put the interface library under the "/KP/lib" path, just like using a static library,
Add this interface library in the "options" dialog box. At the same time, you need to place the DLL file in Windows for searching.
Under the path to, the default directory for Windows Search dynamic link library is "/Windows/system/" and the Application
To place the dynamic link library under these two directories.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.