Sample1: Hello, world.

This page shows the source code needed to realize the MGUI version of the 'Hello' program (first example in the Kernighan & Ritchie C language bible).
An utility function is used in this example to display a message box.

In order to be compatible with Windows, MGUI programs cannot start execution with the standard main() function. However, MGUI programs receive the standard argc, argv as arguments of the program's entry point. The C program starts at the global function MGUIMain(int argc, char **argv) while the C++ program starts execution with a call to a user provided method start(int argc, char **argv).

The C++ version of this program is bit larger than the C version since it requires an 'Application class' and an 'Application Instance' to be defined. Every C++ MGUI program must provide a pure virtual method in the base abstract class CmAppl. So the program must declare a class, derived from CmAppl, and then it must also instantiate an object of such class to complete program initialization.


/* C version */ #include <stdio.h> #include "mgui.h" /* C program's entry point */ void MGUIMain(int argc, char **argv) {    MMessageDialog("Message", "Hello, world", " Ok ", NULL); }
// C++ version
#include <stdio.h>
#include "mguipp.h"

// Application class.
class CaAppl : public CmAppl {
public:
        void start(int, char **);
};

// Application instance
CaAppl appInstance;

// C++ program's entry point
void CaAppl::start(int argc, char **argv)
{
   messageDialog("Message", "Hello, world", " Ok ", NULL);
}






Screenshot

Back