home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / mapi / remote.srv / admmbox.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-11  |  57.6 KB  |  1,649 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  File Name 
  4. //      ADMMBOX.CPP
  5. //
  6. //  Description
  7. //
  8. //  Author
  9. //      Irving De la Cruz
  10. //
  11. //  Revision: 1.7
  12. //
  13. // Written for Microsoft Windows Developer Support
  14. // Copyright (c) 1995-1996 Microsoft Corporation. All rights reserved.
  15. //
  16. #include "ADMIN.H"
  17. #include "COMMON.H"
  18.  
  19. extern "C"
  20. {
  21.     HRESULT WINAPI DisplayMailboxPropSheets
  22.                         (HWND                       hOwnerWnd,
  23.                          POBJECT_INFO               pObjInfo,
  24.                          BOOL                       fCreate);
  25.     BOOL CALLBACK MBProps1DlgProc
  26.                         (HWND                       hDlg, 
  27.                          UINT                       message, 
  28.                          WPARAM                     wParam, 
  29.                          LPARAM                     lParam);
  30.     BOOL CALLBACK MBProps2DlgProc
  31.                         (HWND                       hDlg, 
  32.                          UINT                       message, 
  33.                          WPARAM                     wParam, 
  34.                          LPARAM                     lParam);
  35.     BOOL CALLBACK MBProps3DlgProc
  36.                         (HWND                       hDlg, 
  37.                          UINT                       message, 
  38.                          WPARAM                     wParam, 
  39.                          LPARAM                     lParam);
  40.     BOOL CALLBACK MBProps4DlgProc
  41.                         (HWND                       hDlg, 
  42.                          UINT                       message, 
  43.                          WPARAM                     wParam, 
  44.                          LPARAM                     lParam);
  45.     BOOL CALLBACK MBProps5DlgProc
  46.                         (HWND                       hDlg, 
  47.                          UINT                       message, 
  48.                          WPARAM                     wParam, 
  49.                          LPARAM                     lParam);
  50.     BOOL CALLBACK MBProps6DlgProc
  51.                         (HWND                       hDlg, 
  52.                          UINT                       message, 
  53.                          WPARAM                     wParam, 
  54.                          LPARAM                     lParam);
  55.  
  56.     void WINAPI RemoveSpaces
  57.                         (LPTSTR *                   ppStr,
  58.                          UINT                       uMaxChars);
  59.     HRESULT WINAPI ExportDirectoryToFile
  60.                         (HWND                       hOwnerWnd);
  61.     HRESULT WINAPI ImportDirectoryFromFile
  62.                         (HWND                       hOwnerWnd);
  63. };
  64.  
  65. ///////////////////////////////////////////////////////////////////////////////
  66. //    ExportDirectoryToFile()
  67. //
  68. //    Parameters
  69. //
  70. //    Purpose
  71. //      
  72. //    Return Value
  73. //      
  74. HRESULT WINAPI ExportDirectoryToFile (HWND hOwnerWnd)
  75. {
  76.     LPTSTR szExportFile = (LPTSTR)GetWindowLong (hOwnerWnd, GWL_USERDATA);
  77.     HWND hLabel = GetDlgItem (hOwnerWnd, IDC_MAILBOX_LABEL);
  78.     SetWindowText (hLabel, TEXT(""));
  79.     HRESULT hResult = S_OK;
  80.     long lPipeNum;
  81.     TCHAR achPipeName[128];
  82.     HANDLE hPipe;
  83.     DWORD dwBytesRead, dwBytesWritten;
  84.     AB_ENTRY_INFO abEntry = { 0 };
  85.     char achCRLF[] = "\r\n", achComma[] = ", ", chQuote = '"';
  86.     HANDLE hFile = CreateFile (szExportFile,
  87.                                GENERIC_WRITE,
  88.                                FILE_SHARE_READ,
  89.                                NULL,
  90.                                CREATE_ALWAYS,
  91.                                FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 
  92.                                NULL);
  93.     if (INVALID_HANDLE_VALUE == hFile)
  94.     {
  95.         hResult = HRESULT_FROM_WIN32 (GetLastError());
  96.         goto ExportFinished;
  97.     }
  98.     RpcTryExcept
  99.     {
  100.         hResult = RemoteAdmGetServerMailboxes (&lPipeNum);
  101.         if (!hResult)
  102.         {
  103.             // Construct the download pipe name
  104.             wsprintf (achPipeName, PIPE_NAME_FORMAT, g_szCurrentServer, lPipeNum);
  105.             // Create our endpoint and connect    
  106.             hPipe = CreateFile (achPipeName, 
  107.                                 GENERIC_READ,
  108.                                 0,
  109.                                 NULL,
  110.                                 OPEN_EXISTING,
  111.                                 0,
  112.                                 NULL);
  113.             if (INVALID_HANDLE_VALUE == hPipe)
  114.             {
  115.                 hResult = HRESULT_FROM_WIN32(GetLastError());
  116.             }
  117.         }
  118.     }
  119.     RpcExcept(1)
  120.     {        
  121.         // If we got here is because there was an error while call was made
  122.         // or when it was about to be made.
  123.         hResult = RpcExceptionCode();
  124.         if (RPC_S_SERVER_UNAVAILABLE == hResult)
  125.         {
  126.             hResult = HRESULT_FROM_WIN32(ERROR_HOST_UNREACHABLE);
  127.         }
  128.         else
  129.         {
  130.             hResult = MAKE_HRESULT(1, FACILITY_RPC, hResult);
  131.         }
  132.     }
  133.     RpcEndExcept
  134.     if (!hResult)
  135.     {
  136.         do
  137.         {
  138.             // Read from the pipe
  139.             if (!ReadFile (hPipe, &abEntry, sizeof(AB_ENTRY_INFO), &dwBytesRead, NULL))
  140.             {
  141.                 hResult = HRESULT_FROM_WIN32(GetLastError());
  142.                 if (HRESULT_FROM_WIN32(ERROR_BROKEN_PIPE)   != hResult &&   // For Windows NT
  143.                     HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) != hResult)     // For Windows 95
  144.                 {
  145.                     // There was an error and we can't continue
  146.                     TraceResult ("ExportDirectoryToFile: Failed to read from the source", hResult);
  147.                 }
  148.                 else
  149.                 {
  150.                     // If the pipe was broken, it means the server finished writing
  151.                     // to the it, so we are finished reading from it.
  152.                     hResult = S_OK;
  153.                 }
  154.             }
  155.             else
  156.             {
  157.                 SetWindowText (hLabel, abEntry.Info.MB.szMailboxName);
  158.                 WriteFile (hFile, abEntry.Info.MB.szMailboxName, lstrlen (abEntry.Info.MB.szMailboxName), &dwBytesWritten, NULL);
  159.                 WriteFile (hFile, achComma, 2, &dwBytesWritten, NULL);
  160.                 WriteFile (hFile, abEntry.Info.MB.szFullName, lstrlen (abEntry.Info.MB.szFullName), &dwBytesWritten, NULL);
  161.                 WriteFile (hFile, achComma, 2, &dwBytesWritten, NULL);
  162.                 WriteFile (hFile, abEntry.Info.MB.szJobTitle, lstrlen (abEntry.Info.MB.szJobTitle), &dwBytesWritten, NULL);
  163.                 WriteFile (hFile, achComma, 2, &dwBytesWritten, NULL);
  164.                 WriteFile (hFile, abEntry.Info.MB.szOffice, lstrlen (abEntry.Info.MB.szOffice), &dwBytesWritten, NULL);
  165.                 WriteFile (hFile, achComma, 2, &dwBytesWritten, NULL);
  166.                 WriteFile (hFile, abEntry.Info.MB.szPhone, lstrlen (abEntry.Info.MB.szPhone), &dwBytesWritten, NULL);
  167.                 WriteFile (hFile, achComma, 2, &dwBytesWritten, NULL);
  168.                 WriteFile (hFile, abEntry.Info.MB.szCompany, lstrlen (abEntry.Info.MB.szCompany), &dwBytesWritten, NULL);
  169.                 WriteFile (hFile, achComma, 2, &dwBytesWritten, NULL);
  170.                 WriteFile (hFile, abEntry.Info.MB.szDepartment, lstrlen (abEntry.Info.MB.szDepartment), &dwBytesWritten, NULL);
  171.                 WriteFile (hFile, achComma, 2, &dwBytesWritten, NULL);
  172.                 WriteFile (hFile, abEntry.Info.MB.szAltPhone, lstrlen (abEntry.Info.MB.szAltPhone), &dwBytesWritten, NULL);
  173.                 WriteFile (hFile, achComma, 2, &dwBytesWritten, NULL);
  174.                 WriteFile (hFile, abEntry.Info.MB.szFax, lstrlen (abEntry.Info.MB.szFax), &dwBytesWritten, NULL);
  175.                 WriteFile (hFile, achComma, 2, &dwBytesWritten, NULL);
  176.                 WriteFile (hFile, abEntry.Info.MB.szComments, lstrlen (abEntry.Info.MB.szComments), &dwBytesWritten, NULL);
  177.  
  178.                 WriteFile (hFile, achCRLF, 2, &dwBytesWritten, NULL);
  179.             }
  180.             if (AbortRemoteCall())
  181.             {
  182.                 break; // Out of the DO-WHILE() loop
  183.             }
  184.         } while (dwBytesRead && !hResult);
  185.         CloseHandle (hPipe);
  186.     }
  187.     CloseHandle (hFile);
  188.     SetWindowText (hLabel, TEXT("Done!"));
  189. ExportFinished:
  190.     PostMessage (hOwnerWnd, WM_WINDS_EXPORT_FINISHED, hResult, 0);
  191.     return hResult;
  192. }
  193.  
  194. ///////////////////////////////////////////////////////////////////////////////
  195. //    ImportDirectoryFromFile()
  196. //
  197. //    Parameters
  198. //
  199. //    Purpose
  200. //      
  201. //    Return Value
  202. //      
  203. HRESULT WINAPI ImportDirectoryFromFile (HWND hOwnerWnd)
  204. {
  205.     LPTSTR szImportFile = (LPTSTR)GetWindowLong (hOwnerWnd, GWL_USERDATA);
  206.     HWND hLabel = GetDlgItem (hOwnerWnd, IDC_MAILBOX_LABEL);
  207.     SetWindowText (hLabel, TEXT(""));
  208.     HWND hListBox = GetDlgItem (hOwnerWnd, IDC_IMPORT_LIST);
  209.     TCHAR szBuffer[256];
  210.     
  211.     MAILBOX_INFO MB = { 0 };
  212.     DWORD i, dwBytesRead = 1;
  213.     TCHAR achBuffer[4096], *szSubStr, achEmpty[] = TEXT("");
  214.     HRESULT hResult = S_OK;
  215.     HANDLE hFile = CreateFile (szImportFile,
  216.                                GENERIC_READ,
  217.                                FILE_SHARE_READ,
  218.                                NULL,
  219.                                OPEN_EXISTING,
  220.                                FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 
  221.                                NULL);
  222.     if (INVALID_HANDLE_VALUE == hFile)
  223.     {
  224.         hResult = HRESULT_FROM_WIN32(GetLastError());
  225.         goto ImportFinished;
  226.     }
  227.     do
  228.     {
  229.         ZeroMemory (achBuffer, sizeof(achBuffer));
  230.         ZeroMemory (&MB, sizeof(MAILBOX_INFO));
  231.         for (i=0; i<4096 && !hResult && dwBytesRead; i++)
  232.         {
  233.             if (!ReadFile (hFile, &(achBuffer[i]), 1, &dwBytesRead, NULL))
  234.             {
  235.                 hResult = HRESULT_FROM_WIN32(GetLastError());
  236.                 TraceResult ("ImportDirectoryToFile: Failed to read from the source", hResult);
  237.             }
  238.             else
  239.             {
  240.                 if (achBuffer[i] == '\n')
  241.                 {
  242.                     break;  // Out of the FOR() loop
  243.                 }
  244.             }
  245.         }
  246.         i = lstrlen(achBuffer);
  247.         if (hResult || (!dwBytesRead && 0 == i))
  248.         {
  249.             break;
  250.         }
  251.         if (i>1 && '\n' == achBuffer[i - 1])
  252.         {
  253.             achBuffer[i - 1] = 0;
  254.         }
  255.         if (i>2 && '\r' == achBuffer[i - 2])
  256.         {
  257.             achBuffer[i - 2] = 0;
  258.         }
  259.         
  260.         if (AbortRemoteCall())
  261.         {
  262.             break; // Out of the DO-WHILE() loop
  263.         }
  264.         
  265.         // Get the ALIAS of the mailbox
  266.         szSubStr = strtok (achBuffer, ",");
  267.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  268.         RemoveSpaces (&szSubStr, MAX_ALIAS_SIZE);
  269.         SetWindowText (hLabel, szSubStr);
  270.         if (!IsObjAliasValid (NULL, szSubStr))
  271.         {
  272.             wsprintf (szBuffer, TEXT("%s\tFAILED: Invalid object alias name"), szSubStr);
  273.             ListBox_AddString (hListBox, szBuffer);
  274.             continue;
  275.         }
  276.         lstrcpy (MB.szMailboxName, szSubStr);
  277.         CharUpper (MB.szMailboxName);
  278.  
  279.         // Get the FULL NAME of the mailbox owner
  280.         szSubStr = strtok (NULL, ",");
  281.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  282.         RemoveSpaces (&szSubStr, MAX_STRING_SIZE);
  283.         lstrcpy (MB.szFullName, szSubStr);
  284.  
  285.         // Get the JOB TITLE of the mailbox owner
  286.         szSubStr = strtok (NULL, ",");
  287.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  288.         RemoveSpaces (&szSubStr, MAX_STRING_SIZE);
  289.         lstrcpy (MB.szJobTitle, szSubStr);
  290.  
  291.         // Get the OFFICE LOCATION of the mailbox owner
  292.         szSubStr = strtok (NULL, ",");
  293.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  294.         RemoveSpaces (&szSubStr, MAX_STRING_SIZE);
  295.         lstrcpy (MB.szOffice, szSubStr);
  296.  
  297.         // Get the PHONE NUMBER of the mailbox owner
  298.         szSubStr = strtok (NULL, ",");
  299.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  300.         RemoveSpaces (&szSubStr, MAX_PHONE_SIZE);
  301.         lstrcpy (MB.szPhone, szSubStr);
  302.         
  303.         // Get the COMPANY of the mailbox owner
  304.         szSubStr = strtok (NULL, ",");
  305.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  306.         RemoveSpaces (&szSubStr, MAX_STRING_SIZE);
  307.         lstrcpy (MB.szCompany, szSubStr);
  308.         
  309.         // Get the DEPARTMENT of the mailbox owner
  310.         szSubStr = strtok (NULL, ",");
  311.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  312.         RemoveSpaces (&szSubStr, MAX_STRING_SIZE);
  313.         lstrcpy (MB.szDepartment, szSubStr);
  314.  
  315.         // Get the ALTERNATE PHONE NUMBER of the mailbox owner
  316.         szSubStr = strtok (NULL, ",");
  317.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  318.         RemoveSpaces (&szSubStr, MAX_PHONE_SIZE);
  319.         lstrcpy (MB.szAltPhone, szSubStr);
  320.         
  321.         // Get the FAX NUMBER of the mailbox owner
  322.         szSubStr = strtok (NULL, ",");
  323.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  324.         RemoveSpaces (&szSubStr, MAX_PHONE_SIZE);
  325.         lstrcpy (MB.szFax, szSubStr);
  326.         
  327.         // Get the COMMENTS of the mailbox
  328.         szSubStr = strtok (NULL, ",");
  329.         if (NULL == szSubStr) { szSubStr = achEmpty; }
  330.         RemoveSpaces (&szSubStr, MAX_COMMENT_SIZE);
  331.         lstrcpy (MB.szComments, szSubStr);
  332.  
  333.         lstrcpy (MB.szPassword, TEXT("PASSWORD"));
  334.         
  335.         if (AbortRemoteCall())
  336.         {
  337.             break; // Out of the DO-WHILE() loop
  338.         }
  339.         RpcTryExcept
  340.         {
  341.             hResult = RemoteAdmCreateMailbox ((ADM_MAILBOX_INFO*)&MB);
  342.         }
  343.         RpcExcept(1)
  344.         {        
  345.             // If we got here is because there was an error while call was made
  346.             // or when it was about to be made.
  347.             hResult = RpcExceptionCode();
  348.             if (RPC_S_SERVER_UNAVAILABLE == hResult)
  349.             {
  350.                 hResult = HRESULT_FROM_WIN32(ERROR_HOST_UNREACHABLE);
  351.             }
  352.             else
  353.             {
  354.                 hResult = MAKE_HRESULT(1, FACILITY_RPC, hResult);
  355.             }
  356.         }
  357.         RpcEndExcept
  358.         if (hResult)
  359.         {
  360.             if (HRESULT_FROM_WIN32(ERROR_USER_EXISTS) == hResult)
  361.             {
  362.                 wsprintf (szBuffer, TEXT("%s\tFAILED: The object already exists in the directory"), MB.szMailboxName);
  363.             }
  364.             else
  365.             {
  366.                 wsprintf (szBuffer, TEXT("%s\tFAILED: Error %X"), MB.szMailboxName, hResult);
  367.             }
  368.         }
  369.         else
  370.         {
  371.             lstrcpy (szBuffer, MB.szMailboxName);
  372.             lstrcat (szBuffer, TEXT("\tSuccessfully Imported"));
  373.         }
  374.         ListBox_AddString (hListBox, szBuffer);
  375.  
  376.         if (hResult &&
  377.             hResult != HRESULT_FROM_WIN32(ERROR_HOST_UNREACHABLE) &&
  378.             HRESULT_FACILITY(hResult) != FACILITY_RPC)
  379.         {
  380.             hResult = S_OK;
  381.         }
  382.         if (AbortRemoteCall())
  383.         {
  384.             break; // Out of the DO-WHILE() loop
  385.         }
  386.     } while (!hResult && dwBytesRead);
  387.     CloseHandle (hFile);
  388.     SetWindowText (hLabel, TEXT("Done!"));
  389. ImportFinished:
  390.     PostMessage (hOwnerWnd, WM_WINDS_IMPORT_FINISHED, hResult, 0);
  391.     return hResult;
  392. }
  393.  
  394. ///////////////////////////////////////////////////////////////////////////////
  395. //    RemoveSpaces()
  396. //
  397. //    Parameters
  398. //      
  399. //    Purpose
  400. //      
  401. //    Return Value
  402. //      
  403. void WINAPI RemoveSpaces (LPTSTR * ppStr, UINT uMaxChars)
  404. {
  405.     LPTSTR pStr = *ppStr;
  406.     // On an empty string, return. Nothing to do here
  407.     if (0 == *pStr) 
  408.     {
  409.         return;
  410.     }
  411.     while (' ' == *pStr || '\t' == *pStr)
  412.     {
  413.         pStr++;
  414.     }
  415.     *ppStr = pStr;
  416.     // On an empty string or a single chracter stringm, return.
  417.     int i = lstrlen (pStr);
  418.     if (0 == *pStr || i < 2)
  419.     {
  420.         return;
  421.     }
  422.     pStr = &(pStr[i]);
  423.     while (' ' == *pStr || '\t' == *pStr || NULL == *pStr)
  424.     {
  425.         *pStr = NULL;
  426.         pStr--;
  427.     }
  428.     if (uMaxChars < (UINT)lstrlen (*ppStr))
  429.     {
  430.         (*ppStr)[uMaxChars] = NULL;
  431.     }
  432. }
  433.  
  434. ///////////////////////////////////////////////////////////////////////////////
  435. //    CreateNewMailbox()
  436. //
  437. //    Parameters
  438. //      
  439. //    Purpose
  440. //      
  441. //    Return Value
  442. //      
  443. void WINAPI CreateNewMailbox (HWND hOwnerWnd)
  444. {
  445.     OBJECT_INFO ObjInfo = { 0 };
  446.     lstrcpy (ObjInfo.MB.szPassword, TEXT("PASSWORD"));
  447.     ObjInfo.Type = SERVER_USER_MAILBOX;
  448.     HRESULT hResult = DisplayMailboxPropSheets (hOwnerWnd, &ObjInfo, TRUE);
  449.     if (!hResult)
  450.     {
  451.         RpcTryExcept
  452.         {
  453.             hResult = RemoteAdmCreateMailbox ((ADM_MAILBOX_INFO*)&ObjInfo.MB);
  454.         }
  455.         RpcExcept(1)
  456.         {        
  457.             // If we got here is because there was an error while call was made
  458.             // or when it was about to be made.
  459.             hResult = RpcExceptionCode();
  460.             if (RPC_S_SERVER_UNAVAILABLE == hResult)
  461.             {
  462.                 hResult = HRESULT_FROM_WIN32(ERROR_HOST_UNREACHABLE);
  463.             }
  464.             else
  465.             {
  466.                 hResult = MAKE_HRESULT(1, FACILITY_RPC, hResult);
  467.             }
  468.         }
  469.         RpcEndExcept
  470.     }
  471.     else
  472.     {
  473.         if (S_FALSE == hResult)
  474.         {
  475.             hResult = S_OK;
  476.         }
  477.     }
  478.     if (hResult)
  479.     {
  480.         ErrorHandler (hOwnerWnd, hResult);
  481.     }
  482. }
  483.  
  484. ///////////////////////////////////////////////////////////////////////////////
  485. //    DeleteServerObject()
  486. //
  487. //    Parameters
  488. //      
  489. //    Purpose
  490. //      
  491. //    Return Value
  492. //      
  493. void WINAPI DeleteServerObject (HWND hOwnerWnd, DWORD dwObjID)
  494. {
  495.     if (IDNO == PrivateMessageBox (IDS_MSG_CONFIRM_OBJECT_DELETE,
  496.                                    hOwnerWnd,
  497.                                    MB_YESNO | MB_ICONEXCLAMATION))
  498.     {
  499.         return;
  500.     }
  501.     HRESULT hResult = S_OK;
  502.     RpcTryExcept
  503.     {
  504.         hResult = RemoteAdmDeleteObject (dwObjID);
  505.     }
  506.     RpcExcept(1)
  507.     {        
  508.         // If we got here is because there was an error while call was made
  509.         // or when it was about to be made.
  510.         hResult = RpcExceptionCode();
  511.         if (RPC_S_SERVER_UNAVAILABLE == hResult)
  512.         {
  513.             hResult = HRESULT_FROM_WIN32(ERROR_HOST_UNREACHABLE);
  514.         }
  515.         else
  516.         {
  517.             hResult = MAKE_HRESULT(1, FACILITY_RPC, hResult);
  518.         }
  519.     }
  520.     RpcEndExcept
  521.     if (hResult)
  522.     {
  523.         ErrorHandler (hOwnerWnd, hResult);
  524.     }
  525. }
  526.  
  527. ///////////////////////////////////////////////////////////////////////////////
  528. //    ShowMailboxProps()
  529. //
  530. //    Parameters
  531. //      
  532. //    Purpose
  533. //      
  534. //    Return Value
  535. //      
  536. void WINAPI ShowMailboxProps (HWND hOwnerWnd, DWORD dwObjID)
  537. {
  538.     OBJECT_INFO ObjInfo = { 0 };
  539.     ObjInfo.MB.dwObjID = dwObjID;
  540.     ObjInfo.Type = SERVER_USER_MAILBOX;
  541.     HRESULT hResult = S_OK;
  542.     DWORD dwObjType;
  543.     RpcTryExcept
  544.     {
  545.         hResult = RemoteAdmGetMailboxProps (dwObjID, &dwObjType, (ADM_MAILBOX_INFO*)&ObjInfo.MB);
  546.     }
  547.     RpcExcept(1)
  548.     {        
  549.         // If we got here is because there was an error while call was made
  550.         // or when it was about to be made.
  551.         hResult = RpcExceptionCode();
  552.         if (RPC_S_SERVER_UNAVAILABLE == hResult)
  553.         {
  554.             hResult = HRESULT_FROM_WIN32(ERROR_HOST_UNREACHABLE);
  555.         }
  556.         else
  557.         {
  558.             hResult = MAKE_HRESULT(1, FACILITY_RPC, hResult);
  559.         }
  560.     }
  561.     RpcEndExcept
  562.     if (!hResult)
  563.     {
  564.         hResult = DisplayMailboxPropSheets (hOwnerWnd, &ObjInfo, FALSE);
  565.         if (S_OK == hResult)
  566.         {
  567.             RpcTryExcept
  568.             {
  569.                 hResult = RemoteAdmSetMailboxProps ((ADM_MAILBOX_INFO*)&ObjInfo.MB);
  570.             }
  571.             RpcExcept(1)
  572.             {        
  573.                 // If we got here is because there was an error while call was made
  574.                 // or when it was about to be made.
  575.                 hResult = RpcExceptionCode();
  576.                 if (RPC_S_SERVER_UNAVAILABLE == hResult)
  577.                 {
  578.                     hResult = HRESULT_FROM_WIN32(ERROR_HOST_UNREACHABLE);
  579.                 }
  580.                 else
  581.                 {
  582.                     hResult = MAKE_HRESULT(1, FACILITY_RPC, hResult);
  583.                 }
  584.             }
  585.             RpcEndExcept
  586.         }
  587.         if (S_FALSE == hResult)
  588.         {
  589.             hResult = S_OK;
  590.         }
  591.     }
  592.     if (hResult)
  593.     {
  594.         ErrorHandler (hOwnerWnd, hResult);
  595.     }
  596. }
  597.  
  598. ///////////////////////////////////////////////////////////////////////////////
  599. //    DisplayMailboxPropSheets()
  600. //
  601. //    Parameters
  602. //      
  603. //    Purpose
  604. //      
  605. //    Return Value
  606. //      
  607. HRESULT WINAPI DisplayMailboxPropSheets (HWND           hOwnerWnd,
  608.                                          POBJECT_INFO   pObjInfo,
  609.                                          BOOL           fCreate)
  610. {
  611.     PROPSHEETHEADER psh = { 0 };
  612.     PROPSHEETPAGE psp[6] = { 0 };
  613.     TCHAR szHeaderTitle[64];
  614.  
  615.     OBJECT_INFO NewObjInfo = *pObjInfo;
  616.  
  617.     psp[0].dwSize      = sizeof(PROPSHEETPAGE);
  618.     psp[0].dwFlags     = PSP_USETITLE;
  619.     psp[0].hInstance   = ghInstance;
  620.     psp[0].pszTemplate = MAKEINTRESOURCE (IDD_MB_PROPS1);
  621.     psp[0].pfnDlgProc  = MBProps1DlgProc;
  622.     psp[0].pszTitle    = TEXT("General");
  623.     psp[0].lParam      = (LPARAM)&NewObjInfo;
  624.     
  625.     psp[1].dwSize      = sizeof(PROPSHEETPAGE);
  626.     psp[1].dwFlags     = PSP_USETITLE;
  627.     psp[1].hInstance   = ghInstance;
  628.     psp[1].pszTemplate = MAKEINTRESOURCE (IDD_MB_PROPS2);
  629.     psp[1].pfnDlgProc  = MBProps2DlgProc;
  630.     psp[1].pszTitle    = TEXT("Phones");
  631.     psp[1].lParam      = (LPARAM)&NewObjInfo;
  632.  
  633.     psp[2].dwSize      = sizeof(PROPSHEETPAGE);
  634.     psp[2].dwFlags     = PSP_USETITLE;
  635.     psp[2].hInstance   = ghInstance;
  636.     psp[2].pszTemplate = MAKEINTRESOURCE (IDD_MB_PROPS3);
  637.     psp[2].pfnDlgProc  = MBProps3DlgProc;
  638.     psp[2].pszTitle    = TEXT("Organization");
  639.     psp[2].lParam      = (LPARAM)&NewObjInfo;
  640.  
  641.     psp[3].dwSize      = sizeof(PROPSHEETPAGE);
  642.     psp[3].dwFlags     = PSP_USETITLE;
  643.     psp[3].hInstance   = ghInstance;
  644.     psp[3].pszTemplate = MAKEINTRESOURCE (IDD_MB_PROPS4);
  645.     psp[3].pfnDlgProc  = MBProps4DlgProc;
  646.     psp[3].pszTitle    = TEXT("Account Security");
  647.     psp[3].lParam      = (LPARAM)&NewObjInfo;
  648.  
  649.     psp[4].dwSize      = sizeof(PROPSHEETPAGE);
  650.     psp[4].dwFlags     = PSP_USETITLE;
  651.     psp[4].hInstance   = ghInstance;
  652.     psp[4].pszTemplate = MAKEINTRESOURCE (IDD_MB_PROPS5);
  653.     psp[4].pfnDlgProc  = MBProps5DlgProc;
  654.     psp[4].pszTitle    = TEXT("Delegate Access");
  655.     psp[4].lParam      = (LPARAM)&NewObjInfo;
  656.  
  657.     psp[5].dwSize      = sizeof(PROPSHEETPAGE);
  658.     psp[5].dwFlags     = PSP_USETITLE;
  659.     psp[5].hInstance   = ghInstance;
  660.     psp[5].pszTemplate = MAKEINTRESOURCE (IDD_MB_PROPS6);
  661.     psp[5].pfnDlgProc  = MBProps6DlgProc;
  662.     psp[5].pszTitle    = TEXT("Auto Reply");
  663.     psp[5].lParam      = (LPARAM)&NewObjInfo;
  664.  
  665.     psh.dwSize     = sizeof(PROPSHEETHEADER);
  666.     psh.dwFlags    = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
  667.     psh.hwndParent = hOwnerWnd;
  668.     psh.hInstance  = ghInstance;
  669.     psh.nPages     = sizeof(psp)/sizeof(PROPSHEETPAGE);
  670.     psh.ppsp       = (LPCPROPSHEETPAGE)&psp;
  671.     if (fCreate)
  672.     {
  673.         psh.pszCaption  = TEXT("New Mailbox Properties");
  674.     }
  675.     else
  676.     {
  677.         wsprintf (szHeaderTitle, TEXT("Mailbox Properties for %s"), pObjInfo->MB.szMailboxName);
  678.         psh.pszCaption  = szHeaderTitle;
  679.     }
  680.  
  681.     // If the user hit OK and at least one of the properties changed,
  682.     // we must change the properties on the server
  683. ReEnterProperties:
  684.     if (1 == PropertySheet (&psh) &&
  685.         (fCreate || 
  686.         (NewObjInfo.MB.dwFlags != pObjInfo->MB.dwFlags ||
  687.          NewObjInfo.MB.dwManagerID != pObjInfo->MB.dwManagerID ||
  688.          lstrcmpi (NewObjInfo.MB.szFullName,    pObjInfo->MB.szFullName) ||
  689.          lstrcmpi (NewObjInfo.MB.szPassword,    pObjInfo->MB.szPassword) ||
  690.          lstrcmpi (NewObjInfo.MB.szJobTitle,    pObjInfo->MB.szJobTitle) ||
  691.          lstrcmpi (NewObjInfo.MB.szOffice,      pObjInfo->MB.szOffice) ||
  692.          lstrcmpi (NewObjInfo.MB.szPhone,       pObjInfo->MB.szPhone) ||
  693.          lstrcmpi (NewObjInfo.MB.szAltPhone,    pObjInfo->MB.szAltPhone) ||
  694.          lstrcmpi (NewObjInfo.MB.szFax,         pObjInfo->MB.szFax) ||
  695.          lstrcmpi (NewObjInfo.MB.szCompany,     pObjInfo->MB.szCompany) ||
  696.          lstrcmpi (NewObjInfo.MB.szDepartment,  pObjInfo->MB.szDepartment) ||
  697.          lstrcmpi (NewObjInfo.MB.szManagerAlias,pObjInfo->MB.szManagerAlias) ||
  698.          lstrcmpi (NewObjInfo.MB.szManagerName,pObjInfo->MB.szManagerName) ||
  699.          lstrcmpi (NewObjInfo.MB.szComments,  pObjInfo->MB.szComments))))
  700.     {
  701.         if (fCreate)
  702.         {
  703.             psh.nStartPage = 0;
  704.             if (!IsObjAliasValid (hOwnerWnd, NewObjInfo.MB.szMailboxName))
  705.             {
  706.                 goto ReEnterProperties;
  707.             }
  708.         }
  709.         if (0 == lstrlen (NewObjInfo.MB.szFullName))
  710.         {
  711.             PrivateMessageBox (IDS_MSG_NO_USER_NAME, hOwnerWnd, 0);
  712.             psh.nStartPage = 0;
  713.             goto ReEnterProperties;
  714.         }
  715.         if (0 == lstrlen (NewObjInfo.MB.szPassword))
  716.         {
  717.             PrivateMessageBox (IDS_MSG_NO_PASSWORD, hOwnerWnd, 0);
  718.             psh.nStartPage = 2;
  719.             goto ReEnterProperties;
  720.         }
  721.         *pObjInfo = NewObjInfo;
  722.         return S_OK;
  723.     }
  724.     return S_FALSE;
  725. }
  726.  
  727. ///////////////////////////////////////////////////////////////////////////////
  728. //    IsObjAliasValid()
  729. //
  730. //    Parameters
  731. //
  732. //    Purpose
  733. //      
  734. //    Return Value
  735. //      
  736. BOOL WINAPI IsObjAliasValid (HWND hOwnerWnd, LPTSTR szObjAlias)
  737. {
  738.     TCHAR achTempAlias[MAX_ALIAS_SIZE+1];
  739.     lstrcpy (achTempAlias, szObjAlias);
  740.     szObjAlias[0] = NULL;
  741.     int iChars = lstrlen (achTempAlias);
  742.     if (0 == iChars)
  743.     {
  744.         if (hOwnerWnd)
  745.         {
  746.             PrivateMessageBox (IDS_MSG_NO_OBJECT_ALIAS, hOwnerWnd, 0);
  747.         }
  748.         return FALSE;
  749.     }
  750.     if (!isalpha (achTempAlias[0]))
  751.     {
  752.         if (hOwnerWnd)
  753.         {
  754.             PrivateMessageBox (IDS_MSG_INVALID_OBJECT_ALIAS, hOwnerWnd, 0);
  755.         }
  756.         return FALSE;
  757.     }
  758.     
  759.     for (int i=1; i<iChars; i++)
  760.     {
  761.         if (!isdigit(achTempAlias[i]) &&
  762.             !isalpha(achTempAlias[i]) &&
  763.             '-' != achTempAlias[i] &&
  764.             '_' != achTempAlias[i])
  765.         {
  766.             if (hOwnerWnd)
  767.             {
  768.                 PrivateMessageBox (IDS_MSG_INVALIS_CHARS_IN_ALIAS, hOwnerWnd, 0);
  769.             }
  770.             return FALSE;
  771.         }
  772.     }
  773.     lstrcpy (szObjAlias, achTempAlias);
  774.     return TRUE;
  775. }
  776.  
  777. ///////////////////////////////////////////////////////////////////////////////
  778. //    MBProps1DlgProc()
  779. //
  780. //    Parameters
  781. //      { Refer to Win32 API documentation on dialog procedures }
  782. //
  783. //    Purpose
  784. //      
  785. //    Return Value
  786. //      TRUE if message was handled, FALSE if we don't handle the message
  787. //      
  788. BOOL CALLBACK MBProps1DlgProc (HWND    hDlg, 
  789.                                UINT    message, 
  790.                                WPARAM  wParam, 
  791.                                LPARAM  lParam)
  792. {
  793.     static POBJECT_INFO pObjInfo = NULL;
  794.     static HWND hAliasLabel;
  795.     switch (message)
  796.     {
  797.         case WM_INITDIALOG :
  798.             {
  799.                 // The pointer to the folder object came in the PROPSHEETPAGE
  800.                 // structure. The lParam of this message has a pointer to the
  801.                 // structure used to create this page. Get the OBJECT_INFO
  802.                 // pointer and save it.
  803.                 pObjInfo = (POBJECT_INFO)((PROPSHEETPAGE *)lParam)->lParam;
  804.                 CTL3D_Subclass(g_pctl3d, hDlg, CTL3D_ALL);
  805.                 HWND hCtl = GetDlgItem (hDlg, IDC_OBJECT_ALIAS);
  806.                 SetWindowText (hCtl, pObjInfo->MB.szMailboxName);
  807.                 if (0 == pObjInfo->MB.dwObjID)
  808.                 {
  809.                     EnableWindow (hCtl, TRUE);
  810.                     Edit_LimitText (hCtl, MAX_ALIAS_SIZE);
  811.                     hCtl = GetDlgItem (hDlg, IDC_OBJECT_ALIAS_LABEL);
  812.                     EnableWindow (hCtl, TRUE);
  813.                 }
  814.  
  815.                 hCtl = GetDlgItem (hDlg, IDC_MAILBOX_OWNER);
  816.                 Edit_LimitText (hCtl, MAX_STRING_SIZE);
  817.                 SetWindowText (hCtl, pObjInfo->MB.szFullName);
  818.  
  819.                 hCtl = GetDlgItem (hDlg, IDC_MAILBOX_JOBTITLE);
  820.                 Edit_LimitText (hCtl, MAX_STRING_SIZE);
  821.                 SetWindowText (hCtl, pObjInfo->MB.szJobTitle);
  822.  
  823.                 hCtl = GetDlgItem (hDlg, IDC_MAILBOX_OFFICE);
  824.                 Edit_LimitText (hCtl, MAX_STRING_SIZE);
  825.                 SetWindowText (hCtl, pObjInfo->MB.szOffice);
  826.  
  827.                 hAliasLabel = GetDlgItem (hDlg, IDC_ICON_TITLE);
  828.                 SetWindowText (hAliasLabel, pObjInfo->MB.szMailboxName);
  829.                 SetWindowFont (hAliasLabel, ghBoldFont, TRUE);
  830.  
  831.                 if (OBJECT_DISABLED & pObjInfo->MB.dwFlags)
  832.                 {
  833.                     Button_SetCheck (GetDlgItem (hDlg, IDC_DISABLE), BST_CHECKED);
  834.                 }
  835.                 if (HIDE_IN_DIR & pObjInfo->MB.dwFlags)
  836.                 {
  837.                     Button_SetCheck (GetDlgItem (hDlg, IDC_HIDE), BST_CHECKED);
  838.                 }
  839.                 Static_SetIcon (GetDlgItem (hDlg, IDC_PAGE_ICON),
  840.                                 ImageList_GetIcon (g_hIconImgs, ICON_MAILBOX, ILD_NORMAL));
  841.             }
  842.             return TRUE;
  843.  
  844.         case WM_NOTIFY :
  845.             if (PSN_APPLY == ((LPNMHDR)lParam)->code)
  846.             {
  847.                 if (BST_CHECKED == Button_GetCheck (GetDlgItem (hDlg, IDC_DISABLE)))
  848.                 {
  849.                     pObjInfo->MB.dwFlags |= OBJECT_DISABLED;
  850.                 }
  851.                 else
  852.                 {
  853.                     pObjInfo->MB.dwFlags &= ~OBJECT_DISABLED;
  854.                 }
  855.                 if (BST_CHECKED == Button_GetCheck (GetDlgItem (hDlg, IDC_HIDE)))
  856.                 {
  857.                     pObjInfo->MB.dwFlags |= HIDE_IN_DIR;
  858.                 }
  859.                 else
  860.                 {
  861.                     pObjInfo->MB.dwFlags &= ~HIDE_IN_DIR;
  862.                 }
  863.                 GetWindowText (GetDlgItem (hDlg, IDC_OBJECT_ALIAS),
  864.                                pObjInfo->MB.szMailboxName,
  865.                                MAX_ALIAS_SIZE+1);
  866.                 GetWindowText (GetDlgItem (hDlg, IDC_MAILBOX_OWNER),
  867.                                pObjInfo->MB.szFullName,
  868.                                MAX_STRING_SIZE+1);
  869.                 GetWindowText (GetDlgItem (hDlg, IDC_MAILBOX_JOBTITLE),
  870.                                pObjInfo->MB.szJobTitle,
  871.                                MAX_STRING_SIZE+1);
  872.                 GetWindowText (GetDlgItem (hDlg, IDC_MAILBOX_OFFICE),
  873.                                pObjInfo->MB.szOffice,
  874.                                MAX_STRING_SIZE+1);
  875.                 
  876.                 return PSNRET_NOERROR;
  877.             }
  878.             break;
  879.  
  880.         case WM_COMMAND :
  881.             if (HIWORD(wParam) == EN_CHANGE && LOWORD(wParam) == IDC_OBJECT_ALIAS)
  882.             {
  883.                 GetWindowText ((HWND)lParam, pObjInfo->MB.szMailboxName, MAX_ALIAS_SIZE+1);
  884.                 SetWindowText (hAliasLabel, pObjInfo->MB.szMailboxName);
  885.             }
  886.             break;
  887.     }
  888.     return FALSE;
  889. }
  890.  
  891. ///////////////////////////////////////////////////////////////////////////////
  892. //    MBProps2DlgProc()
  893. //
  894. //    Parameters
  895. //      { Refer to Win32 API documentation on dialog procedures }
  896. //
  897. //    Purpose
  898. //      
  899. //    Return Value
  900. //      TRUE if message was handled, FALSE if we don't handle the message
  901. //      
  902. BOOL CALLBACK MBProps2DlgProc (HWND    hDlg, 
  903.                                UINT    message, 
  904.                                WPARAM  wParam, 
  905.                                LPARAM  lParam)
  906. {
  907.     static POBJECT_INFO pObjInfo = NULL;
  908.     switch (message)
  909.     {   
  910.         case WM_INITDIALOG :
  911.             {
  912.                 // The pointer to the folder object came in the PROPSHEETPAGE
  913.                 // structure. The lParam of this message has a pointer to the
  914.                 // structure used to create this page. Get the OBJECT_INFO
  915.                 // pointer and save it.
  916.                 pObjInfo = (POBJECT_INFO)((PROPSHEETPAGE *)lParam)->lParam;
  917.                 
  918.                 CTL3D_Subclass(g_pctl3d, hDlg, CTL3D_ALL);
  919.                 HWND hCtl = GetDlgItem (hDlg, IDC_MAILBOX_PHONE);
  920.                 Edit_LimitText (hCtl, MAX_PHONE_SIZE);
  921.                 SetWindowText (hCtl, pObjInfo->MB.szPhone);
  922.  
  923.                 hCtl = GetDlgItem (hDlg, IDC_MAILBOX_FAX);
  924.                 Edit_LimitText (hCtl, MAX_PHONE_SIZE);
  925.                 SetWindowText (hCtl, pObjInfo->MB.szFax);
  926.  
  927.                 hCtl = GetDlgItem (hDlg, IDC_MAILBOX_ALTPHONE);
  928.                 Edit_LimitText (hCtl, MAX_PHONE_SIZE);
  929.                 SetWindowText (hCtl, pObjInfo->MB.szAltPhone);
  930.  
  931.                 hCtl = GetDlgItem (hDlg, IDC_ICON_TITLE);
  932.                 SetWindowText (hCtl, pObjInfo->MB.szMailboxName);
  933.                 SetWindowFont (hCtl, ghBoldFont, TRUE);
  934.                 Static_SetIcon (GetDlgItem (hDlg, IDC_PAGE_ICON),
  935.                                 ImageList_GetIcon (g_hIconImgs, ICON_PHONE_HAND, ILD_NORMAL));
  936.             }
  937.             return TRUE;
  938.  
  939.         case WM_NOTIFY :
  940.             if (PSN_APPLY == ((LPNMHDR)lParam)->code)
  941.             {
  942.                 GetWindowText (GetDlgItem (hDlg, IDC_MAILBOX_PHONE),
  943.                                pObjInfo->MB.szPhone,
  944.                                MAX_PHONE_SIZE+1);
  945.                 GetWindowText (GetDlgItem (hDlg, IDC_MAILBOX_FAX),
  946.                                pObjInfo->MB.szFax,
  947.                                MAX_PHONE_SIZE+1);
  948.                 GetWindowText (GetDlgItem (hDlg, IDC_MAILBOX_ALTPHONE),
  949.                                pObjInfo->MB.szAltPhone,
  950.                                MAX_PHONE_SIZE+1);
  951.                 return PSNRET_NOERROR;
  952.             }
  953.             break;
  954.     }
  955.     return FALSE;
  956. }
  957.  
  958. ///////////////////////////////////////////////////////////////////////////////
  959. //    MBProps3DlgProc()
  960. //
  961. //    Parameters
  962. //      { Refer to Win32 API documentation on dialog procedures }
  963. //
  964. //    Purpose
  965. //      
  966. //    Return Value
  967. //      TRUE if message was handled, FALSE if we don't handle the message
  968. //      
  969. BOOL CALLBACK MBProps3DlgProc (HWND    hDlg, 
  970.                                UINT    message, 
  971.                                WPARAM  wParam, 
  972.                                LPARAM  lParam)
  973. {
  974.     static POBJECT_INFO pObjInfo = NULL;
  975.     switch (message)
  976.     {   
  977.         case WM_INITDIALOG :
  978.             {
  979.                 // The pointer to the folder object came in the PROPSHEETPAGE
  980.                 // structure. The lParam of this message has a pointer to the
  981.                 // structure used to create this page. Get the OBJECT_INFO
  982.                 // pointer and save it.
  983.                 pObjInfo = (POBJECT_INFO)((PROPSHEETPAGE *)lParam)->lParam;
  984.                 
  985.                 CTL3D_Subclass(g_pctl3d, hDlg, CTL3D_ALL);
  986.                 HWND hCtl = GetDlgItem (hDlg, IDC_MAILBOX_PHONE);
  987.                 Edit_LimitText (hCtl, MAX_PHONE_SIZE);
  988.                 SetWindowText (hCtl, pObjInfo->MB.szPhone);
  989.  
  990.                 hCtl = GetDlgItem (hDlg, IDC_COMPANY);
  991.                 Edit_LimitText (hCtl, MAX_STRING_SIZE);
  992.                 SetWindowText (hCtl, pObjInfo->MB.szCompany);
  993.  
  994.                 hCtl = GetDlgItem (hDlg, IDC_DEPARTMENT);
  995.                 Edit_LimitText (hCtl, MAX_STRING_SIZE);
  996.                 SetWindowText (hCtl, pObjInfo->MB.szDepartment);
  997.                 
  998.                 hCtl = GetDlgItem (hDlg, IDC_MANAGER);
  999.                 Edit_LimitText (hCtl, MAX_STRING_SIZE);
  1000.                 SetWindowText (hCtl, pObjInfo->MB.szManagerName);
  1001.  
  1002.                 hCtl = GetDlgItem (hDlg, IDC_MAILBOX_COMMENTS);
  1003.                 Edit_LimitText (hCtl, MAX_COMMENT_SIZE);
  1004.                 SetWindowText (hCtl, pObjInfo->MB.szComments);
  1005.  
  1006.                 
  1007.                 hCtl = GetDlgItem (hDlg, IDC_ICON_TITLE);
  1008.                 SetWindowText (hCtl, pObjInfo->MB.szMailboxName);
  1009.                 SetWindowFont (hCtl, ghBoldFont, TRUE);
  1010.                 Static_SetIcon (GetDlgItem (hDlg, IDC_PAGE_ICON),
  1011.                                 ImageList_GetIcon (g_hIconImgs, ICON_WORLD, ILD_NORMAL));
  1012.             }
  1013.             return TRUE;
  1014.  
  1015.         case WM_NOTIFY :
  1016.             if (PSN_APPLY == ((LPNMHDR)lParam)->code)
  1017.             {
  1018.                 GetWindowText (GetDlgItem (hDlg, IDC_COMPANY),
  1019.                                pObjInfo->MB.szCompany,
  1020.                                MAX_STRING_SIZE+1);
  1021.                 GetWindowText (GetDlgItem (hDlg, IDC_DEPARTMENT),
  1022.                                pObjInfo->MB.szDepartment,
  1023.                                MAX_STRING_SIZE+1);
  1024.                 GetWindowText (GetDlgItem (hDlg, IDC_MAILBOX_COMMENTS),
  1025.                                pObjInfo->MB.szComments,
  1026.                                MAX_COMMENT_SIZE+1);
  1027.                 return PSNRET_NOERROR;
  1028.             }
  1029.             break;
  1030.  
  1031.         case WM_COMMAND :
  1032.             if (LOWORD(wParam) == IDC_BROWSE)
  1033.             {
  1034.                 if (TRUE == DialogBoxParam (ghInstance,
  1035.                                             MAKEINTRESOURCE(IDD_ONE_MAILBOX),
  1036.                                             hDlg,
  1037.                                             SelectUserDlgProc,
  1038.                                             (LPARAM)pObjInfo))
  1039.                 {
  1040.                     SetWindowText (GetDlgItem (hDlg, IDC_MANAGER), pObjInfo->MB.szManagerName);
  1041.                 }
  1042.             }
  1043.             break;
  1044.     }
  1045.     return FALSE;
  1046. }
  1047.  
  1048. ///////////////////////////////////////////////////////////////////////////////
  1049. //    MBProps4DlgProc()
  1050. //
  1051. //    Parameters
  1052. //      { Refer to Win32 API documentation on dialog procedures }
  1053. //
  1054. //    Purpose
  1055. //      
  1056. //    Return Value
  1057. //      TRUE if message was handled, FALSE if we don't handle the message
  1058. //      
  1059. BOOL CALLBACK MBProps4DlgProc (HWND    hDlg, 
  1060.                                UINT    message, 
  1061.                                WPARAM  wParam, 
  1062.                                LPARAM  lParam)
  1063. {
  1064.     static POBJECT_INFO pObjInfo = NULL;
  1065.     switch (message)
  1066.     {   
  1067.         case WM_INITDIALOG :
  1068.             {
  1069.                 // The pointer to the folder object came in the PROPSHEETPAGE
  1070.                 // structure. The lParam of this message has a pointer to the
  1071.                 // structure used to create this page. Get the OBJECT_INFO
  1072.                 // pointer and save it.
  1073.                 pObjInfo = (POBJECT_INFO)((PROPSHEETPAGE *)lParam)->lParam;
  1074.                 CTL3D_Subclass(g_pctl3d, hDlg, CTL3D_ALL);
  1075.                 HWND hCtl = GetDlgItem (hDlg, IDC_MAILBOX_PASSWORD);
  1076.                 Edit_LimitText (hCtl, MAX_PASSWORD_SIZE);
  1077.                 SetWindowText (hCtl, pObjInfo->MB.szPassword);
  1078.  
  1079.                 hCtl = GetDlgItem (hDlg, IDC_ICON_TITLE);
  1080.                 SetWindowText (hCtl, pObjInfo->MB.szMailboxName);
  1081.                 SetWindowFont (hCtl, ghBoldFont, TRUE);
  1082.                 Static_SetIcon (GetDlgItem (hDlg, IDC_PAGE_ICON),
  1083.                                 ImageList_GetIcon (g_hIconImgs, ICON_KEY, ILD_NORMAL));
  1084.             }
  1085.             return TRUE;
  1086.  
  1087.         case WM_NOTIFY :
  1088.             if (PSN_APPLY == ((LPNMHDR)lParam)->code)
  1089.             {
  1090.                 GetWindowText (GetDlgItem (hDlg, IDC_MAILBOX_PASSWORD),
  1091.                                pObjInfo->MB.szPassword,
  1092.                                MAX_STRING_SIZE+1);
  1093.                 return PSNRET_NOERROR;
  1094.             }
  1095.             break;
  1096.     }
  1097.     return FALSE;
  1098. }
  1099.  
  1100. ///////////////////////////////////////////////////////////////////////////////
  1101. //    MBProps5DlgProc()
  1102. //
  1103. //    Parameters
  1104. //      { Refer to Win32 API documentation on dialog procedures }
  1105. //
  1106. //    Purpose
  1107. //      
  1108. //    Return Value
  1109. //      TRUE if message was handled, FALSE if we don't handle the message
  1110. //      
  1111. BOOL CALLBACK MBProps5DlgProc (HWND    hDlg, 
  1112.                                UINT    message, 
  1113.                                WPARAM  wParam, 
  1114.                                LPARAM  lParam)
  1115. {
  1116.     static POBJECT_INFO pObjInfo = NULL;
  1117.     switch (message)
  1118.     {   
  1119.         case WM_INITDIALOG :
  1120.             {
  1121.                 // The pointer to the folder object came in the PROPSHEETPAGE
  1122.                 // structure. The lParam of this message has a pointer to the
  1123.                 // structure used to create this page. Get the OBJECT_INFO
  1124.                 // pointer and save it.
  1125.                 pObjInfo = (POBJECT_INFO)((PROPSHEETPAGE *)lParam)->lParam;
  1126.                 CTL3D_Subclass(g_pctl3d, hDlg, CTL3D_ALL);
  1127.                 HWND hCtl = GetDlgItem (hDlg, IDC_ICON_TITLE);
  1128.                 SetWindowText (hCtl, pObjInfo->MB.szMailboxName);
  1129.                 SetWindowFont (hCtl, ghBoldFont, TRUE);
  1130.  
  1131.                 hCtl = GetDlgItem (hDlg, IDC_NYI_LABEL);
  1132.                 SetWindowFont (hCtl, ghBoldFont, TRUE);
  1133.  
  1134.                 Static_SetIcon (GetDlgItem (hDlg, IDC_PAGE_ICON),
  1135.                                 ImageList_GetIcon (g_hIconImgs, ICON_PEOPLE, ILD_NORMAL));
  1136.                 Static_SetIcon (GetDlgItem (hDlg, IDC_CONSTRUCT_ICON),
  1137.                                 ImageList_GetIcon (g_hIconImgs, ICON_CONSTRUCT, ILD_NORMAL));
  1138.             }
  1139.             return TRUE;
  1140.     }
  1141.     return FALSE;
  1142. }
  1143.  
  1144. ///////////////////////////////////////////////////////////////////////////////
  1145. //    MBProps6DlgProc()
  1146. //
  1147. //    Parameters
  1148. //      { Refer to Win32 API documentation on dialog procedures }
  1149. //
  1150. //    Purpose
  1151. //      
  1152. //    Return Value
  1153. //      TRUE if message was handled, FALSE if we don't handle the message
  1154. //      
  1155. BOOL CALLBACK MBProps6DlgProc (HWND    hDlg, 
  1156.                                UINT    message, 
  1157.                                WPARAM  wParam, 
  1158.                                LPARAM  lParam)
  1159. {
  1160.     static POBJECT_INFO pObjInfo = NULL;
  1161.     switch (message)
  1162.     {   
  1163.         case WM_INITDIALOG :
  1164.             {
  1165.                 // The pointer to the folder object came in the PROPSHEETPAGE
  1166.                 // structure. The lParam of this message has a pointer to the
  1167.                 // structure used to create this page. Get the OBJECT_INFO
  1168.                 // pointer and save it.
  1169.                 pObjInfo = (POBJECT_INFO)((PROPSHEETPAGE *)lParam)->lParam;
  1170.                 CTL3D_Subclass(g_pctl3d, hDlg, CTL3D_ALL);
  1171.                 HWND hCtl = GetDlgItem (hDlg, IDC_ICON_TITLE);
  1172.                 SetWindowText (hCtl, pObjInfo->MB.szMailboxName);
  1173.                 SetWindowFont (hCtl, ghBoldFont, TRUE);
  1174.  
  1175.                 hCtl = GetDlgItem (hDlg, IDC_NYI_LABEL);
  1176.                 SetWindowFont (hCtl, ghBoldFont, TRUE);
  1177.  
  1178.                 Static_SetIcon (GetDlgItem (hDlg, IDC_PAGE_ICON),
  1179.                                 ImageList_GetIcon (g_hIconImgs, ICON_AUTO_REPLY, ILD_NORMAL));
  1180.                 Static_SetIcon (GetDlgItem (hDlg, IDC_CONSTRUCT_ICON),
  1181.                                 ImageList_GetIcon (g_hIconImgs, ICON_CONSTRUCT, ILD_NORMAL));
  1182.             }
  1183.             return TRUE;
  1184.     }
  1185.     return FALSE;
  1186. }
  1187.  
  1188. ///////////////////////////////////////////////////////////////////////////////
  1189. //    GetServerMailboxes()
  1190. //
  1191. //    Parameters
  1192. //
  1193. //    Purpose
  1194. //
  1195. //    Return Value
  1196. //
  1197. HRESULT WINAPI GetServerMailboxes (HWND hOwnerWnd)
  1198. {
  1199.     return DownloadBulkInfo (hOwnerWnd, ghListView, ITEM_SERVER_USER_MAILBOXES);
  1200. }
  1201.  
  1202. ///////////////////////////////////////////////////////////////////////////////
  1203. //    PurgeMailboxMessages()
  1204. //
  1205. //    Parameters
  1206. //      
  1207. //    Purpose
  1208. //      
  1209. //    Return Value
  1210. //      
  1211. void WINAPI PurgeMailboxMessages (HWND hOwnerWnd, DWORD dwObjID)
  1212. {
  1213.     if (IDNO == PrivateMessageBox (IDS_MSG_CONFIRM_MB_MSGS_PURGE,
  1214.                                    hOwnerWnd,
  1215.                                    MB_YESNO | MB_ICONEXCLAMATION))
  1216.     {
  1217.         return;
  1218.     }
  1219.     HRESULT hResult = S_OK;
  1220.     RpcTryExcept
  1221.     {
  1222.         hResult = RemoteAdmEmptyMailbox (dwObjID);
  1223.     }
  1224.     RpcExcept(1)
  1225.     {        
  1226.         // If we got here is because there was an error while call was made
  1227.         // or when it was about to be made.
  1228.         hResult = RpcExceptionCode();
  1229.         if (RPC_S_SERVER_UNAVAILABLE == hResult)
  1230.         {
  1231.             hResult = HRESULT_FROM_WIN32(ERROR_HOST_UNREACHABLE);
  1232.         }
  1233.         else
  1234.         {
  1235.             hResult = MAKE_HRESULT(1, FACILITY_RPC, hResult);
  1236.         }
  1237.     }
  1238.     RpcEndExcept
  1239.     if (hResult)
  1240.     {
  1241.         ErrorHandler (hOwnerWnd, hResult);
  1242.     }
  1243. }
  1244.  
  1245. ///////////////////////////////////////////////////////////////////////////////
  1246. //    BrowseFileName()
  1247. //
  1248. //    Parameters
  1249. //      
  1250. //    Purpose
  1251. //      
  1252. //    Return Value
  1253. //      
  1254. BOOL WINAPI BrowseFileName (HWND hOwnerWnd, LPTSTR szFileName, BOOL fImport)
  1255. {
  1256.     szFileName[0] = NULL;
  1257.     // Filter for files for the browse file dialog box
  1258.     static LPTSTR szFilter = TEXT("Comma Delimeted (*.CSV)\0*.CSV\0All Files (*.*)\0*.*\0");
  1259.     OPENFILENAME ofn = { 0 };
  1260.     ofn.lStructSize  = sizeof(OPENFILENAME);
  1261.     ofn.hwndOwner    = hOwnerWnd;
  1262.     ofn.hInstance    = ghInstance;
  1263.     ofn.lpstrFilter  = szFilter;
  1264.     ofn.nFilterIndex = 1;
  1265.     ofn.lpstrFile    = szFileName;
  1266.     ofn.nMaxFile     = _MAX_PATH;
  1267.     ofn.lpstrTitle   = TEXT("WINDS Administrator - File Browse");
  1268.     ofn.lpstrDefExt  = TEXT("*.CSV");
  1269.     if (fImport)
  1270.     {
  1271.         ofn.Flags = OFN_HIDEREADONLY |
  1272.                     OFN_PATHMUSTEXIST |
  1273.                     OFN_FILEMUSTEXIST;
  1274.     }
  1275.     else
  1276.     {
  1277.         ofn.Flags = OFN_HIDEREADONLY |
  1278.                     OFN_OVERWRITEPROMPT |
  1279.                     OFN_CREATEPROMPT    |
  1280.                     OFN_NOREADONLYRETURN;
  1281.     }
  1282.     
  1283.     BOOL fReturn; 
  1284.     if (fImport)
  1285.     {
  1286.         fReturn = GetOpenFileName (&ofn);
  1287.     }
  1288.     else
  1289.     {
  1290.         fReturn = GetSaveFileName (&ofn);
  1291.     }
  1292.     return fReturn;
  1293. }
  1294.  
  1295. ///////////////////////////////////////////////////////////////////////////////
  1296. //    ExportDlgProc()
  1297. //
  1298. //    Parameters
  1299. //      { Refer to Win32 API documentation on dialog procedures }
  1300. //
  1301. //    Purpose
  1302. //      
  1303. //    Return Value
  1304. //      TRUE if message was handled, FALSE if we don't handle the message
  1305. //      
  1306. BOOL CALLBACK ExportDlgProc (HWND    hDlg, 
  1307.                              UINT    message, 
  1308.                              WPARAM  wParam, 
  1309.                              LPARAM  lParam)
  1310. {
  1311.     static BOOL fMailboxes, fGwayDirs;
  1312.     TCHAR szFile[_MAX_PATH];
  1313.     switch (message)
  1314.     {
  1315.         case WM_INITDIALOG :
  1316.             CenterDialogBox (hDlg);
  1317.             SetFocus (GetDlgItem (hDlg, IDC_BROWSE));
  1318.             Button_SetCheck (GetDlgItem (hDlg, IDC_MAILBOXES), BST_CHECKED);
  1319.             Button_SetCheck (GetDlgItem (hDlg, IDC_GW_DIRECTORIES), BST_CHECKED);
  1320.             fMailboxes = fGwayDirs = TRUE;
  1321.             Static_SetIcon (GetDlgItem (hDlg, IDC_PAGE_ICON),
  1322.                             ImageList_GetIcon (g_hIconImgs, ICON_LABELS, ILD_NORMAL));
  1323.             return TRUE;
  1324.  
  1325.         case WM_COMMAND :
  1326.             switch (LOWORD(wParam))
  1327.             {
  1328.                 case IDC_MAILBOXES :
  1329.                 case IDC_GW_DIRECTORIES :
  1330.                     if (HIWORD(wParam) == BN_CLICKED)
  1331.                     {
  1332.                         if (LOWORD(wParam) == IDC_MAILBOXES)
  1333.                         {
  1334.                             fMailboxes = !fMailboxes;
  1335.                         }
  1336.                         else
  1337.                         {
  1338.                             fGwayDirs = !fGwayDirs;
  1339.                         }
  1340.                         if (fGwayDirs || fMailboxes)
  1341.                         {
  1342.                             EnableWindow (GetDlgItem (hDlg, IDOK), TRUE);
  1343.                         }
  1344.                         else
  1345.                         {
  1346.                             EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
  1347.                         }
  1348.                     }
  1349.                     break;
  1350.  
  1351.                 case IDC_BROWSE :
  1352.                     if (BrowseFileName (hDlg, szFile, FALSE))
  1353.                     {
  1354.                         SetWindowText (GetDlgItem (hDlg, IDC_FILENAME), szFile);
  1355.                     }
  1356.                     break;
  1357.  
  1358.                 case IDOK :
  1359.                     if (!GetWindowText (GetDlgItem (hDlg, IDC_FILENAME), szFile, _MAX_PATH))
  1360.                     {
  1361.                         break;
  1362.                     }
  1363.                     DialogBoxParam (ghInstance,
  1364.                                     MAKEINTRESOURCE (IDD_EXPORT_STATE),
  1365.                                     hDlg,
  1366.                                     ExportProgressDlgProc,
  1367.                                     (LPARAM)szFile);
  1368.                     break;
  1369.  
  1370.                 case IDCANCEL :
  1371.                     EndDialog (hDlg, TRUE);
  1372.                     return TRUE;
  1373.             }
  1374.     }
  1375.     return FALSE;
  1376. }
  1377.  
  1378. ///////////////////////////////////////////////////////////////////////////////
  1379. //    ImportDlgProc()
  1380. //
  1381. //    Parameters
  1382. //      { Refer to Win32 API documentation on dialog procedures }
  1383. //
  1384. //    Purpose
  1385. //      
  1386. //    Return Value
  1387. //      TRUE if message was handled, FALSE if we don't handle the message
  1388. //      
  1389. BOOL CALLBACK ImportDlgProc (HWND    hDlg, 
  1390.                              UINT    message, 
  1391.                              WPARAM  wParam, 
  1392.                              LPARAM  lParam)
  1393. {
  1394.     TCHAR szFile[_MAX_PATH];
  1395.     switch (message)
  1396.     {
  1397.         case WM_INITDIALOG :
  1398.             CenterDialogBox (hDlg);
  1399.             PostMessage (hDlg, WM_COMMAND, IDC_BROWSE, 0);
  1400.             Static_SetIcon (GetDlgItem (hDlg, IDC_PAGE_ICON),
  1401.                             ImageList_GetIcon (g_hIconImgs, ICON_CLIP, ILD_NORMAL));
  1402.             return TRUE;
  1403.  
  1404.         case WM_COMMAND :
  1405.             switch (LOWORD(wParam))
  1406.             {
  1407.                 case IDC_BROWSE :
  1408.                     if (BrowseFileName (hDlg, szFile, TRUE))
  1409.                     {
  1410.                         SetWindowText (GetDlgItem (hDlg, IDC_FILENAME), szFile);
  1411.                     }
  1412.                     break;
  1413.  
  1414.                 case IDOK :
  1415.                     if (!GetWindowText (GetDlgItem (hDlg, IDC_FILENAME), szFile, _MAX_PATH))
  1416.                     {
  1417.                         break;
  1418.                     }
  1419.                     DialogBoxParam (ghInstance,
  1420.                                     MAKEINTRESOURCE (IDD_IMPORT_STATE),
  1421.                                     hDlg,
  1422.                                     ImportProgressDlgProc,
  1423.                                     (LPARAM)szFile);
  1424.                     break;
  1425.  
  1426.                 case IDCANCEL :
  1427.                     EndDialog (hDlg, TRUE);
  1428.                     return TRUE;
  1429.             }
  1430.     }
  1431.     return FALSE;
  1432. }
  1433.  
  1434. ///////////////////////////////////////////////////////////////////////////////
  1435. //    ImportProgressDlgProc()
  1436. //
  1437. //    Parameters
  1438. //      { Refer to Win32 API documentation on dialog procedures }
  1439. //
  1440. //    Purpose
  1441. //      
  1442. //    Return Value
  1443. //      TRUE if message was handled, FALSE if we don't handle the message
  1444. //      
  1445. BOOL CALLBACK ImportProgressDlgProc (HWND    hDlg, 
  1446.                                      UINT    message, 
  1447.                                      WPARAM  wParam, 
  1448.                                      LPARAM  lParam)
  1449. {
  1450.     switch (message)
  1451.     {
  1452.         case WM_INITDIALOG :
  1453.             {
  1454.                 SetWindowLong (hDlg, GWL_USERDATA, (long)lParam);
  1455.                 CTL3D_Subclass(g_pctl3d, hDlg, CTL3D_ALL);
  1456.                 
  1457.                 Static_SetIcon (GetDlgItem (hDlg, IDC_STOPWATCH), GetAnimatedTimerCursor());
  1458.                 
  1459.                 SetWindowFont (GetDlgItem (hDlg, IDC_ICON_TITLE), ghBoldFont, FALSE);
  1460.                 SetWindowFont (GetDlgItem (hDlg, IDC_MAILBOX_LABEL), ghBoldFont, FALSE);
  1461.  
  1462.                 int nTabStops[1] = { 80 };
  1463.                 ListBox_SetTabStops (GetDlgItem (hDlg, IDC_IMPORT_LIST), sizeof(nTabStops)/sizeof(int), nTabStops);
  1464.  
  1465.                 PostMessage (hDlg, WM_WINDS_IMPORT_START, 0, 0);
  1466.             }
  1467.             return TRUE;
  1468.  
  1469.         case WM_WINDS_IMPORT_START :
  1470.             {
  1471.                 DWORD dwThreadID;
  1472.                 HANDLE hThread = CreateThread (NULL,
  1473.                                                0,
  1474.                                                (LPTHREAD_START_ROUTINE)ImportDirectoryFromFile,
  1475.                                                (LPVOID)hDlg,
  1476.                                                0,
  1477.                                                &dwThreadID);
  1478.                 if (hThread)
  1479.                 {
  1480.                     CloseHandle (hThread);
  1481.                 }
  1482.                 else
  1483.                 {
  1484.                     PostMessage (hDlg,
  1485.                                  WM_WINDS_IMPORT_FINISHED,
  1486.                                  HRESULT_FROM_WIN32(GetLastError()),
  1487.                                  0);
  1488.                 }
  1489.             }
  1490.             break;
  1491.  
  1492.         case WM_WINDS_IMPORT_FINISHED :
  1493.             EnableWindow (GetDlgItem (hDlg, IDOK), TRUE);
  1494.             EnableWindow (GetDlgItem (hDlg, IDCANCEL), FALSE);
  1495.             Static_SetIcon (GetDlgItem (hDlg, IDC_STOPWATCH),
  1496.                             ImageList_GetIcon (g_hIconImgs, ICON_TIMEUP, ILD_NORMAL));
  1497.             if (wParam)
  1498.             {
  1499.                 ErrorHandler (hDlg, wParam);
  1500.             }
  1501.             break;
  1502.  
  1503.         case WM_COMMAND :
  1504.             switch (LOWORD(wParam))
  1505.             {
  1506.                 case IDCANCEL :
  1507.                     SetEvent (ghCancelEvent);
  1508.                     break;
  1509.  
  1510.                 case IDOK :
  1511.                     EndDialog (hDlg, TRUE);
  1512.                     return TRUE;
  1513.             }
  1514.     }
  1515.     return FALSE;
  1516. }
  1517.  
  1518. ///////////////////////////////////////////////////////////////////////////////
  1519. //    ExportProgressDlgProc()
  1520. //
  1521. //    Parameters
  1522. //      { Refer to Win32 API documentation on dialog procedures }
  1523. //
  1524. //    Purpose
  1525. //      
  1526. //    Return Value
  1527. //      TRUE if message was handled, FALSE if we don't handle the message
  1528. //      
  1529. BOOL CALLBACK ExportProgressDlgProc (HWND    hDlg, 
  1530.                                      UINT    message, 
  1531.                                      WPARAM  wParam, 
  1532.                                      LPARAM  lParam)
  1533. {
  1534.     switch (message)
  1535.     {
  1536.         case WM_INITDIALOG :
  1537.             {
  1538.                 SetWindowLong (hDlg, GWL_USERDATA, (long)lParam);
  1539.                 CTL3D_Subclass(g_pctl3d, hDlg, CTL3D_ALL);
  1540.                 
  1541.                 Static_SetIcon (GetDlgItem (hDlg, IDC_STOPWATCH), GetAnimatedTimerCursor());
  1542.                 
  1543.                 SetWindowFont (GetDlgItem (hDlg, IDC_ICON_TITLE), ghBoldFont, FALSE);
  1544.                 SetWindowFont (GetDlgItem (hDlg, IDC_MAILBOX_LABEL), ghBoldFont, FALSE);
  1545.  
  1546.                 PostMessage (hDlg, WM_WINDS_EXPORT_START, 0, 0);
  1547.             }
  1548.             return TRUE;
  1549.  
  1550.         case WM_WINDS_EXPORT_START :
  1551.             {
  1552.                 DWORD dwThreadID;
  1553.                 HANDLE hThread = CreateThread (NULL,
  1554.                                                0,
  1555.                                                (LPTHREAD_START_ROUTINE)ExportDirectoryToFile,
  1556.                                                (LPVOID)hDlg,
  1557.                                                0,
  1558.                                                &dwThreadID);
  1559.                 if (hThread)
  1560.                 {
  1561.                     CloseHandle (hThread);
  1562.                 }
  1563.                 else
  1564.                 {
  1565.                     PostMessage (hDlg,
  1566.                                  WM_WINDS_EXPORT_FINISHED,
  1567.                                  HRESULT_FROM_WIN32(GetLastError()),
  1568.                                  0);
  1569.                 }
  1570.             }
  1571.             break;
  1572.  
  1573.         case WM_WINDS_EXPORT_FINISHED :
  1574.             TraceMessage ("Export Finished");
  1575.             EnableWindow (GetDlgItem (hDlg, IDOK), TRUE);
  1576.             EnableWindow (GetDlgItem (hDlg, IDCANCEL), FALSE);
  1577.             Static_SetIcon (GetDlgItem (hDlg, IDC_STOPWATCH),
  1578.                             ImageList_GetIcon (g_hIconImgs, ICON_TIMEUP, ILD_NORMAL));
  1579.             if (wParam)
  1580.             {
  1581.                 ErrorHandler (hDlg, wParam);
  1582.             }
  1583.             break;
  1584.  
  1585.         case WM_COMMAND :
  1586.             switch (LOWORD(wParam))
  1587.             {
  1588.                 case IDCANCEL :
  1589.                     SetEvent (ghCancelEvent);
  1590.                     break;
  1591.  
  1592.                 case IDOK :
  1593.                     EndDialog (hDlg, TRUE);
  1594.                     return TRUE;
  1595.             }
  1596.     }
  1597.     return FALSE;
  1598. }
  1599.  
  1600. ///////////////////////////////////////////////////////////////////////////////
  1601. //    GetAnimatedTimerCursor()
  1602. //
  1603. //    Parameters
  1604. //
  1605. //    Purpose
  1606. //      
  1607. //    Return Value
  1608. //      
  1609. HCURSOR WINAPI GetAnimatedTimerCursor()
  1610. {
  1611.     static HCURSOR hCursor = NULL;
  1612.     if (hCursor)
  1613.     {
  1614.         return hCursor;
  1615.     }
  1616.     HMODULE hModule;
  1617.     HRSRC hResource;
  1618.     DWORD dwBytes, dwSize;
  1619.     TCHAR szANIFile[MAX_PATH];
  1620.     GetTempPath (MAX_PATH, szANIFile);
  1621.     lstrcat (szANIFile, TEXT("__WINDS_TIMER__CURSOR.ANI"));
  1622.     HANDLE hResBits, hFile = CreateFile (szANIFile,
  1623.                                          GENERIC_WRITE,
  1624.                                          0,
  1625.                                          NULL,
  1626.                                          CREATE_ALWAYS,
  1627.                                          FILE_ATTRIBUTE_NORMAL,
  1628.                                          NULL);
  1629.     if (INVALID_HANDLE_VALUE == hFile)
  1630.     {   
  1631.         TraceResult ("GetAnimatedTimerCursor: Failed to create temp file", HRESULT_FROM_WIN32(GetLastError()));
  1632.     }
  1633.     else
  1634.     {
  1635.         hModule = GetModuleHandle (NULL);
  1636.         hResource = FindResource (hModule, TEXT("#5000"), RT_RCDATA);
  1637.         hResBits = LoadResource (hModule, hResource);
  1638.         dwSize = SizeofResource (hModule, hResource);
  1639.         WriteFile (hFile, (LPVOID)hResBits, dwSize, &dwBytes, NULL);
  1640.         CloseHandle (hFile);
  1641.         FreeResource (hResource);
  1642.         hCursor = LoadCursorFromFile (szANIFile);
  1643.         DeleteFile (szANIFile);
  1644.     }
  1645.     return hCursor;
  1646. }
  1647.  
  1648. // End of file for ADMMBOX.CPP
  1649.