home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / ADS / CPP / HELLOADS / HELLOADS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  6.8 KB  |  249 lines

  1. /* 
  2.     HELLOADS.CPP -
  3.     
  4.     This file:
  5.  
  6.         A very simple ADS Windows application.
  7.  
  8.         From ACAD command window:
  9.  
  10.         ( xload "helloads" ) to bring up the application and it's
  11.         window.
  12.  
  13.         Command:
  14.  
  15.         (HELLOADS "message") Change application's main window text.
  16.  
  17.     (C) Copyright 1988-1994 by Autodesk, Inc.
  18.  
  19.     This program is copyrighted by Autodesk, Inc. and is  licensed
  20.     to you under the following conditions.  You may not distribute
  21.     or  publish the source code of this program in any form.   You
  22.     may  incorporate this code in object form in derivative  works
  23.     provided  such  derivative  works  are  (i.) are  designed and
  24.     intended  to  work  solely  with  Autodesk, Inc. products, and
  25.     (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright
  26.     1988-1994 by Autodesk, Inc."
  27.  
  28.     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  29.     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  30.     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  31.     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  32.     UNINTERRUPTED OR ERROR FREE.
  33.  
  34. */
  35. #include "HELLOADS.h"
  36.  
  37. //-----------------------------------------------------------------------------
  38. ADS_APP myapp;
  39.  
  40. //-----------------------------------------------------------------------------
  41. WIN_APP* CurApp()
  42. {
  43.     return ( WIN_APP* )&myapp;
  44. }
  45.  
  46. //-----------------------------------------------------------------------------
  47. HINSTANCE AppInstance()
  48. {
  49.     return myapp.main_hinst;
  50. }
  51.  
  52. //-----------------------------------------------------------------------------
  53. char* ModuleName()
  54. {
  55.     return APP_NAME;
  56. }
  57.  
  58. //-----------------------------------------------------------------------------
  59. LRESULT CALLBACK WndProc( HWND hWnd
  60.                         , UINT iMessage
  61.                         , WPARAM wParam
  62.                         , LPARAM lParam );
  63.  
  64. /******************************************************************************
  65. *                                                                             *
  66. *                                 WIN_APP                                     *
  67. *                                                                             *
  68. ******************************************************************************/
  69. //-----------------------------------------------------------------------------
  70. WIN_APP::WIN_APP()
  71. {
  72.     main_wnd    = 0;
  73.     main_hinst  = 0;
  74.     prev_hinst  = 0;
  75. }
  76.  
  77. //-----------------------------------------------------------------------------
  78. void WIN_APP::ShowMainWindow()
  79. {
  80.     if ( main_wnd )
  81.     {
  82.         main_wnd->Show( ncmdshow );
  83.         main_wnd->Update();
  84.     }
  85. }
  86.  
  87. //-----------------------------------------------------------------------------
  88. BOOL WIN_APP::InitInstance( HINSTANCE hInst, HINSTANCE hprev )
  89. {
  90.     main_hinst = hInst;
  91.     prev_hinst = hprev;
  92.  
  93.     return TRUE;
  94. }
  95.  
  96. //-----------------------------------------------------------------------------
  97. BOOL WIN_APP::InitApplication( int nCmdShow, LPSTR _cmdline )
  98. {
  99.     cmdline = _cmdline;
  100.     ncmdshow = nCmdShow;
  101.  
  102.     return TRUE;
  103. }
  104.  
  105. //-----------------------------------------------------------------------------
  106. int WIN_APP::Run( void )
  107. {
  108.     while ( GetMessage( &msg, NULL, 0, 0 ) )
  109.     {
  110.         TranslateMessage( &msg );
  111.         DispatchMessage( &msg );
  112.     }
  113.     return msg.wParam;
  114. }
  115.  
  116. /******************************************************************************
  117. *                                                                             *
  118. *                                 ADS_APP                                     *
  119. *                                                                             *
  120. ******************************************************************************/
  121. //-----------------------------------------------------------------------------
  122. BOOL ADS_APP::InitApplication( int nCmdShow, LPSTR _cmdline )
  123. {
  124.     if ( WIN_APP::InitApplication( nCmdShow, _cmdline ) )
  125.     {
  126.  
  127.         if ( ads_winit( AppInstance(), ModuleName() ) == RTNORM ) 
  128.         {
  129.             main_wnd = new MAINWINDOW;
  130.             return TRUE;
  131.         }
  132.     }
  133.     return FALSE;
  134. }
  135.  
  136.  
  137. //-----------------------------------------------------------------------------
  138. int ADS_APP::Run( void )
  139. {
  140.     while ( TRUE )
  141.     {
  142.         if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  143.         {
  144.             if ( msg.message == WM_QUIT )
  145.             {
  146.                 break;
  147.             }
  148.             TranslateMessage ( &msg );
  149.             DispatchMessage ( &msg );
  150.         }
  151.         else
  152.         {
  153.             if ( !AdsLoop() )
  154.             {
  155.                 return -1;
  156.             }
  157.         }
  158.     }
  159.     return msg.wParam;
  160. }
  161.  
  162.  
  163. //-----------------------------------------------------------------------------
  164. BOOL ADS_APP::AdsLoop()
  165. {
  166.  
  167.     if ( ( ads_stat = ads_link( scode ) ) < 0 ) 
  168.     {
  169.         char errmsg[80];
  170.         sprintf( errmsg
  171.                 , "%s: bad ads_status from ads_link() = %d"
  172.                 , ModuleName()
  173.                 , ads_stat );
  174.         ::MessageBox( NULL, errmsg, "ADS Error", MB_OK );
  175.         return FALSE;
  176.     }
  177.  
  178.     scode = RSRSLT;
  179.  
  180.     switch ( ads_stat ) 
  181.     {
  182.         case RQXLOAD:
  183.         {
  184.             if ( !ads_defun( ModuleName(), 1 ) )    /* command has id 1 */
  185.             {
  186.                 scode = -RSERR;
  187.             }
  188.             else 
  189.             {
  190.                 ads_printf( "%s \"string to show\" command invokes trivial test.\n", ModuleName() );
  191.                 scode = -RSRSLT;
  192.             }
  193.             break;
  194.         }
  195.  
  196.         case RQHUP:
  197.         {
  198.             return FALSE;
  199.         }
  200.  
  201.         case RQSUBR:
  202.         {
  203.             switch ( ads_getfuncode() ) 
  204.             {
  205.                 case 1:
  206.                 {
  207.                     struct resbuf *rp;
  208.                     rp = ads_getargs();
  209.                     if ( rp->restype == RTSTR )
  210.                     {
  211.                         ( ( MAINWINDOW* )main_wnd )->SetText( ADS_STRING( rp->resval.rstring ) );
  212.                         main_wnd->Update();
  213.                     }
  214.                     break;
  215.                 }
  216.                 default:
  217.                 {
  218.                     break;
  219.                 }
  220.             }
  221.             break;
  222.         }
  223.  
  224.         default:
  225.         {
  226.             break;
  227.         }
  228.     }
  229.  
  230.     return TRUE;
  231. }
  232.  
  233. //-----------------------------------------------------------------------------
  234. int PASCAL WinMain( HINSTANCE hInstance
  235.                     , HINSTANCE hPrevInstance
  236.                     , LPSTR lpszCmdLine
  237.                     , int nCmdShow )
  238. {
  239.     if ( CurApp()->InitInstance( hInstance, hPrevInstance ) )
  240.     {
  241.         if ( CurApp()->InitApplication( nCmdShow, lpszCmdLine ) )
  242.         {
  243.             CurApp()->ShowMainWindow();
  244.             return CurApp()->Run();
  245.         }
  246.     }
  247.     return -1;
  248. }
  249.