Ecere SDK/eC Forums
http://ec-lang.org/community/
Print view

What does the main() look like?
http://ec-lang.org/community/viewtopic.php?f=1&t=165
Page 1 of 1
Author:  samsam598 [ Wed Aug 24, 2011 5:33 am ]
Post subject:  What does the main() look like?

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.
Author:  jerome [ Wed Aug 24, 2011 11:57 am ]
Post subject:  Re: What does the main() look like?

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
All times are UTC-05:00 Page 1 of 1