home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Extras / Sensaura / SDK1.0 / data1.cab / Example_Files / ZoomFX / applicat.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-13  |  3.0 KB  |  135 lines

  1. /*
  2.     Company:            Sensaura Ltd
  3.     Copyright:          (C) 2000
  4.  
  5.     File Name:            applicat.cpp
  6.     File Description:    Source file for implementation of Application class
  7.     Author:                Adam Philp
  8.     Last Update:        04-JAN-00
  9.  
  10.     Target Compiler:    Microsoft Visual C++ Version 5.0
  11. */
  12.  
  13. ///////////////////////    Included files ////////////////////////////////////////////////////////////
  14.  
  15. #include <windows.h>
  16.  
  17. #include "applicat.h"
  18. #include "resource.h"
  19. #include "debug.h"
  20.  
  21. /////////////////////// Application class implementation //////////////////////////////////////////
  22.  
  23. Application::Application(LPCSTR pName, HINSTANCE hInstance, HINSTANCE hPrevInstance, 
  24.                          LPSTR pCmdLine, int cmdshow)
  25. {
  26.     PTRACE("Application::Application(pName:%s, hInstance:%X, hPrevInstance:%X, pCmdLine:%s, cmdshow:%d)",
  27.         pName, hInstance, hPrevInstance, pCmdLine, cmdshow);
  28.  
  29.     m_hInstance = hInstance;
  30.     m_hPrevInstance = hPrevInstance;
  31.     m_pName = pName;
  32.     m_nCmdShow = cmdshow;
  33.     m_pMainWindow = NULL;
  34.     m_hAccelTable = NULL;
  35. }
  36.  
  37. Application::~Application()
  38. {
  39.     PTRACE("Application::~Application()");
  40. }
  41.  
  42. /////////////////////// Application public member functions ///////////////////////////////////////
  43.  
  44. int    Application::Run()
  45. {
  46.     int ret = 0;
  47.  
  48.     PTRACE("Application::Run()");
  49.  
  50.     if(!m_hPrevInstance)
  51.         if(!InitApplication())
  52.             ret = -1;
  53.     if(ret == 0)
  54.         if(!InitInstance())
  55.             ret = -2;
  56.     if(ret == 0)
  57.         ret = MessageLoop();
  58.  
  59.     PTRACE("Application::Run() returned %d", ret);
  60.  
  61.     return ret;
  62. }
  63.  
  64. /////////////////////// Application protected member functions ////////////////////////////////////
  65.  
  66. bool Application::InitApplication()
  67. {
  68.     PTRACE("Application::InitApplication() OK");
  69.     return TRUE;
  70. }
  71.  
  72. bool Application::InitInstance()
  73. {
  74.     PTRACE("Application::InitInstance()");
  75.  
  76.     m_pMainWindow = new MainWnd(m_pName, this);
  77.     if(m_pMainWindow == NULL)
  78.         return false;
  79.  
  80.     m_hAccelTable = LoadAccelerators(m_hInstance, MAKEINTRESOURCE(IDR_ACCELERATORS));
  81.     if(!m_pMainWindow->Create())
  82.     {
  83.         delete m_pMainWindow;
  84.         m_pMainWindow = NULL;
  85.         return false;
  86.     }
  87.  
  88.     m_pMainWindow->ShowWindow(m_nCmdShow);
  89.  
  90.     PTRACE("Application::InitInstance() OK");
  91.  
  92.     return true;
  93. }
  94.  
  95. int Application::MessageLoop()
  96. {
  97.     MSG        msg;
  98.     bool    bBreakLoop;
  99.     int        result;
  100.  
  101.     PTRACE("Application::MessageLoop()");
  102.  
  103.     bBreakLoop = false;
  104.     result = 0;
  105.     while(!bBreakLoop) 
  106.     {
  107.         while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
  108.         {
  109.             if(msg.message == WM_QUIT)    
  110.             {
  111.                 delete m_pMainWindow;
  112.                 m_pMainWindow = NULL;
  113.                 bBreakLoop = true;
  114.                 break;
  115.             }
  116.             if(!PreProcessMsg(msg)) 
  117.             {    
  118.                 TranslateMessage(&msg);    // Translate virtual key messages into character messages
  119.                 DispatchMessage(&msg);    // Dispatch message to the window proceedure
  120.             }
  121.         }
  122.     }
  123.     PTRACE("Application::MessageLoop() returned %d", result);
  124.  
  125.     return result;
  126. }
  127.  
  128. bool Application::PreProcessMsg(MSG& msg)
  129. {
  130.     if(m_hAccelTable && m_pMainWindow)
  131.         return TranslateAccelerator(m_pMainWindow->m_hWnd, m_hAccelTable, &msg) ? true : false;
  132.  
  133.     return false;
  134. }
  135.