X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2049ba38adafa0ec146880de29f26e32dd69a125..8429bec1e8e3fcb7d071bc3ef7c665c484b5fdc1:/src/msw/app.cpp diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 12111a86fc..2380393bfd 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -52,6 +52,13 @@ #include #endif +// use debug CRT functions for memory leak detections in VC++ +/* Doesn't work when using the makefiles, for some reason. +#if defined(__WXDEBUG__) && defined(_MSC_VER) + #include +#endif +*/ + extern char *wxBuffer; extern char *wxOsVersion; extern wxList *wxWinHandleList; @@ -59,7 +66,7 @@ extern wxList wxPendingDelete; extern void wxSetKeyboardHook(bool doIt); extern wxCursor *g_globalCursor; -HANDLE wxhInstance = 0; +HINSTANCE wxhInstance = 0; static MSG s_currentMsg; wxApp *wxTheApp = NULL; @@ -94,9 +101,9 @@ long wxApp::sm_lastMessageTime = 0; static HINSTANCE gs_hRichEdit = NULL; #endif -bool wxApp::Initialize(WXHANDLE instance) +bool wxApp::Initialize(WXHINSTANCE instance) { - HANDLE hInstance = (HANDLE)instance; + HINSTANCE hInstance = (HINSTANCE) instance; CommonInit(); @@ -248,7 +255,7 @@ bool wxApp::RegisterWindowClasses() wndclass2.hIcon = NULL; wndclass2.hCursor = NULL; // wndclass2.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ; - wndclass2.hbrBackground = GetStockObject( LTGRAY_BRUSH ); + wndclass2.hbrBackground = (HBRUSH) GetStockObject( LTGRAY_BRUSH ); wndclass2.lpszMenuName = NULL; wndclass2.lpszClassName = wxPanelClassName; if (!RegisterClass( &wndclass2 )) @@ -263,9 +270,9 @@ bool wxApp::RegisterWindowClasses() memset(&wndclass3, 0, sizeof(WNDCLASS)); // start with NULL defaults // Use CS_OWNDC to avoid messing about restoring the context // for every graphic operation. -// wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ; +// wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS ; // wxWin 2.0 - wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ; + wndclass3.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ; wndclass3.lpfnWndProc = (WNDPROC)wxWndProc; wndclass3.cbClsExtra = 0; wndclass3.cbWndExtra = sizeof( DWORD ); // was 4 @@ -330,8 +337,9 @@ void wxApp::CleanUp() if (wxWinHandleList) delete wxWinHandleList ; - + // do it as the very last thing because everything else can log messages + wxLog::DontCreateOnDemand(); delete wxLog::SetActiveTarget(NULL); } @@ -351,6 +359,8 @@ void wxApp::CommonInit() wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); wxTheColourDatabase->Initialize(); + + wxInitializeStockLists(); wxInitializeStockObjects(); #if USE_WX_RESOURCES @@ -376,6 +386,7 @@ void wxApp::CommonCleanUp() // wxDefaultResourceTable->ClearTable(); #endif + // Indicate that the cursor can be freed, // so that cursor won't be deleted by deleting // the bitmap list before g_globalCursor goes out @@ -386,17 +397,7 @@ void wxApp::CommonCleanUp() wxDeleteStockObjects() ; // Destroy all GDI lists, etc. - delete wxTheBrushList; - wxTheBrushList = NULL; - - delete wxThePenList; - wxThePenList = NULL; - - delete wxTheFontList; - wxTheFontList = NULL; - - delete wxTheBitmapList; - wxTheBitmapList = NULL; + wxDeleteStockLists(); delete wxTheColourDatabase; wxTheColourDatabase = NULL; @@ -422,6 +423,15 @@ int wxEntry(WXHINSTANCE hInstance, WXHINSTANCE WXUNUSED(hPrevInstance), char *m_ { wxhInstance = (HINSTANCE) hInstance; +/* Doesn't work when using the makefiles, for some reason. + #if defined(__WXDEBUG__) && defined(_MSC_VER) + // do check for memory leaks on program exit + // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free + // deallocated memory which may be used to simulate low-memory condition) + _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF); + #endif // debug build under MS VC++ +*/ + #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT #if !defined(_WINDLL) @@ -432,7 +442,7 @@ int wxEntry(WXHINSTANCE hInstance, WXHINSTANCE WXUNUSED(hPrevInstance), char *m_ ostream* oStr = new ostream(sBuf) ; wxDebugContext::SetStream(oStr, sBuf); -#endif +#endif // USE_MEMORY_TRACING if (!wxApp::Initialize((WXHINSTANCE) wxhInstance)) return 0; @@ -458,10 +468,10 @@ int wxEntry(WXHINSTANCE hInstance, WXHINSTANCE WXUNUSED(hPrevInstance), char *m_ // Split command line into tokens, as in usual main(argc, argv) char **command = new char*[50]; - + int count = 0; char *buf = new char[strlen(m_lpCmdLine) + 1]; - + // Hangs around until end of app. in case // user carries pointers to the tokens @@ -563,7 +573,7 @@ int wxEntry(WXHINSTANCE hInstance, WXHINSTANCE WXUNUSED(hPrevInstance), char *m_ wxTheApp->SetTopWindow(NULL); } } - + wxTheApp->OnExit(); wxApp::CleanUp(); @@ -681,7 +691,7 @@ bool wxApp::DoMessage() { return FALSE; } - + // Process the message if (!ProcessMessage((WXMSG *)&s_currentMsg)) { @@ -757,26 +767,29 @@ bool wxApp::ProcessMessage(WXMSG *Msg) HWND hWnd; - // Anyone for a message? Try youngest descendants first. + // Try translations first; find the youngest window with + // a translation table. for (hWnd = msg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd)) { wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); if (wnd) { - if (wnd->MSWProcessMessage(Msg)) + if (wnd->MSWTranslateMessage(Msg)) return TRUE; - - // STOP if we've reached the top of the hierarchy! -// if (m_topWindow && (wnd == m_topWindow)) -// return FALSE; } } - // TODO: Is this now obsolete, given that m_topWindow may not be defined? - // Does it do anything useful anyway? -// if (m_topWindow && m_topWindow->MSWProcessMessage(Msg)) -// return TRUE; - return FALSE; + // Anyone for a non-translation message? Try youngest descendants first. + for (hWnd = msg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd)) + { + wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); + if (wnd) + { + if (wnd->MSWProcessMessage(Msg)) + return TRUE; + } + } + return FALSE; } void wxApp::OnIdle(wxIdleEvent& event) @@ -853,7 +866,7 @@ void wxApp::DeletePendingObjects() while (node) { wxObject *obj = (wxObject *)node->Data(); - + delete obj; if (wxPendingDelete.Member(obj)) @@ -939,13 +952,13 @@ int wxApp::GetComCtl32Version() const // have we loaded COMCTL32 yet? HMODULE theModule = ::GetModuleHandle("COMCTL32"); int version = 0; - + // if so, then we can check for the version if (theModule) { // InitCommonControlsEx is unique to 4.7 and later FARPROC theProc = ::GetProcAddress(theModule, "InitCommonControlsEx"); - + if (! theProc) { // not found, must be 4.00 version = 400;