home *** CD-ROM | disk | FTP | other *** search
- /*
- Company: Sensaura
- Copyright: (C) 1999
-
- File Name: applicat.cpp
- File Description: Source file for implementation of Application class
- Author: Adam Philp
- Version: 1.01.000
- Last Update: 11-JAN-99
-
- Target Compiler: Microsoft Visual C++ Version 5.0
- */
-
- /////////////////////// Included files ////////////////////////////////////////////////////////////
-
- #include <windows.h>
-
- #include "applicat.h"
- #include "dxwindow.h"
- #include "resource.h"
-
- #include "debug.h"
-
- /////////////////////// Application class implementation //////////////////////////////////////////
-
- Application::Application(LPCSTR pName,
- HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR pCmdline,
- int cmdshow)
- {
- m_hInstance = hInstance;
- m_hPrevInstance = hPrevInstance;
- m_pName = pName;
- m_nCmdShow = cmdshow;
- m_hMainWindow = NULL;
- m_hAccelTable = NULL;
- }
-
- Application::~Application()
- {
- }
-
- /////////////////////// Application public member functions ///////////////////////////////////////
-
- int Application::Run()
- {
- if(!m_hPrevInstance)
- InitApplication();
- InitInstance();
-
- if(m_hMainWindow)
- return MessageLoop();
- else
- return -1;
- }
-
- void Application::InitApplication()
- {
- }
-
- void Application::InitInstance()
- {
- InitMainWindow();
-
- if(m_hMainWindow)
- if(m_hMainWindow->Create())
- m_hMainWindow->ShowWindow(m_nCmdShow);
- }
-
- void Application::InitMainWindow()
- {
- m_hMainWindow = new DirectXWindow(0, m_pName, this);
- m_hMainWindow->m_Attr.hIcon = LoadIcon(m_hInstance, MAKEINTRESOURCE(IDI_SENSAURA));
- m_hAccelTable = LoadAccelerators(m_hInstance, MAKEINTRESOURCE(IDR_ACCELERATORS));
- }
-
- int Application::MessageLoop()
- {
- MSG msg;
- bool bBreakLoop;
- int result;
- long idleCount;
-
- bBreakLoop = false;
- result = 0;
- idleCount = 0;
- while(!bBreakLoop)
- {
- while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- if(msg.message == WM_QUIT)
- {
- delete m_hMainWindow;
- m_hMainWindow = NULL;
- bBreakLoop = true;
- break;
- }
- if(!PreProcessMsg(msg))
- {
- TranslateMessage(&msg); // Translate virtual key messages into character messages
- DispatchMessage(&msg); // Dispatch message to the window proceedure
- }
- idleCount = 0;
- }
- IdleAction(idleCount++);
- }
- return result;
- }
-
- bool Application::PreProcessMsg(MSG& msg)
- {
- if(m_hAccelTable && m_hMainWindow)
- return TranslateAccelerator(m_hMainWindow->m_hWnd, m_hAccelTable, &msg) ? true : false;
-
- return false;
- }
-
- bool Application::IdleAction(long idleCount)
- {
- return m_hMainWindow ? m_hMainWindow->IdleAction(idleCount) : false;
- }
-