Ecere SDK/eC Forums • View topic - What does the main() look like?




Ecere SDK/eC Forums

Ecere Developers Community

What does the main() look like?

General help with the eC language.

What does the main() look like?

Postby samsam598 » Wed Aug 24, 2011 5:33 am

I am wondering what the main() funtion has been organized?Is it something like below?
Code: Select all

class Form1:Window
{
}
Form1 form1;
int main(int argc,char* argv[])
{
    THE_MAIN_FORM=form1;// Global variable
    return 0;
}

And what if I want to show another window,say a splash window before the main windows shows?

Thanks.
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: What does the main() look like?

Postby jerome » Wed Aug 24, 2011 11:57 am

When you import Ecere, you pick up a default GUI Application class, called GuiApplication.

If you want to define your own Main() (declared as a virtual function in Application), or override Init(), Cycle() or Terminate(), you need to define your own Application/GuiApplication class.

e.g. a console Hello World would be:
Code: Select all
class Hello : Application
{
   void Main()
   {
      PrintLn("Hello!");
   }
}


To create global window instances in a specific order you could do:

Code: Select all
class MyGUIApp : GuiApplication
{
   bool Init()
   {
      form1.Create();
      form2.Create();
      return true;
   }
}
MyForm form2 { };
MyForm form1 { };


The default order of window creations is otherwise controlled by the order in which you declare the instances. The order of eC module within your project also (sadly, at some point we should fix that, especially that we're still missing an item reordering in the Project View file list) have an impact (instances from modules added first are created first).

GuiApplication provides a default Main() method that creates all windows (unless their autoCreate property is set to false), and then run a GUI loop until no more windows are left.

If you override it, you lose this automatic functionality, so you have to make sure to put in your own loop, or chain to GuiApplication::Main(). Here is a very basic Main loop:
Code: Select all
class MyGUIApp : GuiApplication
{
   bool terminate;
   void Main()
   {
      form1.Create();
      while(!terminate)
      {
         bool wait;
         UpdateDisplay();
         wait = !ProcessInput(true);
         if(wait) Wait();
      }
      return true;
   }
}
MyForm form1 { };

You can also take a look at GuiApplication's Main() in sdk/ecere/src/gui/GuiApplication.ec

Regards,

Jerome
jerome
Site Admin
 
Posts: 623
Joined: Sat Jan 16, 2010 11:16 pm


Return to eC Language

Who is online

Users browsing this forum: No registered users and 1 guest

cron