]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/dialup.cpp
added wxUniChar::AsUTF8() for easy conversion in UTF8 build
[wxWidgets.git] / src / msw / dialup.cpp
index ac394e26abbed071e420a633916c6fd4e774e436..9e7eeda8cfba628e6bb38caa320823c40af07e59 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        msw/dialup.cpp
+// Name:        src/msw/dialup.cpp
 // Purpose:     MSW implementation of network/dialup classes and functions
 // Author:      Vadim Zeitlin
 // Modified by:
 
 #if wxUSE_DIALUP_MANAGER
 
+#include "wx/dialup.h"
+
 #ifndef WX_PRECOMP
     #include "wx/log.h"
     #include "wx/intl.h"
     #include "wx/event.h"
+    #include "wx/app.h"
+    #include "wx/timer.h"
+    #include "wx/module.h"
 #endif
 
-#include "wx/timer.h"
-#include "wx/app.h"
 #include "wx/generic/choicdgg.h"
 
 #include "wx/dynlib.h"
-#include "wx/dialup.h"
 
 DEFINE_EVENT_TYPE(wxEVT_DIALUP_CONNECTED)
 DEFINE_EVENT_TYPE(wxEVT_DIALUP_DISCONNECTED)
@@ -63,6 +65,14 @@ DEFINE_EVENT_TYPE(wxEVT_DIALUP_DISCONNECTED)
 #define INTERNET_CONNECTION_PROXY 4
 #endif
 
+// implemented in utils.cpp
+extern "C" WXDLLIMPEXP_BASE HWND
+wxCreateHiddenWindow(LPCTSTR *pclassname, LPCTSTR classname, WNDPROC wndproc);
+
+static const wxChar *
+    wxMSWDIALUP_WNDCLASSNAME = wxT("_wxDialUpManager_Internal_Class");
+static const wxChar *gs_classForDialUpWindow = NULL;
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -195,6 +205,7 @@ public:
 
     // for wxRasDialFunc
     static HWND GetRasWindow() { return ms_hwndRas; }
+    static void ResetRasWindow() { ms_hwndRas = NULL; }
     static wxDialUpManagerMSW *GetDialer() { return ms_dialer; }
 
 private:
@@ -280,6 +291,33 @@ private:
     DECLARE_NO_COPY_CLASS(wxDialUpManagerMSW)
 };
 
+// module to destroy helper window created by wxDialUpManagerMSW
+class wxDialUpManagerModule : public wxModule
+{
+public:
+    bool OnInit() { return true; }
+    void OnExit()
+    {
+        HWND hwnd = wxDialUpManagerMSW::GetRasWindow();
+        if ( hwnd )
+        {
+            ::DestroyWindow(hwnd);
+            wxDialUpManagerMSW::ResetRasWindow();
+        }
+
+        if ( gs_classForDialUpWindow )
+        {
+            ::UnregisterClass(wxMSWDIALUP_WNDCLASSNAME, wxGetInstance());
+            gs_classForDialUpWindow = NULL;
+        }
+    }
+
+private:
+    DECLARE_DYNAMIC_CLASS(wxDialUpManagerModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxDialUpManagerModule, wxModule)
+
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
@@ -460,7 +498,7 @@ wxString wxDialUpManagerMSW::GetErrorString(DWORD error)
 
         case 0:
             // we want the error message to start from a lower case letter
-            buffer[0] = wxTolower(buffer[0]);
+            buffer[0] = (wxChar)wxTolower(buffer[0]);
 
             return wxString(buffer);
     }
@@ -505,7 +543,7 @@ HRASCONN wxDialUpManagerMSW::FindActiveConnection()
         }
         else
         {
-            // an error occured
+            // an error occurred
             wxLogError(_("Cannot find active dialup connection: %s"),
                        GetErrorString(dwRet).c_str());
             return 0;
@@ -840,9 +878,12 @@ bool wxDialUpManagerMSW::Dial(const wxString& nameOfISP,
     if ( dwRet != 0 )
     {
         // can't pass a wxWCharBuffer through ( ... )
-        wxLogError(_("Failed to %s dialup connection: %s"),
-                   wxString(async ? _("initiate") : _("establish")).c_str(),
-                   GetErrorString(dwRet).c_str());
+        if ( async )
+            wxLogError(_("Failed to initiate dialup connection: %s"),
+                       GetErrorString(dwRet).c_str());
+        else
+            wxLogError(_("Failed to establish dialup connection: %s"),
+                       GetErrorString(dwRet).c_str());
 
         // we should still call RasHangUp() if we got a non 0 connection
         if ( ms_hRasConnection )
@@ -910,8 +951,10 @@ bool wxDialUpManagerMSW::HangUp()
         return false;
     }
 
-    DWORD dwRet = ms_pfnRasHangUp(hRasConn);
-    if ( dwRet != 0 )
+    // note that it's not an error if the connection had been already
+    // terminated
+    const DWORD dwRet = ms_pfnRasHangUp(hRasConn);
+    if ( dwRet != 0 && dwRet != ERROR_NO_CONNECTION )
     {
         wxLogError(_("Failed to terminate the dialup connection: %s"),
                    GetErrorString(dwRet).c_str());
@@ -1067,11 +1110,12 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds)
     {
         // create a hidden window to receive notification about connections
         // status change
-        extern const wxChar *wxCanvasClassName;
-        ms_hwndRas = ::CreateWindow(wxCanvasClassName, NULL,
-                                    0, 0, 0, 0,
-                                    0, NULL,
-                                    (HMENU)NULL, wxGetInstance(), 0);
+        ms_hwndRas = wxCreateHiddenWindow
+                     (
+                        &gs_classForDialUpWindow,
+                        wxMSWDIALUP_WNDCLASSNAME,
+                        wxRasStatusWindowProc
+                     );
         if ( !ms_hwndRas )
         {
             wxLogLastError(wxT("CreateWindow(RasHiddenWindow)"));
@@ -1080,9 +1124,6 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds)
 
             ok = false;
         }
-
-        // and subclass it
-        wxSetWindowProc(ms_hwndRas, wxRasStatusWindowProc);
     }
 
     m_data->hWnd = ms_hwndRas;
@@ -1151,7 +1192,7 @@ void wxDialUpManagerMSW::DisableAutoCheckOnlineStatus()
 {
     wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") );
 
-    if ( --m_autoCheckLevel )
+    if ( --m_autoCheckLevel != 0 )
     {
         // still checking
         return;
@@ -1228,7 +1269,8 @@ static DWORD wxRasMonitorThread(wxRasThreadData *data)
                 // using wxLogLastError() from here is dangerous: we risk to
                 // deadlock the main thread if wxLog sends output to GUI
                 DWORD err = GetLastError();
-                wxMessageOutputDebug().Printf
+                wxMessageOutputDebug dbg;
+                dbg.Printf
                 (
                     wxT("WaitForMultipleObjects(RasMonitor) failed: 0x%08lx (%s)"),
                     err,
@@ -1284,11 +1326,10 @@ static void WINAPI wxRasDialFunc(UINT WXUNUSED(unMsg),
 
     wxCHECK_RET( dialUpManager, wxT("who started to dial then?") );
 
-    SendMessage(dialUpManager->GetRasWindow(), wxWM_RAS_DIALING_PROGRESS,
+    SendMessage(wxDialUpManagerMSW::GetRasWindow(), wxWM_RAS_DIALING_PROGRESS,
                 rasconnstate, dwError);
 }
 
 #endif // __BORLANDC__
 
 #endif // wxUSE_DIALUP_MANAGER
-