ukeyconsole.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "stdafx2.h"
  2. #include "resource.h"
  3. #include "MainFrm.h"
  4. CAppModule _Module;
  5. int WINAPI gui_entry(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow, HWND *phWnd, IConsole *pConsole)
  6. {
  7. HRESULT hRes = ::CoInitialize(NULL);
  8. // If you are running on NT 4.0 or higher you can use the following call instead to
  9. // make the EXE free threaded. This means that calls come in on a random RPC thread.
  10. // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
  11. ATLASSERT(SUCCEEDED(hRes));
  12. // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
  13. ::DefWindowProc(NULL, 0, 0, 0L);
  14. AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES); // add flags to support other controls
  15. hRes = _Module.Init(NULL, hInstance);
  16. ATLASSERT(SUCCEEDED(hRes));
  17. ATL::AtlAxWinInit();
  18. CMessageLoop theLoop;
  19. _Module.AddMessageLoop(&theLoop);
  20. CMainFrame wndMain(pConsole);
  21. pConsole->Initialize();
  22. if(wndMain.CreateEx() == NULL)
  23. {
  24. ATLTRACE(_T("Main window creation failed!\n"));
  25. return -1;
  26. }
  27. if (phWnd) {
  28. *phWnd = wndMain.m_hWnd;
  29. }
  30. pConsole->OnStartRead(TRUE);
  31. wndMain.ShowWindow(nCmdShow);
  32. int nRet = theLoop.Run();
  33. _Module.RemoveMessageLoop();
  34. _Module.Term();
  35. ::CoUninitialize();
  36. pConsole->UnInitialize();
  37. pConsole->OnStopReady();
  38. return nRet;
  39. }