[dasher: 6/217] Refactored program startup to ATL standard way.



commit 23f665fa70a7f01aa63fec1e34022e09a217566b
Author: ipomoena <amajorek google com>
Date:   Wed Jul 8 13:34:13 2015 -0700

    Refactored  program startup to ATL standard way.
    
    Also removed encountered windows CE ifdefs. It does not exist anymore.
    We will deal with Phone 8 when we get there.

 .gitignore                             |    1 +
 Src/Win32/Common/WinCommon.h           |    4 ++
 Src/Win32/Dasher.cpp                   |    3 +-
 Src/Win32/DasherControl_vc2013.vcxproj |    1 -
 Src/Win32/DasherWindow.cpp             |   32 -----------
 Src/Win32/DasherWindow.h               |    7 ---
 Src/Win32/WinMain.cpp                  |   92 ++++++++++++--------------------
 7 files changed, 41 insertions(+), 99 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 9658701..a186017 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,4 @@ Template/
 *.filters
 *.sdf
 *~
+*.vcxproj.user
diff --git a/Src/Win32/Common/WinCommon.h b/Src/Win32/Common/WinCommon.h
index 047edd4..24e5266 100644
--- a/Src/Win32/Common/WinCommon.h
+++ b/Src/Win32/Common/WinCommon.h
@@ -13,6 +13,10 @@
 
 #define NOMINMAX
 #define WIN32_LEAN_AND_MEAN     // Excludes rarely-used stuff from the Windows headers
+#define STRICT
+#define _ATL_NO_COM_SUPPORT
+#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
+#define _ATL_ENABLE_PTM_WARNING
 
 #include <atlbase.h>
 #include <atlwin.h>
diff --git a/Src/Win32/Dasher.cpp b/Src/Win32/Dasher.cpp
index a3d2e63..b8f4d7d 100644
--- a/Src/Win32/Dasher.cpp
+++ b/Src/Win32/Dasher.cpp
@@ -52,7 +52,6 @@ CDasher::CDasher(HWND Parent, CDasherWindow *pWindow, CEdit *pEdit)
   m_pCanvas = new CCanvas(this);
   m_pCanvas->Create(m_hParent); // TODO - check return 
 
-  // TODO: See MessageLoop, Main in CDasherWindow - should be brought into this class
   // Framerate settings: currently 40fps.
   SetTimer(m_pCanvas->getwindow(), 1, 25, NULL);
 
@@ -60,7 +59,7 @@ CDasher::CDasher(HWND Parent, CDasherWindow *pWindow, CEdit *pEdit)
 }
 
 CDasher::~CDasher(void) {
-//  WriteTrainFileFull();
+  WriteTrainFileFull();
   delete m_pCanvas;
 #ifdef WIN32_SPEECH
   if (pVoice) {
diff --git a/Src/Win32/DasherControl_vc2013.vcxproj b/Src/Win32/DasherControl_vc2013.vcxproj
index a14bf60..40e3d9b 100644
--- a/Src/Win32/DasherControl_vc2013.vcxproj
+++ b/Src/Win32/DasherControl_vc2013.vcxproj
@@ -196,7 +196,6 @@
   <ItemGroup>
     <ClInclude Include="BTSocketInput.h" />
     <ClInclude Include="Common\WinCommon.h" />
-    <ClInclude Include="Common\WinHelper.h" />
     <ClInclude Include="Common\WinLocalisation.h" />
     <ClInclude Include="Common\WinOptions.h" />
     <ClInclude Include="Common\WinUTF8.h" />
diff --git a/Src/Win32/DasherWindow.cpp b/Src/Win32/DasherWindow.cpp
index 71a62b7..29eeba0 100644
--- a/Src/Win32/DasherWindow.cpp
+++ b/Src/Win32/DasherWindow.cpp
@@ -140,36 +140,6 @@ CDasherWindow::~CDasherWindow() {
   DestroyIcon(m_hIconSm);
 }
 
-
-
-void CDasherWindow::Main() {
-  // TODO: Sort this sort ofthing out, figure out how it fits into ATL etc.
-  // This function is not called by anybody...
-#ifndef _WIN32_WCE
-       DASHER_ASSERT_VALIDPTR_RW(m_pDasher);
-#endif
-
-       m_pDasher->Main();
-       Sleep(50); // limits framerate to 20fps
-}
-
-int CDasherWindow::MessageLoop() {
-  // See previous function's comments
-       MSG msg;
-               
-  while(GetMessage(&msg, NULL, 0, 0)) {
-       if(!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
-                       TranslateMessage(&msg);
-                       DispatchMessage(&msg);
-               }
-       }
-
-  m_pDasher->WriteTrainFileFull();
-  //ACL also stop the timer...but ShutdownTimer() was a no-op, so assume we don't need to?
-
-  return msg.wParam;
-}
-
 void CDasherWindow::Show(int nCmdShow) {
   InvalidateRect(NULL, FALSE);
   
@@ -508,7 +478,6 @@ void CDasherWindow::Layout() {
   }
 }
 
-#ifndef _WIN32_WCE
 void CDasherWindow::HandleWinEvent(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG 
idChild, DWORD dwEventThread, DWORD dwmsEventTime) {
   // Ignore events if not in direct mode
   if(m_pAppSettings && (m_pAppSettings->GetLongParameter(APP_LP_STYLE) != APP_STYLE_DIRECT))
@@ -518,4 +487,3 @@ void CDasherWindow::HandleWinEvent(HWINEVENTHOOK hWinEventHook, DWORD event, HWN
   if(m_pDasher)
     m_pDasher->SetBuffer(0);
 }
-#endif
diff --git a/Src/Win32/DasherWindow.h b/Src/Win32/DasherWindow.h
index 1e28e0a..33b2469 100644
--- a/Src/Win32/DasherWindow.h
+++ b/Src/Win32/DasherWindow.h
@@ -80,12 +80,8 @@ public:
 
        void Show(int nCmdShow);
 
-       int MessageLoop();
-
-#ifndef _WIN32_WCE
   void HandleWinEvent(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, 
     LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime);
-#endif
 
   ///ACL making these public so can be called directly from CDasher,
   /// rather than sending a windows message.
@@ -93,9 +89,6 @@ public:
   
 private:
  
-       // Main processing function, called by MessageLoop
-       void Main();
-
        void SaveWindowState() const;
        bool LoadWindowState();
 
diff --git a/Src/Win32/WinMain.cpp b/Src/Win32/WinMain.cpp
index 72fefb4..d79f1a9 100644
--- a/Src/Win32/WinMain.cpp
+++ b/Src/Win32/WinMain.cpp
@@ -15,77 +15,55 @@
 
 #include "DasherWindow.h"
 
-#include <commctrl.h>
 
 using namespace Dasher;
+class CDasherApp : public CAtlExeModuleT< CDasherApp >
+{
+  CDasherWindow *m_pDasherWindow;
+public:
+  /*
+  Entry point to program on Windows systems
 
-#ifndef _WIN32_WCE
-// Windows Event handler
-VOID CALLBACK WEProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD 
dwEventThread, DWORD dwmsEventTime);
-#endif
+  An interface to the Dasher library is created.
+  A GUI and settings manager are created and given to the Dasher interface.
+  Control is passed to the main GUI loop, and only returns when the main window closes.
+  */
+  HRESULT Run(int nShowCmd){
+    m_pDasherWindow = new CDasherWindow;
 
-/*
-Entry point to program on Windows systems
+    m_pDasherWindow->Create();
+    m_pDasherWindow->Show(nShowCmd);
+    m_pDasherWindow->UpdateWindow();
+    HWINEVENTHOOK hHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_FOCUS, NULL, HandleWinEvent,
+      0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
 
-An interface to the Dasher library is created.
-A GUI and settings manager are created and given to the Dasher interface.
-Control is passed to the main GUI loop, and only returns when the main window closes.
-*/
-static CDasherWindow *g_pDasherWindow = NULL;
+    int iRet = CAtlExeModuleT< CDasherApp >::Run(nShowCmd);
 
-#ifndef _WIN32_WCE
-int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
-#else
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
-#endif
+    if (hHook)
+      UnhookWinEvent(hHook);
 
-#ifndef _WIN32_WCE
-  CoInitialize(NULL);
-#endif
+    delete m_pDasherWindow;
+    m_pDasherWindow = NULL;
 
-  WinHelper::hInstApp = hInstance;
-
-  //SHInitExtraControls();
-
-  // We don't want to starve other interactive applications
-  SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
-
-#ifndef _WIN32_WCE
-  HWINEVENTHOOK hHook;
+    return iRet;
+  };
 
-  hHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_FOCUS, NULL, WEProc,
-                          0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
-#endif
+  static VOID CALLBACK HandleWinEvent(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, 
LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime);
 
-  int iRet = 0;
+} DasherApp;
 
-  g_pDasherWindow = new CDasherWindow;
 
-       g_pDasherWindow->Create();
-  g_pDasherWindow->Show(nCmdShow);
-  g_pDasherWindow->UpdateWindow();
-
-  iRet = g_pDasherWindow->MessageLoop();
+VOID CALLBACK CDasherApp::HandleWinEvent(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, 
LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime) {
+  DasherApp.m_pDasherWindow->HandleWinEvent(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, 
dwmsEventTime);
+}
 
-  delete g_pDasherWindow;
-  g_pDasherWindow = NULL;
-  
-#ifndef _WIN32_WCE
-  if(hHook)
-    UnhookWinEvent(hHook);
-#endif
 
-#ifndef _WIN32_WCE
-  // Close the COM library on the current thread
-  CoUninitialize();
-#endif
+extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpCmdLine*/, int 
nShowCmd)
+{
+  WinHelper::hInstApp = hInstance;
 
-  return iRet;
-}
+  // We don't want to starve other interactive applications
+  SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
 
-#ifndef _WIN32_WCE
-VOID CALLBACK WEProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD 
dwEventThread, DWORD dwmsEventTime) {
-  if(g_pDasherWindow)
-    g_pDasherWindow->HandleWinEvent(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, 
dwmsEventTime);
+  return DasherApp.WinMain(nShowCmd);
 }
-#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]