1 // This is a part of the Microsoft Foundation Classes C++ library.
2 // Copyright (C) 1992-1995 Microsoft Corporation
3 // All rights reserved.
5 // This source code is only intended as a supplement to the
6 // Microsoft Foundation Classes Reference and related
7 // electronic documentation provided with the library.
8 // See these sources for detailed information regarding the
9 // Microsoft Foundation Classes product.
13 #include <Standard_ErrorHandler.hxx>
14 #include <Standard_SStream.hxx>
15 #include <Standard_Failure.hxx>
16 #include <Message.hxx>
17 #include <Message_Messenger.hxx>
18 #include <Message_PrinterOStream.hxx>
21 #pragma code_seg(AFX_CORE1_SEG)
24 /////////////////////////////////////////////////////////////////////////////
25 // Standard WinMain implementation
26 // Can be replaced as long as 'AfxWinInit' is called first
28 // for cout redefinition :
29 #include <io.h> // for _open_osfhandle
30 #include <fcntl.h> // for _O_TEXT
33 #define DISPLAYCONSOLE 1
36 int AFXAPI AfxWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
37 LPTSTR lpCmdLine, int nCmdShow)
41 // Redirection of standard output to console
42 int hCrt; BOOL rep; FILE *hf;
46 hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
47 hf = _fdopen( hCrt, "w" );
49 // stop the buffer on stdout
50 // int i = setvbuf( stdout, NULL, _IONBF, 0 );
53 cout<<"This Debug Window is defined in WinMain.cpp and will disappear in release mode"<<endl;
55 #endif // DISPLAYCONSOLE // By Matra
57 // create log file for all OCC messages
58 // Message::DefaultMessenger()->AddPrinter (new Message_PrinterOStream ("OCCSampleRun.log", Standard_False));
60 ASSERT(hPrevInstance == NULL);
63 CWinApp* pApp = AfxGetApp();
65 // new in 2.0 CAS.CADE uses the standard C++ exception mechanism
66 /*#ifdef _DEBUG // By Matra
67 // _Function declaratiob here because you can jump to InitFailure
68 Standard_ErrorHandler _Function;
69 #endif // _DEBUG // By Matra
71 // AFX internal initialization
72 if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
75 // App global initializations (rare)
77 if (!pApp->InitApplication())
81 // Perform specific initializations
82 if (!pApp->InitInstance())
84 if (pApp->m_pMainWnd != NULL)
86 TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
87 pApp->m_pMainWnd->DestroyWindow();
89 nReturnCode = pApp->ExitInstance();
95 #ifdef _DEBUG // By Matra
98 // new in 2.0 CAS.CADE uses the standard C++ exception mechanism
100 // if(DoesNotAbort(_Function))
103 nReturnCode = pApp->Run();
105 // if(_Function.Catches(STANDARD_TYPE(Standard_Failure)))
106 catch(Standard_Failure const& anException)
108 Standard_SStream ostr;
109 ostr<<anException<<"\n\0";
110 CString aMsg = ostr.str().c_str();
111 MessageBoxW (NULL, aMsg, L"CasCade Error", MB_ICONERROR);
112 goto Application; // restart application loop
114 #else // _DEBUG // By Matra
115 nReturnCode = pApp->Run();
116 #endif // _DEBUG // By Matra
123 // Check for missing AfxLockTempMap calls
124 if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
126 TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
127 AfxGetModuleThreadState()->m_nTempMapLock);
136 #ifdef DISPLAYCONSOLE // By Matra
137 // ferme la console pour le cout
139 //hCrt = _fcloseall(); :-)
141 #endif // DISPLAYCONSOLE // By Matra
147 /////////////////////////////////////////////////////////////////////////////