dbgdlgs.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 9k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*  File: dbgdlgs.cpp
  3.     Description: 
  4.     Revision History:
  5.     Date        Description                                          Programmer
  6.     --------    ---------------------------------------------------  ----------
  7.     12/09/97    Initial creation.                                    BrianAu
  8. */
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #include "pch.h"
  11. #pragma hdrstop
  12. #include "dbgdlgs.h"
  13. #include <resource.h>
  14. #include "viewerp.h"
  15. #include "uncpath.h"
  16. #include "cscutils.h"
  17. #include "msgbox.h"
  18. ShareDbgDialog::ShareDbgDialog(
  19.     LPCTSTR pszShare,
  20.     const CnxNameCache& cnc
  21.     ) : m_hInstance(NULL),
  22.         m_strShare(pszShare),
  23.         m_CnxNameCache(cnc)
  24. {
  25. }
  26. void
  27. ShareDbgDialog::Run(
  28.     HINSTANCE hInstance,
  29.     HWND hwndParent
  30.     )
  31. {
  32.     m_hInstance = hInstance;
  33.     int iResult = DialogBoxParam(m_hInstance,
  34.               MAKEINTRESOURCE(IDD_CACHEVIEW_SHAREDBG),
  35.               hwndParent,
  36.               DlgProc,
  37.               reinterpret_cast<LPARAM>(this));
  38.     if (-1 == iResult)
  39.     {
  40.         CscWin32Message(hwndParent, GetLastError(), CSCUI::SEV_ERROR);
  41.     }
  42. }
  43. BOOL CALLBACK
  44. ShareDbgDialog::DlgProc(
  45.     HWND hwnd,
  46.     UINT message,
  47.     WPARAM wParam,
  48.     LPARAM lParam
  49.     )
  50. {
  51.     ShareDbgDialog *pThis = reinterpret_cast<ShareDbgDialog *>(GetWindowLongPtr(hwnd, DWLP_USER));
  52.     switch(message)
  53.     {
  54.         case WM_INITDIALOG:
  55.             pThis = reinterpret_cast<ShareDbgDialog *>(lParam);
  56.             SetWindowLongPtr(hwnd, DWLP_USER, (INT_PTR)pThis);
  57.             DBGASSERT((NULL != pThis));
  58.             pThis->OnInitDialog(hwnd);
  59.             return TRUE;
  60.         case WM_ENDSESSION:
  61.             EndDialog(hwnd, 0);
  62.             return true;
  63.         case WM_COMMAND:    
  64.             DBGASSERT((NULL != pThis));
  65.             if (BN_CLICKED == HIWORD(wParam))
  66.             {
  67.                 switch(LOWORD(wParam))
  68.                 {
  69.                     case IDCANCEL:
  70.                     case IDOK:
  71.                         EndDialog(hwnd, 0);
  72.                         return TRUE;
  73.                     case IDC_SHRDBG_BTN_REFRESH:
  74.                         pThis->Refresh(hwnd);
  75.                         return TRUE;
  76.                     default:
  77.                         break;
  78.                 }
  79.             }
  80.             break;
  81.     }
  82.     return FALSE;
  83. }
  84. void
  85. ShareDbgDialog::OnInitDialog(
  86.     HWND hwnd
  87.     )
  88. {
  89.     CString strText;
  90.     TCHAR szDrive[] = TEXT("?");
  91.     UNCPath unc(m_strShare);
  92.     szDrive[0] = m_CnxNameCache.GetShareDriveLetter(m_strShare);
  93.     if (TEXT('') != szDrive[0])
  94.     {
  95.         //
  96.         // Drive character provided.
  97.         // Format as "ntspecs (E:) on 'worf'"
  98.         //
  99.         strText.Format(m_hInstance, 
  100.                        IDS_FMT_SHARENAME_LONG,
  101.                        (LPCTSTR)unc.m_strShare,
  102.                        (LPCTSTR)unc.m_strServer,
  103.                        szDrive);
  104.     }
  105.     else
  106.     {
  107.         //
  108.         // Drive character not provided.
  109.         // Format as "ntspecs on 'worf'"
  110.         //
  111.         strText.Format(m_hInstance,
  112.                        IDS_FMT_SHARENAME_LONG_NODRIVE,
  113.                        (LPCTSTR)unc.m_strShare,
  114.                        (LPCTSTR)unc.m_strServer);
  115.     }
  116.     SetWindowText(GetDlgItem(hwnd, IDC_SHRDBG_TXT_SHARENAME), (LPCTSTR)strText);
  117.     Refresh(hwnd);
  118. }
  119. void
  120. ShareDbgDialog::Refresh(
  121.     HWND hwnd
  122.     )
  123. {
  124.     CscShareInformation si;
  125.     TCHAR szNumber[40];
  126.     CscGetShareInformation(m_strShare, &si);
  127.     //
  128.     // PBMF means "pointer to boolean member function"
  129.     //
  130.     typedef bool (CscShareInformation::*PBMF)(void) const;
  131.     static const struct
  132.     {
  133.         int idCtl;
  134.         PBMF pfn;
  135.     } rgStatus[] = {{ IDC_SHRDBG_TXT_MODOFFLINE,      si.ModifiedOffline },
  136.                     { IDC_SHRDBG_TXT_CONNECTED,       si.Connected       },
  137.                     { IDC_SHRDBG_TXT_FILESOPEN,       si.FilesOpen       },
  138.                     { IDC_SHRDBG_TXT_FINDSINPROG,     si.FindsInProgress },
  139.                     { IDC_SHRDBG_TXT_DISCONNECTEDOP,  si.DisconnectedOp  },
  140.                     { IDC_SHRDBG_TXT_MERGING,         si.Merging         }
  141.                    };
  142.     for (int i = 0; i < ARRAYSIZE(rgStatus); i++)
  143.     {
  144.         PBMF pfn = rgStatus[i].pfn;
  145.         wsprintf(szNumber, TEXT("%d"), (si.*pfn)());
  146.         SetWindowText(GetDlgItem(hwnd, rgStatus[i].idCtl), szNumber);
  147.     }
  148.     SendMessage(GetDlgItem(hwnd, IDC_SHRDBG_ICON), 
  149.                 STM_SETICON,
  150.                 (WPARAM)LoadIcon(m_hInstance, MAKEINTRESOURCE(si.Connected() ? IDI_SHARE : IDI_SHARE_NOCNX)),
  151.                 0);
  152. }
  153. FileDbgDialog::FileDbgDialog(
  154.     LPCTSTR pszFile,
  155.     bool bIsDirectory
  156.     ) : m_hInstance(NULL),
  157.         m_strFile(pszFile),
  158.         m_bIsDirectory(bIsDirectory)
  159. {
  160. }
  161. void
  162. FileDbgDialog::Run(
  163.     HINSTANCE hInstance,
  164.     HWND hwndParent
  165.     )
  166. {
  167.     m_hInstance = hInstance;
  168.     int iResult = DialogBoxParam(m_hInstance,
  169.               MAKEINTRESOURCE(IDD_CACHEVIEW_FILEDBG),
  170.               hwndParent,
  171.               DlgProc,
  172.               reinterpret_cast<LPARAM>(this));
  173.     if (-1 == iResult)
  174.     {
  175.         CscWin32Message(hwndParent, GetLastError(), CSCUI::SEV_ERROR);
  176.     }
  177. }
  178. BOOL CALLBACK
  179. FileDbgDialog::DlgProc(
  180.     HWND hwnd,
  181.     UINT message,
  182.     WPARAM wParam,
  183.     LPARAM lParam
  184.     )
  185. {
  186.     FileDbgDialog *pThis = reinterpret_cast<FileDbgDialog *>(GetWindowLongPtr(hwnd, DWLP_USER));
  187.     switch(message)
  188.     {
  189.         case WM_INITDIALOG:
  190.             pThis = reinterpret_cast<FileDbgDialog *>(lParam);
  191.             SetWindowLongPtr(hwnd, DWLP_USER, (INT_PTR)pThis);
  192.             DBGASSERT((NULL != pThis));
  193.             pThis->OnInitDialog(hwnd);
  194.             return TRUE;
  195.         case WM_ENDSESSION:
  196.             EndDialog(hwnd, 0);
  197.             return true;
  198.         case WM_COMMAND:    
  199.             DBGASSERT((NULL != pThis));
  200.             if (BN_CLICKED == HIWORD(wParam))
  201.             {
  202.                 switch(LOWORD(wParam))
  203.                 {
  204.                     case IDCANCEL:
  205.                     case IDOK:
  206.                         EndDialog(hwnd, 0);
  207.                         return TRUE;
  208.                     case IDC_FILEDBG_BTN_REFRESH:
  209.                         pThis->Refresh(hwnd);
  210.                         return TRUE;
  211.                     default:
  212.                         break;
  213.                 }
  214.                 
  215.             }
  216.             break;
  217.     }
  218.     return FALSE;
  219. }
  220. void
  221. FileDbgDialog::OnInitDialog(
  222.     HWND hwnd
  223.     )
  224. {
  225.     SetWindowText(GetDlgItem(hwnd, IDC_FILEDBG_TXT_FILENAME), (LPCTSTR)m_strFile);
  226.     Refresh(hwnd);
  227. }
  228. void
  229. FileDbgDialog::Refresh(
  230.     HWND hwnd
  231.     )
  232. {
  233.     CscFileInformation fi;
  234.     TCHAR szNumber[40];
  235.     CscGetFileInformation(m_strFile, &fi);
  236.     //
  237.     // PBMF means "pointer to boolean member function"
  238.     //
  239.     typedef bool (CscFileInformation::*PBMF)(void) const;
  240.     static const struct
  241.     {
  242.         int idCtl;
  243.         PBMF pfn;
  244.     } rgStatus[] = {{ IDC_FILEDBG_TXT_DATAMOD,           fi.DataLocallyModified   },
  245.                     { IDC_FILEDBG_TXT_ATTRIBMOD,         fi.AttribLocallyModified },
  246.                     { IDC_FILEDBG_TXT_TIMEMOD,           fi.TimeLocallyModified   },
  247.                     { IDC_FILEDBG_TXT_CREATED,           fi.LocallyCreated        },
  248.                     { IDC_FILEDBG_TXT_DELETED,           fi.LocallyDeleted        },
  249.                     { IDC_FILEDBG_TXT_STALE,             fi.Stale                 },
  250.                     { IDC_FILEDBG_TXT_SPARSE,            fi.Sparse                },
  251.                     { IDC_FILEDBG_TXT_ORPHAN,            fi.Orphan                },
  252.                     { IDC_FILEDBG_TXT_SUSPECT,           fi.Suspect               },
  253.                     { IDC_FILEDBG_TXT_PINUSER,           fi.HintPinUser           },
  254.                     { IDC_FILEDBG_TXT_PININHERITUSER,    fi.HintPinInheritUser    },
  255.                     { IDC_FILEDBG_TXT_PININHERITSYSTEM,  fi.HintPinInheritSystem  },
  256.                     { IDC_FILEDBG_TXT_CONSERVEBANDWIDTH, fi.HintConserveBandwidth },
  257.                    };
  258.     for (int i = 0; i < ARRAYSIZE(rgStatus); i++)
  259.     {
  260.         PBMF pfn = rgStatus[i].pfn;
  261.         wsprintf(szNumber, TEXT("%d"), (fi.*pfn)());
  262.         SetWindowText(GetDlgItem(hwnd, rgStatus[i].idCtl), szNumber);
  263.     }
  264.     wsprintf(szNumber, TEXT("%d"), fi.PinCount());
  265.     SetWindowText(GetDlgItem(hwnd, IDC_FILEDBG_TXT_PINCOUNT), szNumber);
  266.     SendMessage(GetDlgItem(hwnd, IDC_FILEDBG_ICON), 
  267.                 STM_SETICON,
  268.                 (WPARAM)LoadIcon(m_hInstance, MAKEINTRESOURCE(m_bIsDirectory ? IDI_FOLDER : IDI_DOCUMENT)),
  269.                 0);
  270. }