home *** CD-ROM | disk | FTP | other *** search
/ Chip Hitware 7 / Chip_Hitware_Vol_07.iso / chiphit7 / multmedi / 95caddra / _002380_ < prev    next >
Text File  |  1996-06-04  |  28KB  |  717 lines

  1. //------------------------------------------------------------------------------------------------------
  2. // Name       : tsample_.c
  3. // Date       : 23.05.1996     Author : SM           System : Win32
  4. //------------------------------------------------------------------------------------------------------
  5. // This file contains the language-independent implementation of the module TSAMPLE_.DLL. All texts and
  6. // resources that are language-dependent are located in an additional TSAMPLE.DLL, whose sources can be
  7. // found in the subdirectories \E (for English) and \D (for German).
  8. //------------------------------------------------------------------------------------------------------
  9.  
  10. #define USER_DATA_ID          "1.00-1995-08-10"
  11.  
  12. //------------------------------------------------------------------------------------------------------
  13.  
  14. #include        "windows.h"
  15. #include        "windowsx.h"
  16. #include        "stdlib.h"
  17. #include        "stdio.h"
  18. #include        "math.h"
  19.  
  20. #include        "e:\release4\toso40.h"          // Toso Interface 4.0 Definitions
  21. #include        "dialog.h"
  22.  
  23. //-----------------------------------------------------------------------------------------------------
  24.  
  25. #define STAR_INDENT_MIN         3       // Minimum number of indents
  26. #define STAR_INDENT_MAX         100     // Maximum number of indents
  27.  
  28. //-----------------------------------------------------------------------------------------------------
  29.  
  30. typedef struct {
  31.   STR32         TimeStamp;
  32.  
  33.   int           StarIndentNum;
  34.   double        StarRotation;
  35. } INF_HEADER;
  36.  
  37. //------ Language-dependent texts in TSAMPLE.DLL -------------------------------------------------------
  38.  
  39. DLL_IMPORT LPSTR
  40.         eStartUpText    [],
  41.         eDialogText     [],
  42.         eMessageText    [],
  43.         eCommandName    [],
  44.         eCommandEntry   [],
  45.         eNewPoint       [];
  46.  
  47. //------------------------------------------------------------------------------------------------------
  48.  
  49. static  HINSTANCE       hInstDLL,               // Instance handle of the main DLL
  50.                         hLanguage,              // Instance handle of the language DLL
  51.                         hGlobalInst;            // Instance handle of the serving application
  52. static  HWND            hGlobalWnd;             // Main window handle of the serving application
  53.  
  54. //------Dialog Window Handling -------------------------------------------------------------------------
  55.  
  56. static  DUMMYSTR        gCaption;               // Current dialog window caption
  57. static  int             gExitDialog;            // Button with which the dialog was canceled
  58. static  INF_HEADER      gCopyHeader;            // Temporary copy of INFHeader
  59.  
  60. //------ Command Processing ----------------------------------------------------------------------------
  61.  
  62. static  INF_HEADER      INFHeader;              // Settings
  63.  
  64. static  DPOINT          gPoint[3];              // Points entered by the user
  65. static  int             gCommandID;             // Current Command's ID
  66. static  HBITMAP         hBitmap;                // Handle of command icon bitmap
  67.  
  68. static  MODULE_COMMAND_DATA     CommandData[TVG_MODULE_SUBMENU_MAX];
  69.  
  70. //------ Command Description ---------------------------------------------------------------------------
  71. // The structure COMMAND_DATA contains a command description. It lists the points to be entered by the
  72. // user and their types. Each point description consists of three values: The point type (POINT_???),
  73. // the index of "related point", i.e. the point to which this point is relative, and a textual
  74. // description of that point.
  75. // The following command required exactly 3 points to be entered (COMMAND_FIXED = number of point to be
  76. // entered is known in advance, "3" says that this known number is three).
  77. // Following a description of those three points to be entered:
  78. // 1) POINT_CENTER = center of a circle, ellipse, etc.
  79. //    "-1"         = no "related point"
  80. //    NULL         = default description
  81. // 2) POINT_RADIUS = radius of a circle
  82. //    "0"          = relative to the point with the index zero (the center point)
  83. //    NULL         = default description
  84. // 3) POINT_RADIUS = radius of a circle
  85. //    "0"          = relative to the point with the index zero (the center point)
  86. //    NULL         = default description
  87. // Please note that the description strings of the points 2) and 3) will be overwritten before passed
  88. // to the serving application in order to change the description to "Enter Radius 1" and "Enter Radius 2"
  89. // (see end of procedure TosoModuleInit()).
  90.  
  91. static  COMMAND_DATA    gInfo[] = {             // Command description structure
  92.         { COMMAND_FIXED,
  93.           3,
  94.           { POINT_CENTER, POINT_RADIUS, POINT_RADIUS },
  95.           { -1, 0, 0 },
  96.           { NULL, NULL, NULL }
  97.         }
  98. };
  99.  
  100. //------------------------------------------------------------------------------------------------------
  101.  
  102. BOOL ModuleLoadSettings( void )
  103. {
  104.   BOOL          Result = FALSE;
  105.  
  106.   if( TosoProfileReadKeyOpen( "TSAMPLE", FALSE ) ) {
  107.     if( TosoProfileReadData( "Init", (LPBYTE) &INFHeader, sizeof( INFHeader ) ) )
  108.       Result = TRUE;
  109.     TosoProfileReadKeyClose();
  110.  
  111.     INFHeader.TimeStamp[31] = 0x00;
  112.     if( lstrcmp( INFHeader.TimeStamp, USER_DATA_ID ) )
  113.       Result = FALSE;
  114.   }
  115.  
  116.   if( !Result ) {
  117.     INFHeader.StarIndentNum = 6;
  118.     INFHeader.StarRotation  = REAL_05PI;
  119.   }
  120.   return( Result );
  121. }
  122.  
  123. //------------------------------------------------------------------------------------------------------
  124.  
  125. BOOL ModuleSaveSettings( void )
  126. {
  127.   BOOL          Result = FALSE;
  128.  
  129.   if( TosoProfileWriteKeyOpen( "TSAMPLE", FALSE ) ) {
  130.     lstrcpy( INFHeader.TimeStamp, USER_DATA_ID );
  131.     if( TosoProfileWriteData( "Init", (LPBYTE) &INFHeader, sizeof( INFHeader ) ) )
  132.       Result = TRUE;
  133.     TosoProfileWriteKeyClose();
  134.   }
  135.   return( Result );
  136. }
  137.  
  138. //------------------------------------------------------------------------------------------------------
  139. // Callback procedure for dialog box handling of DialogEditParamaters(). This procedure handles all
  140. // messages sent to the dialog window.
  141.  
  142. BOOL CALLBACK DialogEditParametersManage( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
  143. {
  144.   static HWND   hOldFocus;
  145.   DUMMYSTR      DummyStr, UnitStr;
  146.   int           DummyInt;
  147.   double        DummyDouble;
  148.  
  149.   switch( message ) {
  150.     case WM_INITDIALOG:                         // Initialize dialog box
  151.       TosoDialogCenter( hDlg );
  152.       SetWindowText( hDlg, gCaption );
  153.  
  154. // Convert the current indent number to a string that can be set to an edit field.
  155.  
  156.       wsprintf( DummyStr, "%d", gCopyHeader.StarIndentNum );
  157.       SetDlgItemText( hDlg, IDD_EDIT0, DummyStr );
  158.  
  159. // Convert the current rotation angle to a string that can be set to an edit field. A conversion made
  160. // by means of TosoConvertAngleString() automatically uses the current coordinate system and its
  161. // parameters like current unit, number diplay, etc. for the conversion.
  162.  
  163.       TosoConvertAngleString( DummyStr, gCopyHeader.StarRotation, UnitStr );
  164.       SetDlgItemText( hDlg, IDD_EDIT1, DummyStr );
  165.       SetDlgItemText( hDlg, IDD_UNIT1, UnitStr );
  166.  
  167. // Set the focus to the first edit field and highlight the complete content of that edit field.
  168.  
  169.       Edit_SetSel( GetDlgItem( hDlg, IDD_EDIT0 ), 0, -1 );
  170.       hOldFocus = SetFocus( GetDlgItem( hDlg, IDD_EDIT0 ) );    
  171.       return( FALSE );
  172.  
  173.  
  174.     case WM_COMMAND:
  175.       switch( GET_WM_COMMAND_ID( wParam, lParam ) ) {
  176.         case IDD_OK:                            // OK
  177.  
  178. // Read the indent number from the edit field and convert it to an integer value.
  179.  
  180.           GetDlgItemText( hDlg, IDD_EDIT0, DummyStr, NAME_LENGTH_EDIT );
  181.           if( sscanf( DummyStr, "%d", &DummyInt ) != 1 ) {
  182.             MessageBox( hDlg, eMessageText[3], eDialogText[0], MB_OK );
  183.  
  184.             Edit_SetSel( GetDlgItem( hDlg, IDD_EDIT0 ), 0, -1 );
  185.             SetFocus( GetDlgItem( hDlg, IDD_EDIT0 ) );    
  186.             return( TRUE );
  187.           }
  188.  
  189. // Check wether the stated indent number is within range. If not, display a message and set the
  190. // focus to the according edit field.
  191.  
  192.           if( DummyInt < STAR_INDENT_MIN || DummyInt > STAR_INDENT_MAX ) {
  193.             MessageBox( hDlg, eMessageText[3], eDialogText[0], MB_OK );
  194.  
  195.             Edit_SetSel( GetDlgItem( hDlg, IDD_EDIT0 ), 0, -1 );
  196.             SetFocus( GetDlgItem( hDlg, IDD_EDIT0 ) );    
  197.             return( TRUE );
  198.           }
  199.           gCopyHeader.StarIndentNum = DummyInt;
  200.  
  201. // Read the rotation angle rom the edit field and convert it to a double with unit [rad]. A conversion
  202. // made by TosoConvertStringAngle() automatically resolves any term or unit stated in that string. If
  203. // an error occurs, display a message and set the focus to the according edit field.
  204.  
  205.           GetDlgItemText( hDlg, IDD_EDIT1, DummyStr, NAME_LENGTH_EDIT );
  206.           if( !TosoConvertStringAngle( &DummyDouble, DummyStr, hDlg ) ) {
  207.             MessageBox( hDlg, eMessageText[2], eDialogText[0], MB_OK );
  208.  
  209.             Edit_SetSel( GetDlgItem( hDlg, IDD_EDIT1 ), 0, -1 );
  210.             SetFocus( GetDlgItem( hDlg, IDD_EDIT1 ) );    
  211.             return( TRUE );
  212.           }
  213.           gCopyHeader.StarRotation = DummyDouble;
  214.  
  215.           gExitDialog = IDD_OK;
  216.           SetFocus( hOldFocus );
  217.           EndDialog( hDlg, TRUE );
  218.           return( TRUE );
  219.  
  220.         case IDD_CANCEL:
  221.           gExitDialog = IDD_CANCEL;
  222.           SetFocus( hOldFocus );
  223.           EndDialog( hDlg, TRUE );
  224.           return( TRUE );
  225.       }
  226.       break;
  227.  
  228. // Help message detection and processing
  229.  
  230.     case WM_ENTERIDLE:
  231.       return( TosoDialogEnterIdle( hDlg, wParam, lParam ) );
  232.  
  233.     default:
  234.       if( message == TosoDialogHelpMessage() ) {
  235.         WinHelp( hDlg, "TSAMPLE.HLP", HELP_CONTEXT, gCommandID );
  236.         return( TRUE );
  237.       }
  238.       break;
  239.   }
  240.   return( FALSE );
  241. }
  242.  
  243. //------------------------------------------------------------------------------------------------------
  244. // This procedure displays and manages the parameter dialog for the command "Star" that this module
  245. // offers to the user.
  246.  
  247. BOOL DialogEditParameters( HWND hMainWnd, LPSTR Caption, int* IndentNum, double* Rotation )
  248. {
  249.   lstrcpy( gCaption, Caption );
  250.  
  251. // Copy the current settings to the temporary copy in order to be able to restore the values if
  252. // the user cancels the dialog.
  253.  
  254.   gCopyHeader.StarIndentNum = *IndentNum;
  255.   gCopyHeader.StarRotation  = *Rotation;
  256.  
  257. // Call and process the dialog window.
  258.  
  259.   if( DialogBox( hLanguage, "EDITPARAM", hMainWnd, DialogEditParametersManage ) == -1 ) {
  260.     MessageBox( hMainWnd, eMessageText[1], eDialogText[0], MB_OK );
  261.     return( FALSE );
  262.   }
  263.  
  264. // Check whether the user canceled the dialog or not. If he pressed OK, copy the new values to
  265. // the current settings.
  266.  
  267.   if( gExitDialog == IDD_CANCEL ) {
  268.     return( FALSE );
  269.   }
  270.   else {
  271.     *IndentNum = gCopyHeader.StarIndentNum;
  272.     *Rotation  = gCopyHeader.StarRotation;
  273.     return( TRUE );
  274.   }
  275. }
  276.  
  277. //------------------------------------------------------------------------------------------------------
  278. // This procedure is used to calculate the polygon corner points of a star based on the current values
  279. // of INFHeader.StarIndentNum and INFHeader.StarRotation.
  280.  
  281. int CommandCalculateStar( DPOINT* p1, DPOINT* p2, DPOINT* p3, DPOINT* Result )
  282. {
  283.   double        dx, dy, r1, r2, Angle1, Angle2, Step;
  284.   int           Count, Index;
  285.  
  286. // Calculation of the first radius (distance p1 - p2)
  287.  
  288.   dx = p2->x - p1->x;
  289.   dy = p2->y - p1->y;
  290.   r1 = sqrt( dx * dx + dy * dy );
  291.  
  292. // Calculation of the second radius (distance p1 - p3)
  293.  
  294.   dx = p3->x - p1->x;
  295.   dy = p3->y - p1->y;
  296.   r2 = sqrt( dx * dx + dy * dy );
  297.  
  298. // Step angle
  299.  
  300.   Step = REAL_2PI / INFHeader.StarIndentNum;
  301.  
  302. // Calculation of point pairs with an offset of 1/2 step
  303.  
  304.   Angle1 = INFHeader.StarRotation;
  305.   Angle2 = INFHeader.StarRotation + 0.5 * Step;
  306.  
  307.   Index = 0;
  308.   for( Count = 0; Count < INFHeader.StarIndentNum; Count++ ) {
  309.     Result[Index  ].x = p1->x + cos( Angle1 ) * r2;
  310.     Result[Index++].y = p1->y + sin( Angle1 ) * r2;
  311.     Result[Index  ].x = p1->x + cos( Angle2 ) * r1;
  312.     Result[Index++].y = p1->y + sin( Angle2 ) * r1;
  313.     Angle1 += Step;
  314.     Angle2 += Step;
  315.   }
  316.  
  317. // Number of calculated points
  318.  
  319.   return( Index );
  320. }
  321.  
  322. //------------------------------------------------------------------------------------------------------
  323. // This procedure creates an object of types "Surface" and fills it with required definition points to
  324. // build a star.
  325.  
  326. BOOL CommandFinishStar( void )
  327. {
  328.   int           Total, Count;
  329.   BOOL          Result = TRUE;
  330.  
  331. // Room to store the polygon point of the calculated star.
  332.  
  333.   DPOINT        Poly[STAR_INDENT_MAX*2];
  334.  
  335. // Fill the array Poly[] with a list of point coordinates
  336.  
  337.   Total = CommandCalculateStar( gPoint + 0, gPoint + 1, gPoint + 2, Poly );
  338.  
  339. // Open an object of "Surface"
  340.  
  341.   TosoObjectOpen( OBJ_SURFACE );
  342.  
  343. // Add the start-point of the polygon
  344.  
  345.   TosoObjectAddPoint( DB_POINT_START, Poly[0].x, Poly[0].y );
  346.  
  347. // Add all further points as end-point
  348.  
  349.   for( Count = 1; Count < Total; Count++ )
  350.     TosoObjectAddPoint( DB_POINT_END, Poly[Count].x, Poly[Count].y );
  351.  
  352. // Close the object, initialize its properties and insert it into the current drawing
  353.  
  354.   if( !TosoObjectFastInsert() )
  355.     Result = FALSE;
  356.  
  357.   return( Result );
  358. }
  359.  
  360. //------------------------------------------------------------------------------------------------------
  361. // This procedure is called by the serving application during the execution of the module-supplied
  362. // command "Star". It is called each time the entry of a new point is about to start.
  363.  
  364. int TosoInputPointInitProc( int CommandID, int PointIndex, double XPos, double YPos )
  365. {
  366.  
  367. // There is no need to initialize anything, so return immediately.
  368.  
  369.   return( INPUT_OK );
  370. }
  371.  
  372. //------------------------------------------------------------------------------------------------------
  373. // This procedure is called by the serving application during the execution of the module-supplied
  374. // command "Star". It is called at least once each time the user move the cursor.
  375.  
  376. BOOL TosoInputPointMoveProc( int CommandID, int PointIndex, double XPos, double YPos )
  377. {
  378.  
  379. // The only action required is to store the current point's coordinates. These coordinate will be used
  380. // to draw the "rubber lines" within the procedure TosoInputDisplayProc() and later on to create the
  381. // object within the procedure TosoInputFinishProc().
  382. // It will suffice if the coordinate are only stored at this one location since TosoInputPointMoveProc()
  383. // will at least be called once with the final coordinate of each point.
  384.  
  385.   gPoint[PointIndex].x = XPos;
  386.   gPoint[PointIndex].y = YPos;
  387.  
  388.   return( TRUE );
  389. }
  390.  
  391. //------------------------------------------------------------------------------------------------------
  392. // This procedure is called by the serving application during the execution of the module-supplied
  393. // command "Star". It is called each time the entry of a point is to be finished.
  394.  
  395. int TosoInputPointExitProc( int CommandID, int PointIndex, double XPos, double YPos )
  396. {
  397.  
  398. // There is no need to do anything, so return immediately. The final point coordinate that are passed
  399. // in XPos and YPos should have already been saved in the TosoInputPoitMoveProc(), so there is no need
  400. // to do it here again.
  401.  
  402.   return( INPUT_OK );
  403. }
  404.  
  405. //------------------------------------------------------------------------------------------------------
  406. // This procedure is called by the serving application during the execution of the module-supplied
  407. // command "Star". It is called each time the module has to update the "rubber lines" displaying the
  408. // current input status on the screen.
  409. // Since the given hDrawDC is using an reversing pen, both "display" and "hide" require the same
  410. // drawing operations.
  411.  
  412. void TosoInputDisplayProc( int CommandID, int PointIndex, HDC hDrawDC, BOOL DrawFixed, BOOL DrawVariable )
  413. {
  414.   int           Total, Count;
  415.  
  416. // Room to store the polygon point of the calculated star.
  417.  
  418.   DPOINT        Poly[STAR_INDENT_MAX*2];
  419.  
  420.   switch( CommandID ) {
  421.     case 1:                             // Star
  422.  
  423. // First step: draw all rubber lines that do not change due to mouse movement. Since the complete star
  424. // changes when the mouse position changes, this case is empty here.
  425.  
  426.       if( DrawVariable ) {
  427.  
  428.  
  429.       }
  430.  
  431. // Second step: draw all rubber lines that do change due to mouse movement. Since the complete star
  432. // changes when the mouse position changes, everything is drawn in this case.
  433.  
  434.       if( DrawVariable ) {
  435.  
  436. // Point index 0: No rubber lines visible during entry of first point (center).
  437.  
  438.         if( PointIndex == 0 ) {
  439.  
  440.         }
  441.  
  442. // Point index 1: Display a circle defined by point index 0 (center) and point index 1 (radius 1)
  443.  
  444.         if( PointIndex == 1 ) {
  445.           TosoInputDrawCircle( hDrawDC, gPoint[0].x, gPoint[0].y, gPoint[1].x, gPoint[1].y );
  446.         }
  447.  
  448. // Point index 2: Calculate and display a complete star based on point index 0 (center), point
  449. //                index 1 (radius 1) and point index 2 (radius 2).
  450.  
  451.         if( PointIndex == 2 ) {
  452.           Total = CommandCalculateStar( gPoint + 0, gPoint + 1, gPoint + 2, Poly );
  453.  
  454.           for( Count = 1; Count < Total; Count++ )
  455.             TosoInputDrawLine( hDrawDC, Poly[Count-1].x, Poly[Count-1].y, Poly[Count].x, Poly[Count].y );
  456.  
  457.           TosoInputDrawLine( hDrawDC, Poly[Total-1].x, Poly[Total-1].y, Poly[0].x, Poly[0].y );
  458.         }
  459.       }
  460.       break;
  461.   }
  462. }
  463.  
  464. //------------------------------------------------------------------------------------------------------
  465. // This procedure is called by the serving application during the execution of the module-supplied
  466. // command "Star". It is called each time the user wants to edit the parameters of the currently active
  467. // command.
  468.  
  469. BOOL TosoInputParameterProc( int CommandID )
  470. {
  471.   gCommandID = CommandID;
  472.  
  473.   switch( CommandID ) {
  474.     case 1:                             // Star
  475.  
  476. // Display the parameter dialog window. If the parameters are changed (i.e. if DialogEditParameters()
  477. // return TRUE, do also return TRUE to indicate the serving application that parameters of the
  478. // currently active command have changed, i.e. this command should be re-initialised.
  479.  
  480.       return( DialogEditParameters( hGlobalWnd, eCommandName[0], &INFHeader.StarIndentNum, &INFHeader.StarRotation ) );
  481.   }
  482. }
  483.  
  484. //------------------------------------------------------------------------------------------------------
  485. // This procedure is called by the serving application during the execution of the module-supplied
  486. // command "Star". It is called each time the user explicity canceles the currently active command
  487. // by pressing the right mouse button. If the current command were a command that requires a non-fixed
  488. // number of point entries, this is the place to terminate the command by returning INPUT_FINISH. If
  489. // the current allowed parameters to be editing DURING its execution (like the serving application's
  490. // DRAW > CURVE command), this is the right place to display a corresponding dialog window.
  491.  
  492. int TosoInputCancelProc( int CommandID, int PointCount )
  493. {
  494.   return( INPUT_CANCEL );
  495. }
  496.  
  497. //------------------------------------------------------------------------------------------------------
  498. // This procedure is called by the serving application during the execution of the module-supplied
  499. // command "Star". It is called each time the user has successfully enteres all required points, i.e.
  500. // the command is finished and the resulting actions are to be performed.
  501.  
  502. void TosoInputFinishProc( int CommandID, int PointCount )
  503. {
  504.   BOOL          Result = TRUE;
  505.  
  506. // Tell the interface that some objects are to be created.
  507.  
  508.   if( !TosoCreationStart() )
  509.     return;
  510.  
  511. // Start a new undo level. All objects created since now can either now be inserted to the drawing by
  512. // calling TosoUndoFinishProcess() or can be deleted by calling TosoUndoCancelProcess().
  513.  
  514.   TosoUndoInitProcess();
  515.  
  516. // Execute the command, i.e. calculate the resulting polygon and create an object of type "Surface"
  517. // based on that calculation.
  518.  
  519.   switch( CommandID ) {
  520.     case 1:                             // Star
  521.       Result = CommandFinishStar();
  522.       break;
  523.   }
  524.  
  525. // If creation was successful, end the newly created undo level (which inserts all objects to the
  526. // current drawing) and draw all newly created objects. Else, delete all newly created objects by
  527. // canceling the undo level.
  528.   
  529.   if( Result ) {
  530.     TosoUndoFinishProcess();
  531.     TosoDrawNewObjects();
  532.   }
  533.   else
  534.     TosoUndoCancelProcess();
  535.  
  536. // Tell the interface that the object creation was ended.
  537.  
  538.   TosoCreationEnd();
  539. }
  540.  
  541. //------------------------------------------------------------------------------------------------------
  542. // This DLL entry procedure must exist in any DLL to be used in Win32. Since our DLL does all necessary
  543. // initialization in its TosoModuleInit() procedure, this procedure is quite empty.
  544.  
  545. BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD Reason, LPVOID Dummy )
  546. {
  547.   switch( Reason ) {
  548.     case DLL_PROCESS_ATTACH:
  549.       hInstDLL = hInstance;
  550.       break;
  551.  
  552.     case DLL_PROCESS_DETACH:
  553.       hInstDLL = NULL;
  554.       break;
  555.   }
  556.   return( TRUE );
  557. }
  558.  
  559. //------------------------------------------------------------------------------------------------------
  560. // This procedure is called when the module is loaded by the serving application. Its main tasks are:
  561. // - Checking whether it is compatible with the given InterfaceVersion
  562. // - Checking whether it is licensed to the given serial number (optional)
  563. // - Storing of the serving application's instance and main windows handle for further use
  564. // - Loading of the language-dependent library
  565. // - Filling in the module ID structure whose address is passed in ModuleID
  566. // - Loading of options from the registry database
  567. // - Loading profiles
  568. // - Allocating any static memory required
  569.  
  570. DLL_EXPORT BOOL TosoModuleInit( const LPSTR SerialNumber, HINSTANCE hMainInst, HWND hMainWnd,
  571.                                                           int InterfaceVersion, MODULE_ID* ModuleID )
  572. {
  573.   int           Count;
  574.  
  575.   if( InterfaceVersion < TOSO_INTERFACE_VERSION ) {
  576.     MessageBox( hMainWnd, eMessageText[0], eDialogText[0], MB_OK );
  577.     return( FALSE );
  578.   }
  579.   hGlobalInst = hMainInst;
  580.   hGlobalWnd  = hMainWnd;
  581.  
  582. // Load the command icon bitmap from the language DLL.
  583.  
  584.   hLanguage = LoadLibrary( "TSAMPLE.DLL" );
  585.   hBitmap = LoadBitmap( hLanguage, "IDB_COMMAND" );
  586.  
  587. // Fill the module information data block
  588.  
  589.   ModuleID->OwnerID    = DB_OWNER_TOSO;
  590.   ModuleID->ModuleID   = 0x0000;
  591.   ModuleID->ModuleCTRL = MODULECTRL_ALL;
  592.  
  593.   ModuleID->ModuleProc.InputPointInitProc = (TOSOINPUTPOINTINIT_PROC) TosoInputPointInitProc;
  594.   ModuleID->ModuleProc.InputPointMoveProc = (TOSOINPUTPOINTMOVE_PROC) TosoInputPointMoveProc;
  595.   ModuleID->ModuleProc.InputPointExitProc = (TOSOINPUTPOINTEXIT_PROC) TosoInputPointExitProc;
  596.   ModuleID->ModuleProc.InputDisplayProc   = (TOSOINPUTDISPLAY_PROC)   TosoInputDisplayProc;
  597.   ModuleID->ModuleProc.InputParameterProc = (TOSOINPUTPARAMETER_PROC) TosoInputParameterProc;
  598.   ModuleID->ModuleProc.InputCancelProc    = (TOSOINPUTCANCEL_PROC)    TosoInputCancelProc;
  599.   ModuleID->ModuleProc.InputFinishProc    = (TOSOINPUTFINISH_PROC)    TosoInputFinishProc;
  600.  
  601.   ModuleID->ModuleData.Type = MODULETYPE_DRAW;
  602.  
  603.   ModuleID->ModuleData.InputData.CommandMode = COMMAND_DIRECT;
  604.   ModuleID->ModuleData.MenuData.MenuEntry   = eStartUpText[1];
  605.   ModuleID->ModuleData.MenuData.Description = eStartUpText[2];
  606.  
  607.   ModuleID->ModuleData.IconHandle  = hBitmap;
  608.   ModuleID->ModuleData.IconXOffset = 0;
  609.   ModuleID->ModuleData.IconYOffset = 0;
  610.   ModuleID->ModuleData.IconMode    = 0;
  611.  
  612.   ModuleID->CommandData = CommandData;
  613.  
  614. // Fill in the commands' names and the accompanying information.
  615.  
  616.   Count = 0;
  617.   while( eCommandEntry[Count] == NULL || eCommandEntry[Count][0] != END_CHAR ) {
  618.     CommandData[Count].InputData.CommandMode = COMMAND_DIRECT;
  619.     CommandData[Count].MenuData.MenuEntry   = eCommandEntry[Count];
  620.     CommandData[Count].MenuData.Description = eCommandName [Count];
  621.  
  622.     CommandData[Count].IconHandle  = hBitmap;
  623.     CommandData[Count].IconXOffset = 0;
  624.     CommandData[Count].IconYOffset = ( Count + 1 ) * 48;
  625.     CommandData[Count].IconMode    = 0;
  626.  
  627.     if( eCommandEntry[Count] )
  628.       CommandData[Count].Type = IDM_ENTRY;
  629.     else
  630.       CommandData[Count].Type = IDM_ENTRY | IDM_SEPARATOR;
  631.  
  632.     Count++;
  633.   }
  634.   CommandData[Count].Type = IDM_END;
  635.  
  636. // Fill the command description structure with the predefined global structure gInfo.
  637.  
  638.   CommandData[0].InputData = gInfo[0];
  639.   CommandData[0].InputData.PointNames[1] = eNewPoint[0];
  640.   CommandData[0].InputData.PointNames[2] = eNewPoint[1];
  641.  
  642. // Read the current settings (set to their default values if not found)
  643.  
  644.   ModuleLoadSettings();
  645.  
  646.   return( TRUE );
  647. }
  648.  
  649. //------------------------------------------------------------------------------------------------------
  650. // This procedure is called when the module is removed by the serving application. Its main tasks are:
  651. // - Checking whether anything is to be saved. If so, it should display a message information the user
  652. //   about it and allowing him to save those changes.
  653. // - Freeing of all statically allocated memory.
  654. // If this procedure return FALSE, the serving application will not be able to terminate. So please, do
  655. // only return FALSE if shutting down the module now would severely damage or destroy user data.
  656.  
  657. DLL_EXPORT BOOL TosoModuleExit( void )
  658. {
  659.   ModuleSaveSettings();
  660.  
  661.   DeleteBitmap( hBitmap );
  662.  
  663.   return( TRUE );
  664. }
  665.  
  666. //------------------------------------------------------------------------------------------------------
  667. // This procedure is called when a module's command is chosen by the user. For a command module, its
  668. // main tasks are:
  669. // - If requested, display the help topic for the given command
  670. // - Execute the chosen command (if it is a "direct" command that does not require point entry)
  671. // - Register an external command (if it is a "indirect" command that does require point entry)
  672. // - Error handling and display
  673.  
  674. DLL_EXPORT BOOL TosoModuleCommand( int CommandID, int ExecMode )
  675. {
  676.   BOOL          Result = FALSE;
  677.  
  678. // Check whether a help topic is to be displayed instead of starting a command.
  679.  
  680.   if( ExecMode == MODULEEXEC_HELP ) {
  681.     switch( CommandID ) {
  682.       case 1:
  683.       case 3:
  684.         WinHelp( hGlobalWnd, "TSAMPLE.HLP", HELP_CONTEXT, CommandID );
  685.         break;
  686.     }
  687.     return( FALSE );
  688.   }
  689.  
  690. // Execute the command chosen by the user.
  691.  
  692.   switch( CommandID ) {
  693.     case 1:
  694.       Result = TRUE;
  695.  
  696. // If the user has first selected the command from the menu, allow him to edit the parameters first.
  697. // If the command does only use seldomly-modified parameters, this is NOT necessary.
  698.  
  699.       if( ExecMode == MODULEEXEC_USER ) {
  700.         gCommandID = CommandID;
  701.         if( !DialogEditParameters( hGlobalWnd, eCommandName[0], &INFHeader.StarIndentNum, &INFHeader.StarRotation ) )
  702.           Result = FALSE;
  703.       }
  704.       break;
  705.  
  706.     case 3:
  707.       MessageBox( hGlobalWnd, eStartUpText[0], eDialogText[0], MB_OK );
  708.       Result = TRUE;
  709.       break;
  710.  
  711.     default:
  712.       Result = FALSE;
  713.       break;
  714.   }
  715.   return( Result );
  716. }
  717.