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

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