怎么为控制台程序编写gui_如何在没有GUI的情况下构建控制台应用程序

怎么为控制台程序编写gui

​Console applications are pure 32-bit Windows programs that run without a graphical interface. When a console application is started, Windows creates a text-mode console window through which the user can interact with the application. These applications typically don't require much user input. All the information a console application needs can be provided through command line parameters.

控制台应用程序是纯32位Windows程序,无需图形界面即可运行。 启动控制台应用程序时,Windows将创建一个文本模式控制台窗口,用户可以通过该窗口与应用程序进行交互。 这些应用程序通常不需要太多用户输入。 控制台应用程序需要的所有信息都可以通过命令行参数提供

For students, console applications will simplify learning Pascal and Delphi - after all, all the Pascal introductory examples are just console applications.

对于学生而言,控制台应用程序将简化Pascal和Delphi的学习-毕竟,所有Pascal入门示例都只是控制台应用程序。

新增:控制台应用程序 ( New: Console Application )

Here's how to quickly build console applications that run without a graphical interface.

以下是快速构建无需图形界面即可运行的控制台应用程序的方法。

If you have a Delphi version newer than 4, than all you have to do is to use the Console Application Wizard. Delphi 5 introduced the console application wizard. You can reach it by pointing to File|New, this opens up a New Items dialog - in the New page select the Console Application. Note that in Delphi 6 the icon that represents a console application looks different. Double click the icon and the wizard will set up a Delphi project ready to be compiled as a console application.

如果您的Delphi版本高于4,那么您所要做的就是使用“控制台应用程序向导”。 Delphi 5引入了控制台应用程序向导。 您可以通过指向文件|新建来打开它,这将打开“新建项目”对话框-在“新建”页面中选择控制台应用程序。 请注意,在Delphi 6中,代表控制台应用程序的图标看起来有所不同。 双击图标,向导将设置一个Delphi项目,准备将其编译为控制台应用程序。

While you could create console mode applications in all 32-bit versions of Delphi, it's not an obvious process. Let's see what you need to do in Delphi versions <=4 to create an "empty" console project. When you start Delphi, a new project with one empty form is created by default. You have to remove this form (a GUI element) and tell Delphi that you want a console mode app. This is what you should do:

虽然可以在所有32位版本的Delphi中创建控制台模式应用程序,但这并不是一个显而易见的过程。 让我们看看在创建<empty>控制台项目的Delphi版本<= 4中需要执行的操作。 当您启动Delphi时,默认情况下会创建一个具有一个空表单的新项目。 您必须删除此表单( GUI元素),并告诉Delphi您想要控制台模式的应用程序。 这是您应该做的:

  1. Select File > New Application.

    选择文件>新建应用程序。

  2. Select Project > Remove From Project.

    选择项目>从项目中删除。

  3. Select Unit1 (Form1) and OK. Delphi will remove the selected unit from the uses clause of the current project.

    选择Unit1(Form1),然后单击OK 。 Delphi将从当前项目的uses子句中删除选定的单元。

  4. Select Project > View Source.

    选择项目>查看源。

  5. Edit your project source file:

    编辑您的项目源文件:

    • Delete all the code inside

    •删除里面的所有代码

    begin and end.

    开始结束

    • After the

    • 之后

    uses keyword, replace the Forms unit with SysUtils.

    使用关键字,用SysUtils替换Forms单元。

    • Place

    •放置

    {$APPTYPE CONSOLE} right under the program statement.

    {$ APPTYPE CONSOLE}就在程序语句的下面。

You are now left with a very small program which looks much like a Turbo Pascal program which, if you compile it will produce a very small EXE. Note that a Delphi console program is not a DOS program because it is able to call Windows API functions and also use its own resources. No matter how you have created a skeleton for a console application your editor should look like:

现在,您剩下一个非常小的程序,该程序看起来很像Turbo Pascal程序,如果您对其进行编译,它将产生一个非常小的EXE。 请注意,Delphi控制台程序不是DOS程序,因为它能够调用Windows API函数并使用其自己的资源。 无论您如何为控制台应用程序创建框架,编辑器都应如下所示:

program Project1;{$APPTYPE CONSOLE}uses SysUtils;

程序 Project1; {$ APPTYPE CONSOLE} 使用 SysUtils;

begin// Insert user code hereend.

开始 //在此处插入用户代码 结束。

This is nothing more than a "standard" Delphi project file, the one with the .dpr extension.

这仅是一个“标准” Delphi项目文件扩展名为.dpr

  • The program keyword identifies this unit as a program's main source unit. When we run a project file from the IDE, Delphi uses the name of the Project file for the name of the EXE file that it creates - Delphi gives the project a default name until you save the project with a more meaningful name.

    program关键字将该单元标识为程序的主要源单元。 当我们从IDE运行项目文件时,Delphi使用项目文件的名称作为它创建的EXE文件的名称-Delphi为项目提供默认名称,直到您使用更有意义的名称保存项目为止。

  • The $APPTYPE directive controls whether to generate a Win32 console or graphical UI application. The {$APPTYPE CONSOLE} directive (equivalent to the /CC command-line option), tells the compiler to generate a console application.

    $ APPTYPE指令控制是生成Win32控制台还是图形UI应用程序。 {$ APPTYPE CONSOLE}指令(等效于/ CC命令行选项),告诉编译器生成控制台应用程序。

  • The uses keyword, as usual, lists all the units this unit uses (units that are part of a project). As you can see, the SysUtils unit is included by default. Another unit is included too, the System unit, though this is hidden from us.

    像往常一样, uses关键字列出了此单元使用的所有单元(属于项目一部分的单元)。 如您所见,默认情况下包含SysUtils单元。 也包括另一个单元,即系统单元,尽管这对我们来说是隐藏的。

  • In between the begin ... end pair you add your code.

    开始 ... 结束对之间添加代码。

翻译自: https://www.thoughtco.com/console-applications-with-no-gui-4077224

怎么为控制台程序编写gui

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值