]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/dialup.cpp
wxTinderbox build fix (!PCH support).
[wxWidgets.git] / src / msw / dialup.cpp
index 04ee582b81f23c26f6ed95e24b22dd2b770d4563..074b23c6a52d25336bb5505b5a31890a0fe67443 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "wx/dynlib.h"
 #include "wx/dialup.h"
 
 #include "wx/dynlib.h"
 #include "wx/dialup.h"
+#include "wx/module.h"
 
 DEFINE_EVENT_TYPE(wxEVT_DIALUP_CONNECTED)
 DEFINE_EVENT_TYPE(wxEVT_DIALUP_DISCONNECTED)
 
 DEFINE_EVENT_TYPE(wxEVT_DIALUP_CONNECTED)
 DEFINE_EVENT_TYPE(wxEVT_DIALUP_DISCONNECTED)
@@ -63,6 +64,14 @@ DEFINE_EVENT_TYPE(wxEVT_DIALUP_DISCONNECTED)
 #define INTERNET_CONNECTION_PROXY 4
 #endif
 
 #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
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -195,6 +204,7 @@ public:
 
     // for wxRasDialFunc
     static HWND GetRasWindow() { return ms_hwndRas; }
 
     // for wxRasDialFunc
     static HWND GetRasWindow() { return ms_hwndRas; }
+    static void ResetRasWindow() { ms_hwndRas = NULL; }
     static wxDialUpManagerMSW *GetDialer() { return ms_dialer; }
 
 private:
     static wxDialUpManagerMSW *GetDialer() { return ms_dialer; }
 
 private:
@@ -280,6 +290,33 @@ private:
     DECLARE_NO_COPY_CLASS(wxDialUpManagerMSW)
 };
 
     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
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
@@ -505,7 +542,7 @@ HRASCONN wxDialUpManagerMSW::FindActiveConnection()
         }
         else
         {
         }
         else
         {
-            // an error occured
+            // an error occurred
             wxLogError(_("Cannot find active dialup connection: %s"),
                        GetErrorString(dwRet).c_str());
             return 0;
             wxLogError(_("Cannot find active dialup connection: %s"),
                        GetErrorString(dwRet).c_str());
             return 0;
@@ -910,8 +947,10 @@ bool wxDialUpManagerMSW::HangUp()
         return false;
     }
 
         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());
     {
         wxLogError(_("Failed to terminate the dialup connection: %s"),
                    GetErrorString(dwRet).c_str());
@@ -1067,11 +1106,12 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds)
     {
         // create a hidden window to receive notification about connections
         // status change
     {
         // 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)"));
         if ( !ms_hwndRas )
         {
             wxLogLastError(wxT("CreateWindow(RasHiddenWindow)"));
@@ -1080,9 +1120,6 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds)
 
             ok = false;
         }
 
             ok = false;
         }
-
-        // and subclass it
-        wxSetWindowProc(ms_hwndRas, wxRasStatusWindowProc);
     }
 
     m_data->hWnd = ms_hwndRas;
     }
 
     m_data->hWnd = ms_hwndRas;
@@ -1151,7 +1188,7 @@ void wxDialUpManagerMSW::DisableAutoCheckOnlineStatus()
 {
     wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") );
 
 {
     wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") );
 
-    if ( --m_autoCheckLevel )
+    if ( --m_autoCheckLevel != 0 )
     {
         // still checking
         return;
     {
         // still checking
         return;
@@ -1285,7 +1322,7 @@ static void WINAPI wxRasDialFunc(UINT WXUNUSED(unMsg),
 
     wxCHECK_RET( dialUpManager, wxT("who started to dial then?") );
 
 
     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);
 }
 
                 rasconnstate, dwError);
 }