offline.cpp
上传用户:xhy777
上传日期:2007-02-14
资源大小:24088k
文件大小:4k
源码类别:

系统编程

开发平台:

Visual C++

  1. #include "private.h"   // Class Definitions 
  2. BOOL PromptToGoOffline(VOID);
  3. BOOL PromptToGoOnline(VOID);
  4. BOOL CALLBACK GoOfflinePromptDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  5.         LPARAM lParam);
  6. BOOL CALLBACK GoOnlinePromptDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  7.         LPARAM lParam);
  8. // Make sure that Notification Sinks are apartment model and hence are always called back
  9. // on the same thread making it unnecessary to use any critical sections -- BUGBUG
  10. // TRUE means that the state now is Online
  11. // FALSE means that the user chose to remain Offline
  12. BOOL
  13. OnConnectedNotification(void)
  14. {
  15.     BOOL fRet = TRUE;
  16.             
  17.     // Check to see if the user is offline and wants to "go online"
  18.     if((IsGlobalOffline()))
  19.     {
  20.         //Ask the user with a dialog
  21.         fRet = PromptToGoOnline();
  22.     }  
  23.     return fRet;
  24. }
  25. // TRUE means that the state now is Offline
  26. // FALSE means that the user chose to remain Online
  27. BOOL
  28. OnDisconnectedNotification(void)
  29. {      
  30.     BOOL fRet = TRUE;
  31.     // Check to see if the user wants to go offline
  32.     if(!(IsGlobalOffline()))
  33.     {
  34.         //Ask the user with a dialog, if the user says yes, then
  35.         // toggle to offline mode by calling wininet
  36.         fRet = PromptToGoOffline();
  37.     }
  38.         
  39.     return fRet;
  40. }
  41.     
  42. BOOL PromptToGoOffline(VOID)
  43. {
  44.     // run the dialog
  45.     BOOL fRet = DialogBoxParam(MLGetHinst(),MAKEINTRESOURCE(IDD_GO_OFFLINE_DLG),
  46.             NULL,GoOfflinePromptDlgProc,(LPARAM) 0);
  47.     return fRet;
  48. }
  49. /*******************************************************************
  50.         NAME:           GoOfflinePromptDlgProc
  51.         SYNOPSIS:       Dialog proc for Go Offline dialog
  52. ********************************************************************/
  53. BOOL CALLBACK GoOfflinePromptDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  54.         LPARAM lParam)
  55. {
  56.     switch (uMsg) {
  57.     case WM_INITDIALOG:
  58.         SetWindowPos(hDlg, HWND_TOPMOST, 0, 0, 0, 0,
  59.                 SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
  60.         return TRUE;
  61.         break;
  62.     case WM_COMMAND:
  63.         switch (wParam) {
  64.         case IDOK:
  65.             SetGlobalOffline(TRUE); 
  66.             EndDialog(hDlg,TRUE);
  67.             return TRUE;
  68.             break;
  69.         case IDCANCEL:            
  70.             EndDialog(hDlg,FALSE);
  71.             return TRUE;
  72.             break;
  73.         default:
  74.             break;
  75.         }
  76.         break;
  77.    default:
  78.         break;
  79.    }
  80.     return FALSE;
  81. }
  82. BOOL PromptToGoOnline(VOID)
  83. {
  84.     // run the dialog
  85.     BOOL fRet = DialogBoxParam(MLGetHinst(),MAKEINTRESOURCE(IDD_GO_ONLINE_DLG),
  86.             NULL,GoOnlinePromptDlgProc,(LPARAM) 0);
  87.     return fRet;
  88. }
  89. /*******************************************************************
  90.         NAME:           GoOnlinePromptDlgProc
  91.         SYNOPSIS:       Dialog proc for Go Online dialog
  92. ********************************************************************/
  93. BOOL CALLBACK GoOnlinePromptDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  94.         LPARAM lParam)
  95. {
  96.     switch (uMsg) {
  97.     case WM_INITDIALOG:
  98.         return TRUE;
  99.         break;
  100.     case WM_COMMAND:
  101.         switch (wParam) {
  102.         case IDOK:
  103.             SetGlobalOffline(FALSE); 
  104.             EndDialog(hDlg,TRUE);
  105.             return TRUE;
  106.             break;
  107.         case IDCANCEL: 
  108.             EndDialog(hDlg,FALSE);
  109.             return TRUE;
  110.             break;
  111.          default:
  112.             break;
  113.         }
  114.         break;
  115.     default:
  116.         break;
  117.     }
  118.     return FALSE;
  119. }