⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpletemplate.c

📁 Tilcon是目前最先进的实时操作系统图形开发工具。同步支持最新版本的Tornado/VxWorks以及WindML多媒体库。适用与VxWorks实时环境下构建虚拟仪表
💻 C
字号:
/***********************************************************************
**      simpletemplate.c
***********************************************************************/

/*----------------------------------------------------------------------
**      Define the Main TWD window filename.
**
**      To use a filename other than "main.twd", you can give the name
**      of your TWD file on the command line as the first argument or
**      change the following line:
*/

#define MAIN_WINDOW_FILE  "main.twd"

/*----------------------------------------------------------------------
**      Change the following lines if you are going beyond a simple application
**
**      Each engine can work with many applications but APPNAME should be unique
**      unless the applications cooperate to share the same objects.
**
**      Each application can open many channels to other applications and
**      engines but each channel's USERPROG in the application must be unique.
*/

#define APPNAME                 "simpletemplate"
#define USERPROG                "simpletemplate"


/*----------------------------------------------------------------------
**      INCLUDE FILES
*/

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <tilcon/TRTAPI.h>      /* Tilcon API functions */

#if defined (CC_TRT_DOS)
#include <windows.h>
#endif


/*----------------------------------------------------------------------
**      define TRT_OS_ENV
**
**      NOTE: do not change the order
**            CC_TRT_WCE has CC_TRT_DOS defined as well and must follow it
*/
#ifdef          CC_TRT_VXWORKS
#define TRT_OS_ENV TRT_VXWORKS
#endif

#ifdef          CC_TRT_NTO
#define TRT_OS_ENV TRT_NTO_PHOTON
#endif

#ifdef          CC_TRT_DOS
#define TRT_OS_ENV TRT_MS_WINDOWS
#endif

#ifdef          CC_TRT_WCE
#define TRT_OS_ENV TRT_WCE
#endif

#ifdef          CC_TRT_LINUX
#define TRT_OS_ENV TRT_LNX_X11R6
#endif


/*----------------------------------------------------------------------
**      GLOBALS
*/

pid_t TRT_cid;                             /* Identifies Tilcon Runtime */
TRT_ReceiveData rec_data;                  /* Record from API */
char *main_window_file = MAIN_WINDOW_FILE; /* twd filename */
char  main_window_id[TRT_MAX_ID_LENGTH];   /* window id inside file */


/*----------------------------------------------------------------------
**      On Error Exit With Message Box
*/

void ExitBox(char *ErrorMessage)
{
    TRT_MessageBox( TRT_cid, NULL, APPNAME,
            ErrorMessage, NULL, "OK", NULL,
            TRT_MessageBox_FontHelvetica, 14,
            TRT_MessageBox_Exclamation|TRT_MessageBox_Wait,
            0, NULL, NULL);
    TRT_Exit (TRT_cid);
    exit(0);
}

/***********************************************************************
**************************  Main Entry Point  **************************
***********************************************************************/

#if defined(CC_TRT_DOS) && !defined(_CONSOLE)
/*----------------------------------------------------
**      MS Windows non-console application entry point
*/
int PASCAL WinMain ( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow )
{
#else
/*----------------------------------------------------
**      standard application entry point
*/
int main ( int argc, char *argv[] )
{
#endif

    /*----------------------------------------------
    **  variables
    */

    long           errorcode = 0;
    int            c;
    int            ContinueLooping = TRUE;
    TRT_StartData  StartData;


    /*----------------------------------------------
    **  if given an optional command line argument , use it
    */

#if defined(CC_TRT_DOS) && !defined(_CONSOLE)

    if(lpszCmdLine && lpszCmdLine[0])
    {
        /*
        **      Assume the lpszCmdLine contains only
        **      the single TWD filename
        */
        main_window_file = lpszCmdLine;
    }

#else

    if(argc > 1)
    {
        main_window_file = argv[1];
    }

#endif

    /*----------------------------------------------
    **  Initialize the StartData structure
    */
    StartData.Os_Env    = TRT_OS_ENV;
    StartData.Display   = NULL;
    StartData.IPAddr    = NULL;
    StartData.AppName   = APPNAME;
    StartData.Userprog  = USERPROG;
    StartData.Flags     = 0;

    /*----------------------------------------------
    **  Start the Embedded Engine and connect to it
    */
    errorcode = TRT_StartEx (0, &StartData);
    TRT_cid   = StartData.TRT_CID;

    if(errorcode)
    {
            printf("Cannot Start Runtime\n");
            exit(0);
    }

    /*----------------------------------------------
    **  force all API commands to be synchronous
    */
    errorcode = TRT_Debug(TRT_cid, 3);

    if(errorcode) ExitBox("Cannot run TRT_Debug");

    /*----------------------------------------------
    **  Load Main Window
    */
    errorcode  = TRT_WindowLoad(TRT_cid, main_window_file );

    if(errorcode) ExitBox("Cannot load the Main Window! File NOT found");

    /*----------------------------------------------
    **  Get the name of the Window
    */
    errorcode = TRT_GetWindowID(TRT_cid,main_window_id);

    if(errorcode) ExitBox("Cannot Get Main Window ID");

    /*----------------------------------------------
    **  Display Main Window
    */
    errorcode = TRT_WindowDisplay(TRT_cid,main_window_id);

    if(errorcode) ExitBox("Cannot Display Main Window");

    /*----------------------------------------------
    **  Main Loop
    **  Wait for communication from Engine
    **  Act on notification
    */
    while(ContinueLooping)
    {

        /* Wait for a notification */
        c = TRT_GetInput(NULL, 0, NULL, 0, &rec_data, TRT_BLOCK);

        switch(c)
        {
            /*------------------
            **  Received a standard notification
            */
            case 0:
            {
                /*
				** what type of object is notifying us?
                */
				switch (rec_data.code)
                {
                    /*------------------
                    **  if 'X' close button is presed
                    **  on the window title bar, then stop looping
                    */
                    case TRT_window:
                    if (rec_data.state == TRT_window_quit)
                    {
                        ContinueLooping = FALSE;
                    }
                    break;

                    /*------------------*/
                    default:
                    {
                        char message[40+TRT_MAX_ID_LENGTH];
                        sprintf(message,"Unhandled notification for object '%s'",rec_data.ID);
                        TRT_MessageBox( TRT_cid, NULL, APPNAME,
                            message, NULL, "OK", NULL,
                            TRT_MessageBox_FontHelvetica, 14,
                            TRT_MessageBox_Exclamation|TRT_MessageBox_Wait,
                                                0, NULL, NULL);
                    }

                }
            }
            break;

            /*------------------
            **  A Callback function was called inside TRT_GetInput
            */
            case 1:
            break;

            /*------------------
            **  Non-blocking mode -- no new events or a critical error
            **  Blocking mode -- a critical error
            */
            case -1:
            break;

            /*------------------
            **  should never happen
            */
            default:
            break;

        }
    }

    /*----------------------------------------------
    **  Cleanup and exit
    */

    TRT_WindowDelete (TRT_cid, main_window_id ); /* Close Window */
    TRT_Exit (TRT_cid);                          /* Notify Runtime to exit */
    return(0);
}

/********************** end of file simpletemplate.c ********************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -