home *** CD-ROM | disk | FTP | other *** search
/ Aztec Masterblend / aztecmasterblendazteknewmediaj / lc / source.txt < prev   
Text File  |  1992-11-04  |  19KB  |  425 lines

  1. ----------------------------------------------------------------
  2. ----------------------------------------------------------------
  3. ----------------------------------------------------------------
  4. ----------------------------------------------------------------
  5. ----------------------------------------------------------------
  6. This text file contains four source files.  Use your editor to
  7. cut this file into these:
  8.  
  9.           lc_samp.c
  10.           lc_samp.h
  11.           lc_samp.mak
  12.           lc_samp.rc
  13.     
  14. ----------------------------------------------------------------
  15. ----------------------------------------------------------------
  16. ----------------------------------------------------------------
  17. ----------------------------------------------------------------
  18. ----------------------------------------------------------------
  19. ------------------  HERE BEGINS THE LC_SAMP.C FILE -------------
  20. /*  
  21.     Sample Non-DDE client program for LC.EXE
  22.     Garry J. Vass [72307,3311]
  23.     
  24.     This program (cloned from generic.c) uses the LC.EXE
  25.     Winapp to perform calculations on strings containing
  26.     expressions of the form:
  27.     
  28.          3+4+5+6
  29.          3*4
  30.          3/sin(3)*log(2)
  31.          and so on.
  32.          
  33.     For locating code that is specific to this application
  34.     (i.e., not generic), set your Search function for "COMMENT".
  35.     
  36.     Why not DDE?  
  37.     
  38.         1.  This particular client-server relationship
  39.             is straightforward, well structured, 
  40.             predictable, and requires expedience.
  41.         2.  About 12 lines of code for this versus
  42.             300+ lines to implement DDE.
  43.         3.  The downside is that the messages WM_USER+63
  44.             (request), and WM_USER+64 (reply) are
  45.             looked upon as private channels.  This is
  46.             conceptually similar to the old-world situation
  47.             where DOS resident programs argued over who
  48.             owned what hotkey (sigh).  I use a recognition
  49.             signature 0x4C43, 'L'<<4 + 'C', in the message
  50.             to establish ownership.
  51.  
  52.  
  53.                                                               */    
  54. /**************************************************************/
  55. /*                                                            */
  56. /*                                                            */
  57. /*                                                            */
  58. /*                                                            */
  59. /*                                                            */
  60. /**************************************************************/
  61. #include "windows.h"
  62. #include "lc_samp.h"
  63. int request_calculation( HWND sender, char *str );
  64. /**************************************************************/
  65. /*                                                            */
  66. /*                                                            */
  67. /*                                                            */
  68. /*                                                            */
  69. /*                                                            */
  70. /**************************************************************/
  71. HANDLE hInst;
  72. FARPROC Lproc;
  73. char Inputstring[ 255 ] = "2+2";
  74. char Resultstring[ 255 ] = "Result: 4";
  75. char Anystring[ 255 ];
  76. #define WAK( a ) MessageBox(  GetFocus(  ), a, "WIN-ACK", MB_OK  );
  77. /**************************************************************/
  78. /*                                                            */
  79. /*                                                            */
  80. /*                                                            */
  81. /*                                                            */
  82. /*                                                            */
  83. /**************************************************************/
  84. /*  COMMENT:
  85.     This variable is used to specify the handle (HWND) of
  86.     the LC application.
  87. */
  88. static HWND Lchwnd = -1;
  89. /**************************************************************/
  90. /*                                                            */
  91. /*                                                            */
  92. /*                                                            */
  93. /*                                                            */
  94. /*                                                            */
  95. /**************************************************************/
  96. int PASCAL WinMain( HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  97. {
  98. MSG msg;
  99.     if( !hPrevInstance ) {
  100.         if( !InitApplication( hInstance ) )
  101.             return( FALSE );
  102.         /*  COMMENT:
  103.             This code starts the LC application.  If Windows
  104.             cannot start the program, she returns a value
  105.             less than 32.  
  106.         */
  107.         if( WinExec( "LC", SW_SHOWMINNOACTIVE ) < 32 ) {
  108.             MessageBox( GetFocus(), 
  109.                         (LPSTR)"I cannot find my server",
  110.                         (LPSTR)"ShowStopper", 
  111.                         MB_OK );
  112.             return( FALSE );
  113.         }
  114.     }
  115.     if( !InitInstance( hInstance, nCmdShow ) )
  116.         return( FALSE );
  117.     while( GetMessage( &msg, NULL, NULL, NULL ) ) {
  118.            TranslateMessage( &msg );
  119.            DispatchMessage( &msg );
  120.     }
  121.     return( msg.wParam );
  122. }
  123. /**************************************************************/
  124. /*                                                            */
  125. /*                                                            */
  126. /*                                                            */
  127. /*                                                            */
  128. /*                                                            */
  129. /**************************************************************/
  130. BOOL InitApplication( HANDLE hInstance )
  131. {
  132. WNDCLASS wc;
  133.      wc.style              = NULL;
  134.      wc.lpfnWndProc        = MainWndProc;
  135.      wc.cbClsExtra         = 0;
  136.      wc.cbWndExtra         = 0;
  137.      wc.hInstance          = hInstance;
  138.      wc.hIcon              = LoadIcon( NULL, IDI_APPLICATION );
  139.      wc.hCursor            = LoadCursor( NULL, IDC_ARROW );
  140.      wc.hbrBackground      = GetStockObject( WHITE_BRUSH );
  141.      wc.lpszMenuName       = "lcmenu";
  142.      wc.lpszClassName      = "lcclass";
  143.      return( RegisterClass( &wc ) );
  144. }
  145. /**************************************************************/
  146. /*                                                            */
  147. /*                                                            */
  148. /*                                                            */
  149. /*                                                            */
  150. /*                                                            */
  151. /**************************************************************/
  152. BOOL InitInstance( HANDLE hInstance, int nCmdShow )
  153. {
  154. HWND hWnd;
  155.      hInst = hInstance;
  156.      hWnd = CreateWindow( "lcclass",
  157.                           "LC Sample",
  158.                           WS_OVERLAPPEDWINDOW,
  159.                           CW_USEDEFAULT,
  160.                           CW_USEDEFAULT,
  161.                           CW_USEDEFAULT,
  162.                           CW_USEDEFAULT,
  163.                           NULL,
  164.                           NULL,
  165.                           hInstance,
  166.                           NULL );
  167.      if( !hWnd )
  168.          return( FALSE );
  169.      ShowWindow( hWnd, nCmdShow );
  170.      UpdateWindow( hWnd );
  171.      return( TRUE );
  172. }
  173. /**************************************************************/
  174. /*                                                            */
  175. /*                                                            */
  176. /*                                                            */
  177. /*                                                            */
  178. /*                                                            */
  179. /**************************************************************/
  180. long FAR PASCAL MainWndProc( HWND hWnd, unsigned message, WORD wParam, LONG lParam )
  181. {
  182.     switch( message ) {
  183.             case WM_COMMAND:
  184.                  if( wParam == IDM_ABOUT ) {
  185.                      Lproc = MakeProcInstance(