Home > Back-end >  GCC using VCL (LCL) https://github.com/ying32/liblcl
GCC using VCL (LCL) https://github.com/ying32/liblcl

Time:12-25

The address of the project:
https://github.com/ying32/liblcl

Familiar with the library cross-platform open source without copyright problems


C language called liblcl example
 
//main. C: this file contains the "main" function, the program will start and end here,
//

# include "liblcl. H"


# ifdef _WIN32
//UTF8 decoding
Char * UTF8Decode (char * STR) {
Int len=MultiByteToWideChar (CP_UTF8, 0, STR, 1, 0, 0).
Would be * wCharBuffer=(*) would be malloc (len * sizeof (would) + 1);
MultiByteToWideChar (CP_UTF8, 0, STR, 1, wCharBuffer, len);

Len=WideCharToMultiByte (wCharBuffer CP_ACP, 0, 1, 0, 0, 0, NULL);
Char * aCharBuffer=(char *) malloc (len * sizeof (char) + 1);
WideCharToMultiByte (wCharBuffer CP_ACP, 0, 1, aCharBuffer, len, 0, NULL);
Free ((void *) wCharBuffer);

Return aCharBuffer;
}
# endif

//button click event
Void onButton1Click (TObject sender) {
ShowMessage (" Hello world!" );
}

//file drag and drop event
Void onOnDropFiles (TObject sender, void * aFileNames, intptr_t len) {
Printf (" aFileNames: % p, len=% d \ n ", aFileNames, len);
Intptr_t I;
//GetFPStringArrayMember for a member function was obtained from the string array of Lazarus,
for (i=0; I & lt; Len. I++) {

# ifdef _WIN32
//because liblcl use utf-8 encoding, so get or incoming under the Windows, it takes the utf-8 encoding/decoding
Char * filename=UTF8Decode (GetFPStringArrayMember (aFileNames, I));
# the else
//Linux and macOS default is utf-8, without the encoding/decoding
Char * filename=GetFPStringArrayMember (aFileNames, I);
# endif
Printf (" file [% d]=% s \ n ", I + 1, filename);
# ifdef _WIN32
Free ((void *) filename);
# endif
}
}

//window, press the keyboard events
Void onFormKeyDown (TObject sender, Char * key, TShiftState shift) {
Printf (" key=% d, shift=% d \ n ", * key, shift);
If (* key==vkReturn) {
ShowMessage (" press Enter!" );
}

TShiftState s=the Include (0, ssAlt);
{if (an InSet (s, ssAlt))
Printf (" ssAlt1 \ n ");
}
S=Exclude (s, ssAlt);
if (! An InSet (s, ssAlt)) {
Printf (" ssAlt2 \ n ");
}
}

//edit box content change events
Void onEditChange (TObject sender) {
Printf (" % s \ n ", Edit_GetText (sender));
}

Int main ()
{
//load the library
# ifdef _WIN32
If (load_liblcl (" liblcl. DLL ")) {
# endif
# ifdef __linux__
If (load_liblcl (" liblcl. So ")) {
# endif
# ifdef __APPLE__
If (load_liblcl (" liblcl. Dylib ")) {
# endif

//the main window display in the task bar, Windows only effective
Application_SetMainFormOnTaskBar (Application, TRUE);
//the application title, affect, such as the title of the ShowMessage,
Application_SetTitle (Application, "Hello, LCL");
//initialize the application
Application_Initialize (Application);

//create a window
TForm form=Application_CreateForm (Application, FALSE);
//set the window title
LCL Form_SetCaption (form, "form");
//Settings window position
Form_SetPosition (form, poScreenCenter);

//- drag and drop files test -- -- --
Receive files//drag
Form_SetAllowDropFiles (form, TRUE);
//drag and drop files event
Form_SetOnDropFiles (form, onOnDropFiles);

//window receive priority keys, is not affected by other
Form_SetKeyPreview (form, TRUE);

//window button event
Form_SetOnKeyDown (form, onFormKeyDown);

//-- -- -- -- -- -- -- -- -- -- from the memory stream or loading the UI layout file -- -- -- -- -- -- -- -- -- --
//loaded from a file window Settings
//from the flow load
//TMemoryStream mem=NewMemoryStream ();
//MemoryStream_Write (mem, data, datalen);
//MemoryStream_SetPosition (mem, 0);
//ResFormLoadFromStream (mem, form);
//MemoryStream_Free (mem);

//loaded from a file
//ResFormLoadFromFile ("./Form1. GFM ", form);

//-- -- -- -- -- -- -- -- -- -- dynamically created controls -- -- -- -- -- -- -- -- -- --
//create a button
TButton BTN=Button_Create (form);
//set the child parent window
Button_SetParent (BTN, form);
//set button click event
Button_SetOnClick (BTN, onButton1Click);
//set button title
Button_SetCaption (BTN, "for the");
//set button on the left side of the Parent position
Button_SetLeft (BTN, 100);
//set button at the top of the Parent to edge position
Button_SetTop (BTN, 100);

//to create a single file box (TMemo)
TEdit edit=Edit_Create (form);
//set the child parent window
Edit_SetParent (edit, form);
//set the left
Edit_SetLeft (edit, 10);
//set the topside
Edit_SetTop (edit, 10);
//set editor content change events
Edit_SetOnChange (edit, onEditChange);

//run the app
Application_Run (Application);

//release liblcl library
Close_liblcl ();
}
return 0;
}

CodePudding user response:

Class library in C library? How to make interface design?

CodePudding user response:

The dynamic link? I tried to GCC obj generated by the static link Delphi, use the VCL, FMX didn't get success, no external dependencies can be, but little sense

CodePudding user response:

Dynamic link, using the LCL library (Lazarus that set of library)

CodePudding user response:

Makes little sense to feel, not equal to the UI with Lazarus, function module, and then link the GCC wrote both to dynamic link can also be static link (Free Pascal also static link C obj)

CodePudding user response:

If there is a c + + version of Lazarus, a Linux platform will be more convenient,

CodePudding user response:

CB has a Linux version of the compiler, but currently only support x64, does not support x86 and ARM, MIPS

CodePudding user response:

nullnullnullnullnullnullnull
  • Related