From: <zou...@us...> - 2008-03-19 11:07:57
|
Revision: 1048 http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=1048&view=rev Author: zouzou123gen Date: 2008-03-19 04:07:22 -0700 (Wed, 19 Mar 2008) Log Message: ----------- SingleInstance was being destroyed too soon Modified Paths: -------------- dcplusplus/trunk/changelog.txt dcplusplus/trunk/win32/MainWindow.cpp dcplusplus/trunk/win32/MainWindow.h dcplusplus/trunk/win32/main.cpp Modified: dcplusplus/trunk/changelog.txt =================================================================== --- dcplusplus/trunk/changelog.txt 2008-03-18 22:12:38 UTC (rev 1047) +++ dcplusplus/trunk/changelog.txt 2008-03-19 11:07:22 UTC (rev 1048) @@ -3,6 +3,7 @@ * Fixed help links (thanks poy) * Use setenv on unix (thanks yakov suraev) * Fixed out of focus window when restoring from icon (poy) +* [L#203865] Fixed multiple instances (poy) -- 0.705 2008-03-14 -- * Several patches for better *nix compatibility of the core (thanks steven sheehy et al) Modified: dcplusplus/trunk/win32/MainWindow.cpp =================================================================== --- dcplusplus/trunk/win32/MainWindow.cpp 2008-03-18 22:12:38 UTC (rev 1047) +++ dcplusplus/trunk/win32/MainWindow.cpp 2008-03-19 11:07:22 UTC (rev 1048) @@ -88,7 +88,7 @@ onSized(std::tr1::bind(&MainWindow::handleSized, this, _1)); onSpeaker(std::tr1::bind(&MainWindow::handleSpeaker, this, _1, _2)); onHelp(std::tr1::bind(&MainWindow::handleHelp, this, IDC_HELP_CONTENTS)); - onRaw(std::tr1::bind(&MainWindow::handleTrayIcon, this, _1, _2), SmartWin::Message(WM_APP + 242)); + onRaw(std::tr1::bind(&MainWindow::handleTrayIcon, this, _2), SmartWin::Message(WM_APP + 242)); updateStatus(); layout(); @@ -99,8 +99,9 @@ onClosing(std::tr1::bind(&MainWindow::closing, this)); onRaw(std::tr1::bind(&MainWindow::handleTrayMessage, this), SmartWin::Message(RegisterWindowMessage(_T("TaskbarCreated")))); - onRaw(std::tr1::bind(&MainWindow::handleEndSession, this, _1, _2), SmartWin::Message(WM_ENDSESSION)); - onRaw(std::tr1::bind(&MainWindow::handleWhereAreYou, this, _1, _2), SmartWin::Message(SingleInstance::WMU_WHERE_ARE_YOU)); + onRaw(std::tr1::bind(&MainWindow::handleEndSession, this), SmartWin::Message(WM_ENDSESSION)); + onRaw(std::tr1::bind(&MainWindow::handleCopyData, this, _2), SmartWin::Message(WM_COPYDATA)); + onRaw(std::tr1::bind(&MainWindow::handleWhereAreYou, this), SmartWin::Message(SingleInstance::WMU_WHERE_ARE_YOU)); TimerManager::getInstance()->start(); @@ -537,7 +538,7 @@ paned->setRect(r); } -LRESULT MainWindow::handleWhereAreYou(WPARAM, LPARAM) { +LRESULT MainWindow::handleWhereAreYou() { return SingleInstance::WMU_WHERE_ARE_YOU; } @@ -817,10 +818,9 @@ } } -LRESULT MainWindow::handleCopyData(WPARAM /*wParam*/, LPARAM lParam) { - tstring cmdLine = (LPCTSTR) (((COPYDATASTRUCT *)lParam)->lpData); - parseCommandLine(Text::toT(WinUtil::getAppName() + " ") + cmdLine); - return true; +LRESULT MainWindow::handleCopyData(LPARAM lParam) { + parseCommandLine(Text::toT(WinUtil::getAppName() + " ") + reinterpret_cast<LPCTSTR>(reinterpret_cast<COPYDATASTRUCT*>(lParam)->lpData)); + return TRUE; } void MainWindow::handleHashProgress() { @@ -914,7 +914,7 @@ ::HtmlHelp(handle(), WinUtil::getHelpFile().c_str(), action, id); } -LRESULT MainWindow::handleEndSession(WPARAM wParam, LPARAM lParam) { +LRESULT MainWindow::handleEndSession() { if (c != NULL) { c->removeListener(this); delete c; @@ -988,7 +988,7 @@ return handled; } -LRESULT MainWindow::handleTrayIcon(WPARAM /*wParam*/, LPARAM lParam) +LRESULT MainWindow::handleTrayIcon(LPARAM lParam) { if (lParam == WM_LBUTTONUP) { handleRestore(); Modified: dcplusplus/trunk/win32/MainWindow.h =================================================================== --- dcplusplus/trunk/win32/MainWindow.h 2008-03-18 22:12:38 UTC (rev 1047) +++ dcplusplus/trunk/win32/MainWindow.h 2008-03-19 11:07:22 UTC (rev 1048) @@ -159,16 +159,16 @@ void handleCloseWindows(unsigned id); void handleSize(); void handleActivate(bool active); - LRESULT handleEndSession(WPARAM wParam, LPARAM lParam); - LRESULT handleTrayIcon(WPARAM wParam, LPARAM lParam); + LRESULT handleEndSession(); + LRESULT handleTrayIcon(LPARAM lParam); // Other events bool handleSized(const SmartWin::WidgetSizedEventResult& sz); LRESULT handleSpeaker(WPARAM wParam, LPARAM lParam); LRESULT handleTrayMessage(); - LRESULT handleCopyData(WPARAM wParam, LPARAM lParam); - LRESULT handleWhereAreYou(WPARAM wParam, LPARAM lParam); + LRESULT handleCopyData(LPARAM lParam); + LRESULT handleWhereAreYou(); void handleTabsTitleChanged(const SmartUtil::tstring& title); Modified: dcplusplus/trunk/win32/main.cpp =================================================================== --- dcplusplus/trunk/win32/main.cpp 2008-03-18 22:12:38 UTC (rev 1047) +++ dcplusplus/trunk/win32/main.cpp 2008-03-19 11:07:22 UTC (rev 1048) @@ -32,23 +32,18 @@ const UINT SingleInstance::WMU_WHERE_ARE_YOU = ::RegisterWindowMessage(WMU_WHERE_ARE_YOU_MSG); -static void sendCmdLine(HWND hOther, const tstring& cmdLine) -{ - LRESULT result; - +static void sendCmdLine(HWND hOther, const tstring& cmdLine) { COPYDATASTRUCT cpd; cpd.dwData = 0; cpd.cbData = sizeof(TCHAR)*(cmdLine.length() + 1); cpd.lpData = (void *)cmdLine.c_str(); - result = SendMessage(hOther, WM_COPYDATA, NULL, (LPARAM)&cpd); + ::SendMessage(hOther, WM_COPYDATA, 0, reinterpret_cast<LPARAM>(&cpd)); } BOOL CALLBACK searchOtherInstance(HWND hWnd, LPARAM lParam) { DWORD result; - LRESULT ok = ::SendMessageTimeout(hWnd, SingleInstance::WMU_WHERE_ARE_YOU, 0, 0, - SMTO_BLOCK | SMTO_ABORTIFHUNG, 5000, &result); - - if(ok && result == SingleInstance::WMU_WHERE_ARE_YOU) { + if(::SendMessageTimeout(hWnd, SingleInstance::WMU_WHERE_ARE_YOU, 0, 0, SMTO_BLOCK | SMTO_ABORTIFHUNG, 5000, &result) && + result == SingleInstance::WMU_WHERE_ARE_YOU) { // found it HWND *target = (HWND *)lParam; *target = hWnd; @@ -57,14 +52,31 @@ return TRUE; } -bool checkOtherInstances(const tstring& cmdLine) { +void callBack(void* ptr, const string& a) { + SplashWindow& splash = *((SplashWindow*)ptr); + splash(a); +} + +#ifdef _DEBUG +void (*old_handler)(); + +// Dummy function to have something to break at +void term_handler() { + old_handler(); +} +#endif + +int SmartWinMain(SmartWin::Application& app) { + dcdebug("StartWinMain\n"); + #ifndef _DEBUG SingleInstance dcapp(_T("{DCPLUSPLUS-AEE8350A-B49A-4753-AB4B-E55479A48351}")); #else SingleInstance dcapp(_T("{DCPLUSPLUS-AEE8350A-B49A-4753-AB4B-E55479A48350}")); #endif - if(dcapp.isRunning()) { + tstring cmdLine = app.getCommandLine().getParamsRaw(); + HWND hOther = NULL; ::EnumWindows(&searchOtherInstance, (LPARAM)&hOther); @@ -81,34 +93,11 @@ ::ShowWindow(hOther, SW_RESTORE); } sendCmdLine(hOther, cmdLine); - return false; + return 1; } } - return true; -} -void callBack(void* ptr, const string& a) { - SplashWindow& splash = *((SplashWindow*)ptr); - splash(a); -} - #ifdef _DEBUG -void (*old_handler)(); - -// Dummy function to have something to break at -void term_handler() { - old_handler(); -} -#endif - -int SmartWinMain(SmartWin::Application& app) { - dcdebug("StartWinMain\n"); - - if(!checkOtherInstances(app.getCommandLine().getParamsRaw())) { - return 1; - } - -#ifdef _DEBUG old_handler = set_terminate(&term_handler); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |