X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d0e278d98e9ecc0f78943a662fca855811f3bea7..adb799d6ef8e1ba754ab08b26e64fa40219f95f8:/src/msw/app.cpp?ds=sidebyside diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 2b69e91300..b7ea221656 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -76,6 +76,11 @@ #include "wx/msw/wrapcctl.h" +// For MB_TASKMODAL +#ifdef __WXWINCE__ +#include "wx/msw/wince/missing.h" +#endif + #if (!defined(__MINGW32__) || wxCHECK_W32API_VERSION( 2, 0 )) && \ !defined(__CYGWIN__) && !defined(__DIGITALMARS__) && !defined(__WXWINCE__) && \ (!defined(_MSC_VER) || (_MSC_VER > 1100)) @@ -94,8 +99,13 @@ extern void wxSetKeyboardHook(bool doIt); // NB: all "NoRedraw" classes must have the same names as the "normal" classes // with NR suffix - wxWindow::MSWCreate() supposes this +#ifdef __WXWINCE__ + wxChar *wxCanvasClassName; + wxChar *wxCanvasClassNameNR; +#else const wxChar *wxCanvasClassName = wxT("wxWindowClass"); const wxChar *wxCanvasClassNameNR = wxT("wxWindowClassNR"); +#endif const wxChar *wxMDIFrameClassName = wxT("wxMDIFrameClass"); const wxChar *wxMDIFrameClassNameNoRedraw = wxT("wxMDIFrameClassNR"); const wxChar *wxMDIChildFrameClassName = wxT("wxMDIChildFrameClass"); @@ -249,6 +259,20 @@ bool wxApp::Initialize(int& argc, wxChar **argv) // ensure that base cleanup is done if we return too early wxCallBaseCleanup callBaseCleanup(this); +#ifdef __WXWINCE__ + wxString tmp = GetAppName(); + tmp += wxT("ClassName"); + wxCanvasClassName = wxStrdup( tmp.c_str() ); + tmp += wxT("NR"); + wxCanvasClassNameNR = wxStrdup( tmp.c_str() ); + HWND hWnd = FindWindow( wxCanvasClassNameNR, NULL ); + if (hWnd) + { + SetForegroundWindow( (HWND)(((DWORD)hWnd)|0x01) ); + return false; + } +#endif + // the first thing to do is to check if we're trying to run an Unicode // program under Win9x w/o MSLU emulation layer - if so, abort right now // as it has no chance to work @@ -262,7 +286,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv) ( NULL, _T("This program uses Unicode and requires Windows NT/2000/XP/CE.\nProgram aborted."), - _T("wxWindows Fatal Error"), + _T("wxWidgets Fatal Error"), MB_ICONERROR | MB_OK ); @@ -276,13 +300,6 @@ bool wxApp::Initialize(int& argc, wxChar **argv) #if wxUSE_OLE || wxUSE_DRAG_AND_DROP -#ifdef __WIN16__ - // for OLE, enlarge message queue to be as large as possible - int iMsg = 96; - while (!SetMessageQueue(iMsg) && (iMsg -= 8)) - ; -#endif // Win16 - #if wxUSE_OLE // we need to initialize OLE library #ifdef __WXWINCE__ @@ -317,7 +334,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv) wxDisableButtonBrush = ::CreateBrushIndirect( & lb ); ::DeleteObject( (HGDIOBJ)lb.lbHatch ); } - //else: wxWindows resources are probably not linked in + //else: wxWidgets resources are probably not linked in #endif #if wxUSE_PENWINDOWS @@ -326,13 +343,6 @@ bool wxApp::Initialize(int& argc, wxChar **argv) wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100); - // This is to foil optimizations in Visual C++ that throw out dummy.obj. - // PLEASE DO NOT ALTER THIS. -#if defined(__VISUALC__) && defined(__WIN16__) && !defined(WXMAKINGDLL) - extern char wxDummyChar; - if (wxDummyChar) wxDummyChar++; -#endif - #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) wxSetKeyboardHook(TRUE); #endif @@ -486,6 +496,12 @@ bool wxApp::UnregisterWindowClasses() void wxApp::CleanUp() { + // all objects pending for deletion must be deleted first, otherwise we + // would crash when they use wxWinHandleHash (and UnregisterWindowClasses() + // call wouldn't succeed as long as any windows still exist), so call the + // base class method first and only then do our clean up + wxAppBase::CleanUp(); + #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) wxSetKeyboardHook(FALSE); #endif @@ -517,8 +533,11 @@ void wxApp::CleanUp() delete wxWinHandleHash; wxWinHandleHash = NULL; - - wxAppBase::CleanUp(); + +#ifdef __WXWINCE__ + free( wxCanvasClassName ); + free( wxCanvasClassNameNR ); +#endif } // ---------------------------------------------------------------------------- @@ -545,17 +564,9 @@ wxApp::~wxApp() delete [] argv; } -bool wxApp::Initialized() -{ -#ifndef _WINDLL - if (GetTopWindow()) - return TRUE; - else - return FALSE; -#else // Assume initialized if DLL (no way of telling) - return TRUE; -#endif -} +// ---------------------------------------------------------------------------- +// wxApp idle handling +// ---------------------------------------------------------------------------- void wxApp::OnIdle(wxIdleEvent& event) { @@ -587,6 +598,10 @@ void wxApp::WakeUpIdle() } } +// ---------------------------------------------------------------------------- +// other wxApp event hanlders +// ---------------------------------------------------------------------------- + void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)) { if (GetTopWindow()) @@ -604,6 +619,10 @@ void wxApp::OnQueryEndSession(wxCloseEvent& event) } } +// ---------------------------------------------------------------------------- +// miscellaneous +// ---------------------------------------------------------------------------- + /* static */ int wxApp::GetComCtl32Version() { @@ -742,3 +761,43 @@ bool wxApp::Yield(bool onlyIfNeeded) return TRUE; } +#if wxUSE_EXCEPTIONS + +// ---------------------------------------------------------------------------- +// exception handling +// ---------------------------------------------------------------------------- + +bool wxApp::OnExceptionInMainLoop() +{ + // ask the user about what to do: use the Win32 API function here as it + // could be dangerous to use any wxWidgets code in this state + switch ( + ::MessageBox + ( + NULL, + _T("An unhandled exception occurred. Press \"Abort\" to \ +terminate the program,\r\n\ +\"Retry\" to exit the program normally and \"Ignore\" to try to continue."), + _T("Unhandled exception"), + MB_ABORTRETRYIGNORE | + MB_ICONERROR| + MB_TASKMODAL + ) + ) + { + case IDABORT: + throw; + + default: + wxFAIL_MSG( _T("unexpected MessageBox() return code") ); + // fall through + + case IDRETRY: + return false; + + case IDIGNORE: + return true; + } +} + +#endif // wxUSE_EXCEPTIONS