home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL1.ZIP / OWLINC.ZIP / APPLICAT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  4.7 KB  |  120 lines

  1. // ObjectWindows - (C) Copyright 1991 by Borland International
  2.  
  3. #ifndef __APPLICAT_H
  4. #define __APPLICAT_H
  5.  
  6. #ifndef __MODULE_H
  7. #include <module.h>
  8. #endif
  9.  
  10. // Application Class 
  11.  
  12. _CLASSDEF(TApplication)
  13.  
  14. class _EXPORT TApplication : public TModule {
  15. public:
  16.  
  17.     // WinMain arguments
  18.     HANDLE         hPrevInstance;
  19.     int            nCmdShow;
  20.  
  21.     PTWindowsObject MainWindow;
  22.     HANDLE HAccTable;
  23.     PTWindowsObject KBHandlerWnd;
  24.  
  25.     TApplication(LPSTR AName, HANDLE AnInstance,
  26.               HANDLE APrevInstance, LPSTR ACmdLine, int ACmdShow);
  27.     ~TApplication();
  28.     virtual void Run();
  29.     virtual BOOL CanClose();
  30.     void SetKBHandler(PTWindowsObject AWindowsObject);
  31.  
  32.     // define pure virtual functions derived from Object class
  33.     virtual classType        isA() const
  34.          { return applicationClass; }
  35.     virtual Pchar nameOf() const
  36.          {return "TApplication";}
  37. protected:
  38.     virtual void InitApplication();  // "first"-instance initialization
  39.     virtual void InitInstance();     // each-instance initialization
  40.     virtual void InitMainWindow();   // init application main window 
  41.  
  42.     virtual void MessageLoop();
  43.     /* IdleAction may be redefined in derived classes to do some action when 
  44.        there are no messages pending. */
  45.     virtual void IdleAction() {} 
  46.     virtual BOOL ProcessAppMsg(LPMSG PMessage);
  47.     virtual BOOL ProcessDlgMsg(LPMSG PMessage);
  48.     virtual BOOL ProcessAccels(LPMSG PMessage);
  49.     virtual BOOL ProcessMDIAccels(LPMSG PMessage);
  50. };    // end of Application class  
  51.  
  52. /* Performs special handling for the message last retrieved.  
  53.    Translates keyboard input messages into control selections or 
  54.    command messages, when appropriate.  Dispatches message, if 
  55.    translated. */
  56. inline BOOL TApplication::ProcessAppMsg(LPMSG PMessage)
  57.        { if ( KBHandlerWnd )
  58.            if ( KBHandlerWnd->IsFlagSet(WB_MDICHILD) )
  59.              return ProcessMDIAccels(PMessage) ||
  60.                     ProcessDlgMsg(PMessage) ||
  61.                     ProcessAccels(PMessage);
  62.            else
  63.             return ProcessDlgMsg(PMessage) ||
  64.                    ProcessMDIAccels(PMessage) ||
  65.                    ProcessAccels(PMessage);
  66.          else
  67.            return ProcessMDIAccels(PMessage) ||
  68.                   ProcessAccels(PMessage); }
  69.  
  70. /* Attempts to translate a message into a control selection if the 
  71.    currently active OWL window has requested "keyboard handling".  
  72.    (Some keyboard input messages are translated into control 
  73.    selection messages). Dispatches message, if translated. */
  74. inline BOOL TApplication::ProcessDlgMsg(LPMSG PMessage)
  75.     { if (KBHandlerWnd && KBHandlerWnd->HWindow)
  76.            return IsDialogMessage(KBHandlerWnd->HWindow, PMessage);
  77.          else
  78.            return FALSE; }
  79.  
  80. /* Attempts to translate a message into a command message if the 
  81.    TApplication has loaded an accelerator table. (Keyboard input 
  82.    messages for which an entry exists in the accelerator table are 
  83.    translated into command messages.)  Dispatches message, if 
  84.    translated.  (Translation of MDI accelerator messages is performed 
  85.    in ProcessMDIAccels function.) */
  86. inline BOOL TApplication::ProcessAccels(LPMSG PMessage)
  87.        { return HAccTable && 
  88.          TranslateAccelerator(
  89.                  MainWindow->HWindow, HAccTable, PMessage); }
  90.  
  91. /* Attempts to translate a message into a system command message 
  92.    for MDI TApplications (whose main window is a TMDIFrame). (Some 
  93.    keyboard input messages are translated into system commands for 
  94.    MDI applications). Dispatches message, if translated. */
  95. inline BOOL TApplication::ProcessMDIAccels(LPMSG PMessage)
  96.        { return (PTWindowsObject)(MainWindow->GetClient()) &&
  97.            TranslateMDISysAccel(
  98.             ((PTWindowsObject)(MainWindow->GetClient()))->HWindow, PMessage); }
  99.  
  100. /* Activates and deactivates "keyboard handling" (translation of 
  101.    keyboard input into control selections) for the currently active 
  102.    TWindowsObject by setting the KBHandlerWnd to the parameter passed. 
  103.    This function is called internally by the OWL whenever a OWL window 
  104.    is activated.  If "keyboard handling" has been requested for the 
  105.    TWindowsObject, the parameter passed is non-NULL, else NULL is 
  106.    passed.  "Keyboard handling" is requested, by default, for all 
  107.    modeless dialogs and may be requested for a TWindow via a call to 
  108.    its EnableKBHandler function. */
  109. inline void TApplication::SetKBHandler(PTWindowsObject AWindowsObject)
  110.        { KBHandlerWnd = AWindowsObject; }
  111.  
  112. // WinMain Prototype
  113. extern "C" {
  114. int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
  115. }
  116.  
  117. extern PTApplication _EXPFUNC GetApplicationObject();
  118.  
  119. #endif // ifndef _APPLICAT_H
  120.