home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WWINMAIN.HPP < prev    next >
C/C++ Source or Header  |  1996-10-18  |  5KB  |  94 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,8);
  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. #define MAINOBJECT( __main_class )                              \
  35.     class MyApplicationClass : public WApplication {            \
  36.         public:                                                 \
  37.             __main_class *_mainForm;                            \
  38.                                                                 \
  39.             MyApplicationClass() : _mainForm( NULL ) {          \
  40.                 SetEventHandler( WStartEvent, this,             \
  41.                       (WEventHandler)&MyApplicationClass::StartHandler );\
  42.                 SetEventHandler( WRunEvent, this,               \
  43.                       (WEventHandler)&MyApplicationClass::RunHandler );\
  44.                 SetEventHandler( WEndEvent, this,               \
  45.                       (WEventHandler)&MyApplicationClass::EndHandler );\
  46.             }                                                   \
  47.                                                                 \
  48.             ~MyApplicationClass() {}                            \
  49.                                                                 \
  50.             WBool StartHandler( WObject *, WStartEventData *event ) { \
  51.                 _mainForm = new __main_class;                   \
  52.                 if( !_mainForm || !_mainForm->Initialize() ){   \
  53.                     event->abortRun = TRUE;                     \
  54.                     event->exitCode = -1;                       \
  55.                 }                                               \
  56.                 return TRUE;                                    \
  57.             }                                                   \
  58.                                                                 \
  59.             WBool RunHandler( WObject *, WRunEventData * ) {    \
  60.                 WCurrentThread::ProcessMessages();              \
  61.                 return TRUE;                                    \
  62.             }                                                   \
  63.             WBool EndHandler( WObject *, WEndEventData * ) {    \
  64.                 delete _mainForm;                               \
  65.                 _mainForm = NULL;                               \
  66.                 return TRUE;                                    \
  67.             }                                                   \
  68.     }; MAINOBJECT_CUSTOM( MyApplicationClass, __main_class )
  69.  
  70.  
  71. #define MAINOBJECT_CUSTOM( __app_class, __main_class )          \
  72.                                                                 \
  73.     W_REDEFINENEW                                               \
  74.     W_REDEFINEDELETE                                            \
  75.                                                                 \
  76.     static __app_class _WAppObject;                             \
  77.                                                                 \
  78.     int WINAPI WinMain( HINSTANCE inst, HINSTANCE prev,         \
  79.                           WAnsiChar * cmd, int show )           \
  80.     {                                                           \
  81.         if( _WAppObject.Initialize( inst, prev, cmd, show ) ){  \
  82.             _WAppObject.Run();                                  \
  83.         }                                                       \
  84.                                                                 \
  85.         return _WAppObject.Uninitialize();                      \
  86.     }
  87.  
  88. #ifndef _WNO_PRAGMA_PUSH
  89. #pragma enum pop;
  90. #pragma pack(pop);
  91. #endif
  92.  
  93. #endif // _WWINMAIN_HPP_INCLUDED
  94.