I recently wrote a console program. The function of this program is very simple. It is to export (specify the table name, specify the field name in the table) data from the database to a WORD file. After the program was written, I found during testing that when the user is exporting After creating a database table, if you want to export the data in another table, you have to re-run the program, which is obviously not good. However, if it is implemented using loops or goto statements in the program, there will be too much text in the console and it will not look good. So I finally thought about whether we could have the console automatically clear the screen after we finished importing a database table, and then export the next database table. Then I searched online for a long time, but couldn't find a satisfactory answer. The online method of "clearing the screen" is to type n carriage returns. I don't think this is clearing the screen at all. Suddenly I thought of writing a screen-clearing DLL in C++, and the result was quite satisfying. Below we will implement the C# language to clear the screen in the console step by step:
(1) Open VS2005 and create a new C++ class library project called CLS;
(2) Open the CLS.h file and rename the class name to "CLS";
(3) Open the CLS.cpp file and introduce the "windows.h" file into it;
// This is the main DLL file.
#include "stdafx.h"
#include "windows.h"
#include "CLS.h"
(4) Add static methods to the CLS class (access attributes are public)
public ref class CLS
{
public:
static void cls()
{
system("cls");
}
};
(5) Finally compile the entire project and introduce CLS.dll in the CLS/debug/ folder into the C# project;
(6) Wherever the screen needs to be cleared, just call CLS.cls(). Functions such as pause can also be implemented using the same method as above.
Why is this possible? Anyone who has studied .Net FrameWork should understand very well, because no matter it is C++, C, VB or C# language, IL (Intermediate Language) language will eventually be generated, so no matter which program is written in the above language, it can be Interoperable.
If anything written above is wrong, please tell me! I just started blogging, and there is definitely a lot to learn.
http://www.cnblogs.com/blueskybcl/archive/2010/04/24/1719171.html