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

📄 splash.cpp

📁 MicroStation源代码
💻 CPP
字号:
/*----------------------------------------------------------------------+
|  
|   splash
|
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
|
|   STATUS: WORKING
|   DATE:   1/11/00 9:55:18 AM
|
|   This example demonstrates how to place a JPG image on a dialog box
|   using a Generic item.  The splash screen disapears after 10 seconds.
|   You can change the expire time in the variable expireTime below.
|
|   Note:
|   =====
|   The image file needs to be located in a directory pointed to by
|   the MicroStation environment variable MS_DEF.
|
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
|
|   Include Files
|
+----------------------------------------------------------------------*/
#include <mdl.h>
#include <cmdlist.h>
#include <string.h>

#include <msvar.fdf>
#include <dlogman.fdf>
#include <msfile.fdf>
#include <msinput.fdf>
#include <msoutput.fdf>
#include <msrsrc.fdf>
#include <msstate.fdf>
#include <mssystem.fdf>
#include <msimage.fdf>

#include "splash.h"

/*----------------------------------------------------------------------+
|
|   Private Global variables
|
+----------------------------------------------------------------------*/

/*
    Set your splash display time in seconds here

    Note:
    Time is expressed in ticks (one-sixtieth of a second increments).
    To convert seconds to ticks:
    
    i.e. 10 seconds = 10 * 60(ticks)
*/

Private int expireTime = 5;

/*----------------------------------------------------------------------+
|
|   Function Declarations
|
+----------------------------------------------------------------------*/
void mdlWindow_findUsableSpace (BSIRect *, int, int);

/*----------------------------------------------------------------------+
|
|   name        exitApplication
|
|   author      BSI                                         12/1998
|
+----------------------------------------------------------------------*/
Private void exitApplication
(
void
)
    {
    /* Queue up a command to unload the current MDL application */
    mdlDialog_cmdNumberQueue (FALSE, CMD_MDL_UNLOAD,
                              mdlSystem_getCurrTaskID (), TRUE);

    mdlState_startDefaultCommand ();
    }

/*----------------------------------------------------------------------+
|
|   name        dialogCenter
|
|   author      BSI                                         12/1998
|
+----------------------------------------------------------------------*/
Private void dialogCenter
(
long id /* => Dialog ID to center */
)
    {
    Point2d     orgin;
    DialogBox   *dbP;
    DialogBox   *mswindowP;
    BSIRect     rectP,rectP2;
    int         height, height2, weight, weight2;

    /* Verify if dialog box exists */
    if ((dbP = mdlDialog_create (NULL, NULL, RTYPE_DialogBox, id, FALSE)) )
        {
        /* Get the usable display area of the MicroStation main screen */
        mdlWindow_findUsableSpace (&rectP2, 0, 101);
        /*(
        BSIRect *useRectP,
        int      screen,    <== Should be 0. Set to the number of graphic heads - 1
        int      priority   <== Set priority to 0 for within the work area. or
                                use 101 for the entire window.
        ); */
    
        /* Store the height and width of the MicroStation main screen */
        height2 = mdlDialog_rectHeight (&rectP2);
        weight2 = mdlDialog_rectWidth (&rectP2);

        /* Get the height and width of our dialog box */
        mdlWindow_globalRectGetGlobal (&rectP, dbP);
        
        /* Store the height and width of our dialog box */
        height = mdlDialog_rectHeight (&rectP);
        weight = mdlDialog_rectWidth (&rectP);

        /* Find the origin points to place our dialog box at the center */
        orgin.x = (mdlDialog_toPixels (dbP, weight2) - mdlDialog_toPixels (dbP, weight))/2;
        orgin.y = (mdlDialog_toPixels (dbP, height2) - mdlDialog_toPixels (dbP, height))/2; 
     
        /* Display the dialog box */
        mdlWindow_resize (dbP, CORNER_ALL, &orgin);
        mdlDialog_show (dbP);
        }

    return;
    }

/*----------------------------------------------------------------------+
|
|   name        dialogClose
|
|   author      BSI                                         12/1998
|
+----------------------------------------------------------------------*/
Private int dialogClose
(
long id,        /* => Dialog ID to close */
char *taskIdP   /* => NULL or MDL TASK ID */
)
    {
    DialogBox   *dbP;
    void        *ownerMD;

    if (taskIdP)
        {
        ownerMD = mdlSystem_findMdlDesc (taskIdP);
        dbP = mdlDialog_find (id, ownerMD);
        }
    else
        {
        dbP = mdlDialog_find (id, NULL);
        }

    if (mdlDialog_closeCommandQueue (dbP))
        {
        return !SUCCESS;
        }
    else
        {
        return NULL;
        }
    }

/*----------------------------------------------------------------------+
|
|   name        dialogHook
|
|   author      BSI                                         1/2000
|
+----------------------------------------------------------------------*/
Private void dialogHook
(
DialogMessage *dmP /* => a ptr to a dialog message */
)
    {
    /* Set to TRUE if dealing with any of the following messages/events */
    dmP->msgUnderstood = TRUE;

    /* Only look for specific events */
    switch (dmP->messageType)
        {
        /* This is called when the dialog box is created in memory
           and before being displayed. No dialog items have been created
           at this point. This is also where we can specify
           additional events to be processed for this item */
        case DIALOG_MESSAGE_CREATE:
            {
            /* Create an interest in button clicks on our dialog box */
            dmP->u.create.interests.mouses = TRUE;
            break;
            }

        case DIALOG_MESSAGE_BUTTON:
            {
            if (dmP->u.button.buttonTrans == BUTTONTRANS_DOWN)
                {
                /* Exit the current MDL application */
                dialogClose (DIALOGID_DIALOG1, NULL);
                exitApplication ();
                }
            break;    
            }

        default:
            /* Set value to FALSE for all other messages */
            dmP->msgUnderstood = FALSE;
            break;
        }                                       
    }

/*----------------------------------------------------------------------+
|
|   name        genericItemHook
|
|   author      BSI                                         1/2000
|
+----------------------------------------------------------------------*/
Private void genericItemHook
(
DialogItemMessage *dimP /* => a ptr to a dialog item message */
)    
    {
    /*
        This function is called to process the generic item
        i.e. display the image on our dialog box.
    */
    dimP->msgUnderstood = TRUE;        /* Only look for specific events */
    switch (dimP->messageType)        {        /* This is called when the dialog item is created in memory*/
        case DITEM_MESSAGE_CREATE:            {            DialogItem  *diP = dimP->dialogItemP;            Point2d     itemSize;            char        fullFileSpec[MAXFILELENGTH + 1];            byte        *rgbBufferP;                                   /* Calculate the size of the item on the dialog box */
            itemSize.x = diP->rect.corner.x - diP->rect.origin.x + 1;            itemSize.y = diP->rect.corner.y - diP->rect.origin.y + 1;
            /* Make sure the image file exists */
            if (! mdlFile_find (fullFileSpec, diP->rawItemP->labelP, "d:\\lg_app_mdl\\splash\\", ".jpg"))                {                /* Read the file into memory */
                if (! mdlImage_readFileToRGB (&rgbBufferP, NULL, fullFileSpec,                                              -1,&itemSize, NULL))
                    {
                    /* Associate the memory to our dialog as user data */
                    mdlDialog_userDataPtrSet (dimP->db, rgbBufferP);                    }
                }            break;            }            /* This is called whenever a redraw is required */
        case DITEM_MESSAGE_DRAW:            {            int         i, rowLength;            byte        *redP, *greenP, *blueP;            DialogItem  *diP = dimP->dialogItemP;            /* Get the current pointer to our image */
            if (redP = mdlDialog_userDataPtrGet (dimP->db))                {                rowLength = diP->rect.corner.x - diP->rect.origin.x + 1;                greenP = redP  + rowLength;                blueP = greenP + rowLength;                /* Display all rows of the imeage */
                for (i = diP->rect.origin.y; i <= diP->rect.corner.y; i++)                    {                    /* Draw the current row of the image */
                    mdlDither_drawRow (dimP->db, diP->rect.origin.x,                                        diP->rect.corner.x, i,                                       redP, greenP, blueP);
                    /* Increment the RGB pointers */
                    redP   += 3 * rowLength;                    greenP += 3 * rowLength;                    blueP  += 3 * rowLength;                    }
                }
            /* Draw a frame/border around the image */
            mdlDialog_rectDrawEdge (dimP->db, &diP->rect, TRUE);            break;            }
        /* This is called when the dialog item has been destroyed */    
        case DITEM_MESSAGE_DESTROY:            {            byte *imageP;                /* Free the memory associated with the image */
            if (imageP = mdlDialog_userDataPtrGet (dimP->db))
                {
                free (imageP);                }
            break;            }                default:            /* Set value to FALSE for all other messages */
            dimP->msgUnderstood = FALSE;            break;        }    }       

/*----------------------------------------------------------------------+
|
|	name        timerFunc
|
|   author      BSI                                         1/2000
|
+----------------------------------------------------------------------*/
Private void timerFunc
(
int	userArg,
int	timerHandle
)
    {
    static boolean  hasRun = FALSE;
    static int      startTicks = 0;
    static int      elapsedTime = 0;
    
    /* Run only once */
    if (hasRun == FALSE)
        {
        /* Record time started */
        startTicks = mdlSystem_getTicks ();
        hasRun = TRUE;
        }

    /* Get elapsed time from start */
    elapsedTime = ((mdlSystem_getTicks () - startTicks) / 60);

    /* When elapsed time equals the expireTime */
    if (elapsedTime == expireTime)
	    {
	    /* Exit the current MDL application */
		dialogClose (DIALOGID_DIALOG1, NULL);
	    exitApplication ();
	    }
    }

/*----------------------------------------------------------------------+
|
|	name        timerStart
|
|   author      BSI                                         1/2000
|
+----------------------------------------------------------------------*/
Private void timerStart
(
void
)
    {
    int timerHandle = 0;
    
    /* Set our timer function's hook */
    mdlSystem_setTimerFunction (&timerHandle, 60, timerFunc, NULL, TRUE);
    }

/*----------------------------------------------------------------------+
|
|   publishHooks
|
|   author      BSI                                         12/1998
|
+----------------------------------------------------------------------*/
Private void publishHooks
(
void
)
    {
    static DialogHookInfo uHooks[] = 
        {
        {HOOKDIALOGID_DIALOG1,  dialogHook},
        {HOOKITEMID_IMAGE,      genericItemHook},
        }; 

    mdlDialog_hookPublish (sizeof (uHooks) / sizeof (DialogHookInfo), uHooks);
    }

/*----------------------------------------------------------------------+
|
|   name        openResources
|
|   author      BSI                                         12/1998
|
+----------------------------------------------------------------------*/
Private void openResources
(
void
)
    {
    RscFileHandle rscH;

    if (mdlResource_openFile (&rscH, NULL, RSC_READONLY) != SUCCESS)
        {
        mdlOutput_error ("Unable to load Resource File.");
        }
    }

/*----------------------------------------------------------------------+
|                                   
|   name        main                                
|
|   author      BSI                                         12/1998
|                                   
+----------------------------------------------------------------------*/
Private int main 
(
int     argc,   /* => Number of arguments passed in argv */
char    *argv[] /* => Array of pointers to arguments */
)   
    {
    /* Open our application for use with the Resource Manager */
    openResources ();

    /* Publish hook functions for our dialog box and items */
    publishHooks ();

    /* If user is calling within MicroStation */
    if (strcmp (argv[1], "USER") != SUCCESS)
        {
        dialogCenter (DIALOGID_DIALOG1);
        timerStart ();
        }
    else
        {
        /* User is processing in an off line mode */
        /* Init applications - Not yet implemented */

        //mdlSystem_enterGraphicsExtended (1);
        //timerStart ();
        
        /* Exit the current MDL application */
		printf("defe");
        exitApplication ();
        return SUCCESS;
        }

    return SUCCESS;
    }

⌨️ 快捷键说明

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