zoukankan      html  css  js  c++  java
  • C++ Builder入门第一例

    Project1.cpp:

    #include <vcl.h>
    #include <tchar.h>
    
    class Tmyform : public TForm    //定义一个窗体类
    {
    __published:    //VCL组件成员及事件处理函数
        TLabel *Label1,*Label2;
        TEdit *Edit1;
        TButton *btnOk,*btnExit;
        void __fastcall btnOkClick(TObject *Sender);
        void __fastcall btnExitClick(TObject *Sender);
    private:
    public:
        __fastcall Tmyform(TComponent* Owner);    //构造函数
    };
    
    __fastcall Tmyform::Tmyform(TComponent* Owner)
        : TForm(Owner)
    {
    btnExit->Enabled=false;
    btnOk->Default=true;
    }
    void __fastcall Tmyform::btnOkClick(TObject *Sender)
    {
    this->Label2->Caption="你好,"+this->Edit1->Text;
    this->btnExit->Enabled=true;
    }
    void __fastcall Tmyform::btnExitClick(TObject *Sender)
    {
    this->Close();
    }
    
    #pragma resource "*.dfm"    //包含Project1.dfm文件,设置组件的一些属性的值
    
    WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)    //相当于DOS程序中的main函数
    {
        Tmyform *f1;
        Application->Initialize();    //进行一些初始化工作
        Application->CreateForm(__classid(Tmyform), &f1);    //创建对象f1作为主窗体
        Application->Run();    //显示主窗体,进入循环,开始处理消息
        return 0;
    }

    Project1.dfm:

    object f1: Tmyform
      Left = 0
      Top = 0
      Caption = 'Hello C++ Builder'
      ClientHeight = 263
      ClientWidth = 592
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object Label1: TLabel
        Left = 16
        Top = 16
        Width = 36
        Height = 13
        Caption = #22995#21517#65306
      end
      object Label2: TLabel
        Left = 16
        Top = 35
        Width = 31
        Height = 13
        Caption = 'Label2'
      end
      object Edit1: TEdit
        Left = 80
        Top = 13
        Width = 121
        Height = 21
        TabOrder = 0
      end
      object btnOk: TButton
        Left = 16
        Top = 64
        Width = 75
        Height = 25
        Caption = '&OK'
        TabOrder = 1
        OnClick = btnOkClick
      end
      object btnExit: TButton
        Left = 126
        Top = 64
        Width = 75
        Height = 25
        Caption = '&Exit'
        TabOrder = 2
        OnClick = btnExitClick
      end
    end

    编译方法:

    bcc32 -WV Project1.cpp

    把这个例子和C++ Builder自动生成的工程对比一下,你会学到一些东西的。

    -WV:生成使用VCL的Windows程序

    程序运行后的效果如下图:

    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    SpringBoot(八):SpringBoot中配置字符编码 Springboot中文乱码处理
    SpringBoot(二): SpringBoot属性配置文件 SpringBoot多环境配置文件 SpringBoot自定义配置文件
    使用Maven新建SpringBoot工程
    SpringBoot(四): SpringBoot web开发 SpringBoot使用jsp
    SpringBoot(三):SpringBoot热部署插件
    SpringBoot(六):SpringBoot中如何使用Servlet?
    ARQ自动重传请求与UDP提供可靠交付
    多线程程序中操作的原子性转帖
    多目录的Makefile
    VC++小小绘图程序
  • 原文地址:https://www.cnblogs.com/jijm123/p/14337122.html
Copyright © 2011-2022 走看看