home *** CD-ROM | disk | FTP | other *** search
- /*
- Company: Sensaura Ltd
- Copyright: (C) 2000
-
- File Name: applicat.cpp
- File Description: Source file for implementation of Application class
- Author: Adam Philp
- Last Update: 04-JAN-00
-
- Target Compiler: Microsoft Visual C++ Version 5.0
- */
-
- /////////////////////// Included files ////////////////////////////////////////////////////////////
-
- #include <windows.h>
-
- #include "applicat.h"
- #include "resource.h"
- #include "debug.h"
-
- /////////////////////// Application class implementation //////////////////////////////////////////
-
- Application::Application(LPCSTR pName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR pCmdLine, int cmdshow)
- {
- PTRACE("Application::Application(pName:%s, hInstance:%X, hPrevInstance:%X, pCmdLine:%s, cmdshow:%d)",
- pName, hInstance, hPrevInstance, pCmdLine, cmdshow);
-
- m_hInstance = hInstance;
- m_hPrevInstance = hPrevInstance;
- m_pName = pName;
- m_nCmdShow = cmdshow;
- m_pMainWindow = NULL;
- m_hAccelTable = NULL;
- }
-
- Application::~Application()
- {
- PTRACE("Application::~Application()");
- }
-
- /////////////////////// Application public member functions ///////////////////////////////////////
-
- int Application::Run()
- {
- int ret = 0;
-
- PTRACE("Application::Run()");
-
- if(!m_hPrevInstance)
- if(!InitApplication())
- ret = -1;
- if(ret == 0)
- if(!InitInstance())
- ret = -2;
- if(ret == 0)
- ret = MessageLoop();
-
- PTRACE("Application::Run() returned %d", ret);
-
- return ret;
- }
-
- /////////////////////// Application protected member functions ////////////////////////////////////
-
- bool Application::InitApplication()
- {
- PTRACE("Application::InitApplication() OK");
- return TRUE;
- }
-
- bool Application::InitInstance()
- {
- PTRACE("Application::InitInstance()");
-
- m_pMainWindow = new MainWnd(m_pName, this);
- if(m_pMainWindow == NULL)
- return false;
-
- m_hAccelTable = LoadAccelerators(m_hInstance, MAKEINTRESOURCE(IDR_ACCELERATORS));
- if(!m_pMainWindow->Create())
- {
- delete m_pMainWindow;
- m_pMainWindow = NULL;
- return false;
- }
-
- m_pMainWindow->ShowWindow(m_nCmdShow);
-
- PTRACE("Application::InitInstance() OK");
-
- return true;
- }
-
- int Application::MessageLoop()
- {
- MSG msg;
- bool bBreakLoop;
- int result;
-
- PTRACE("Application::MessageLoop()");
-
- bBreakLoop = false;
- result = 0;
- while(!bBreakLoop)
- {
- while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- if(msg.message == WM_QUIT)
- {
- delete m_pMainWindow;
- m_pMainWindow = NULL;
- bBreakLoop = true;
- break;
- }
- if(!PreProcessMsg(msg))
- {
- TranslateMessage(&msg); // Translate virtual key messages into character messages
- DispatchMessage(&msg); // Dispatch message to the window proceedure
- }
- }
- }
- PTRACE("Application::MessageLoop() returned %d", result);
-
- return result;
- }
-
- bool Application::PreProcessMsg(MSG& msg)
- {
- if(m_hAccelTable && m_pMainWindow)
- return TranslateAccelerator(m_pMainWindow->m_hWnd, m_hAccelTable, &msg) ? true : false;
-
- return false;
- }
-