以C++重寫Borland VCL Framework

4 09 2008

以C++重寫Borland VCL Framework一直是我的夢想

所以我開始這個計畫,就是實現一個與VCL很相似的Win32 GUI Framework

目前都還在起步階段

我設計的這個framework暫時稱作Compact GUI Library (CGL)

目前的framework程式碼 在此下載

支援GNU C++,MS VC++,Borland C++ Compiler

整個framework的變數命名都盡量與VCL相近

說明白一點,就是我要用純C++重寫Borland VCL。

不想再看到任何Object Pascal的影子!

到底CGL與VCL有多相近呢?

一個典型的CGL 程序的代碼範例如下:

#include "cgl.hpp"

class TForm1:public TForm{
    public:
        TButton *btn,*btn2;
        TForm1(char *_ClassName):TForm(_ClassName)
        {
            ;
        }
        void Init()
        {
            btn = new TButton;
            btn->AttachTo(this->Handle);
            btn->OnMouseClick = TMEM(TForm1,clickbutton);
            btn->Height = 10;
            btn2 = new TButton;
            btn2->AttachTo(this->Handle);
        }
        ~TForm1()
        {
            delete btn;
        }
        int clickbutton(void * Sender)
        {
            ShowMessage("Button Clicked!");
            Caption = "Google !";
            Canvas->MoveTo(0,0);
            Canvas->LineTo(350,350);
            Canvas->Brush->Style = bsSolid;
            Canvas->Rectangle(0,0,400,400);
            Canvas->Font->Size = 24;
            Canvas->Font->Name = "新細明體";
            Canvas->Font->Underline = true;
            Canvas->TextOut( 50,50 , "窗外有藍天,視野寬廣無限。" );
            TBitmap *bmp = new TBitmap(200,200);
            bmp->Canvas->Brush->Color = TColor(120,235,160);
            bmp->Canvas->FillRect(TRect(0,0,200,200));
            bmp->Canvas->Brush->Style = bsClear;
            bmp->Canvas->Font->Italic = true;
            bmp->Canvas->Font->Size = 16;
            bmp->Canvas->TextOut(0,0,"CodeGear C++Builder");
            ::BitBlt( Canvas->Handle() ,0,0,200,200,bmp->Canvas->Handle(),0,0,SRCCOPY);
            delete bmp;
            return 0;
        }
};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
    Application = new TAPPLICATION;
    Application->Init(hInstance,hPrevInstance);

    try{
        TForm1 *win;
        win = new TForm1("Form1");
        win->Create();
        win->Init();
        win->Width = 600;
        win->Height = 200;
    }catch( Exception &exception ){
        Application->ShowException(&exception);
    }
    catch (...)
    {
        try
        {
            throw Exception("");
        }
        catch (Exception &exception)
        {
            Application->ShowException(&exception);
        }
    }

    int ret = Application->Run();
    delete Application;
    return ret;
}

Actions

Information

3 responses

11 09 2008
Fei

Do you have the plan to make it an opensource project ?

24 11 2008
Virginia

Well said.

24 10 2009
初學C++

你好,無法下載framework程式碼是否可以寄給我
(是否可在DEV C++下COMPILER)

Leave a comment