home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / hpp.z / WWINMAIN.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-19  |  3.6 KB  |  102 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. #ifndef _WWINMAIN_HPP_INCLUDED
  12. #define _WWINMAIN_HPP_INCLUDED
  13.  
  14. #ifndef _WNO_PRAGMA_PUSH
  15. #pragma pack(push,4);
  16. #pragma enum int;
  17. #endif
  18.  
  19. #include <stdlib.h>
  20.  
  21. #ifndef _WDEF_HPP_INCLUDED
  22. #  include "wdef.hpp"
  23. #endif
  24. #ifndef _WSTRING_HPP_INCLUDED
  25. #  include "wstring.hpp"
  26. #endif
  27. #ifndef _WAPPLIC_HPP_INCLUDED
  28. #  include "wapplic.hpp"
  29. #endif
  30. #ifndef _WMEMORY_HPP_INCLUDED
  31. #  include "wmemory.hpp"
  32. #endif
  33.  
  34. #ifndef CALLBACK
  35. #if defined( __NT__ )
  36. #define CALLBACK __stdcall
  37. #else
  38. #define CALLBACK __far __pascal
  39. #endif
  40. #endif
  41.  
  42. #define MAINOBJECT( __main_class ) \
  43.     class MyApplicationClass : public WApplication { \
  44.         public:\
  45.             __main_class *_mainForm; \
  46.                                      \
  47.             MyApplicationClass() : _mainForm( NULL ) { \
  48.                 SetEventHandler( WStartEvent, this, \
  49.                       (WEventHandler)&MyApplicationClass::StartHandler );\
  50.                 SetEventHandler( WRunEvent, this, \
  51.                       (WEventHandler)&MyApplicationClass::RunHandler );\
  52.                 SetEventHandler( WEndEvent, this, \
  53.                       (WEventHandler)&MyApplicationClass::EndHandler );\
  54.             }\
  55.             \
  56.             ~MyApplicationClass() {} \
  57.                                      \
  58.             WBool StartHandler( WObject *, WStartEventData *event ) { \
  59.                 _mainForm = new __main_class;\
  60.                 if( !_mainForm || !_mainForm->Initialize() ){\
  61.                     event->abortRun = TRUE;\
  62.                     event->exitCode = -1;\
  63.                 }\
  64.                 return TRUE;\
  65.             }\
  66.             \
  67.             WBool RunHandler( WObject *, WRunEventData * ) { \
  68.                 WCurrentThread::ProcessMessages();\
  69.                 return TRUE;\
  70.             }\
  71.             WBool EndHandler( WObject *, WEndEventData * ) { \
  72.                 delete _mainForm;\
  73.                 _mainForm = NULL;\
  74.                 return TRUE;\
  75.             }\
  76.     }; MAINOBJECT_CUSTOM( MyApplicationClass, __main_class )
  77.  
  78.  
  79. #define MAINOBJECT_CUSTOM( __app_class, __main_class )      \
  80.                                                             \
  81.     W_REDEFINENEW                       \
  82.     W_REDEFINEDELETE                    \
  83.                                                             \
  84.     static __app_class _WAppObject;                         \
  85.                                                             \
  86.     int CALLBACK WinMain( unsigned int inst, unsigned int prev,       \
  87.                           const WChar * cmd, int show )               \
  88.     {                                                                 \
  89.         if( _WAppObject.Initialize( inst, prev, cmd, show ) ){   \
  90.             _WAppObject.Run();                \
  91.         }                                     \
  92.                                               \
  93.         return _WAppObject.Uninitialize(); \
  94.     }
  95.  
  96. #ifndef _WNO_PRAGMA_PUSH
  97. #pragma enum pop;
  98. #pragma pack(pop);
  99. #endif
  100.  
  101. #endif // _WWINMAIN_HPP_INCLUDED
  102.