help.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 7k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //---------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft Corporation 1991-1992
  4. //
  5. // File: help.c
  6. //
  7. // History:
  8. //  6 Apr 94    MikeSh  Created
  9. //
  10. //---------------------------------------------------------------------------
  11. #include "shellprv.h"
  12. #pragma  hdrstop
  13. #include "printer.h"
  14. #include "drives.h" // for ShowMountedVolumeProperties
  15. //
  16. // NOTE: If you change or delete any of these strings, notify the help group
  17. //
  18. static TCHAR szAddPrinter[] = TEXT("AddPrinter");
  19. static TCHAR szConnect[] = TEXT("Connect");
  20. static TCHAR szDisconnect[] = TEXT("Disconnect");
  21. static TCHAR szPrintersFolder[] = TEXT("PrintersFolder");
  22. static TCHAR szFontsFolder[] = TEXT("FontsFolder");
  23. //
  24. // (internal) entry point for Help "Shortcuts".
  25. //
  26. VOID WINAPI SHHelpShortcuts_RunDLL_Common(HWND hwndStub, HINSTANCE hAppInstance, LPCTSTR pszCmdLine, int nCmdShow)
  27. {
  28.     LPITEMIDLIST pidl = NULL;
  29.     if (!lstrcmp(pszCmdLine, szAddPrinter))
  30.     {
  31.         // install a new printer
  32.         pidl = Printers_PrinterSetup(hwndStub, MSP_NEWPRINTER, (LPTSTR)c_szNewObject, NULL);
  33.     }
  34.     else if (!lstrcmp(pszCmdLine, szPrintersFolder))
  35.     {
  36.         // bring up the printers folder
  37.         pidl = SHCloneSpecialIDList(hwndStub, CSIDL_PRINTERS, FALSE);
  38.         goto OpenFolder;
  39.     }
  40.     else if (!lstrcmp(pszCmdLine, szFontsFolder))
  41.     {
  42.         // bring up the printers folder
  43.         pidl = SHCloneSpecialIDList(hwndStub, CSIDL_FONTS, FALSE);
  44. OpenFolder:
  45.         if (pidl)
  46.         {
  47.             CMINVOKECOMMANDINFOEX ici;
  48.             ZeroMemory(&ici, SIZEOF(ici));
  49.             ici.cbSize = SIZEOF(CMINVOKECOMMANDINFOEX);
  50.             ici.hwnd = hwndStub;
  51.             ici.nShow = SW_SHOWNORMAL;
  52.             InvokeFolderCommandUsingPidl(&ici, NULL, pidl, NULL, SEE_MASK_FLAG_DDEWAIT);
  53.         }
  54.     }
  55.     else if (!lstrcmp(pszCmdLine, szConnect))
  56.     {
  57.         SHNetConnectionDialog(hwndStub, NULL, RESOURCETYPE_DISK);
  58.         goto FlushDisconnect;
  59.     }
  60.     else if (!lstrcmp(pszCmdLine, szDisconnect))
  61.     {
  62.         WNetDisconnectDialog(hwndStub, RESOURCETYPE_DISK);
  63. FlushDisconnect:
  64.         SHChangeNotifyHandleEvents();   // flush any drive notifications
  65.     }
  66. #ifdef DEBUG
  67.     else if (!StrCmpN(pszCmdLine, TEXT("PrtProp "), 8))
  68.     {
  69.         SHObjectProperties(hwndStub, SHOP_PRINTERNAME, &(pszCmdLine[8]), TEXT("Sharing"));
  70.     }
  71.     else if (!StrCmpN(pszCmdLine, TEXT("FileProp "), 9))
  72.     {
  73.         SHObjectProperties(hwndStub, SHOP_FILEPATH, &(pszCmdLine[9]), TEXT("Sharing"));
  74.     }
  75. #endif
  76.     else
  77.         DebugMsg(DM_TRACE, TEXT("SHHelpShortcuts: unrecognized command '%s'"), pszCmdLine);
  78.     if (pidl)
  79.         ILFree(pidl);
  80. }
  81. VOID WINAPI SHHelpShortcuts_RunDLL(HWND hwndStub, HINSTANCE hAppInstance, LPCSTR lpszCmdLine, int nCmdShow)
  82. {
  83. #ifdef UNICODE
  84.     UINT iLen = lstrlenA(lpszCmdLine)+1;
  85.     LPWSTR  lpwszCmdLine;
  86.     lpwszCmdLine = (LPWSTR)LocalAlloc(LPTR,iLen*SIZEOF(WCHAR));
  87.     if (lpwszCmdLine)
  88.     {
  89.         MultiByteToWideChar(CP_ACP, 0,
  90.                             lpszCmdLine, -1,
  91.                             lpwszCmdLine, iLen);
  92.         SHHelpShortcuts_RunDLL_Common( hwndStub,
  93.                                        hAppInstance,
  94.                                        lpwszCmdLine,
  95.                                        nCmdShow );
  96.         LocalFree(lpwszCmdLine);
  97.     }
  98. #else
  99.     SHHelpShortcuts_RunDLL_Common(hwndStub,hAppInstance,lpszCmdLine,nCmdShow);
  100. #endif
  101. }
  102. VOID WINAPI SHHelpShortcuts_RunDLLW(HWND hwndStub, HINSTANCE hAppInstance, LPCWSTR lpwszCmdLine, int nCmdShow)
  103. {
  104. #ifdef UNICODE
  105.     SHHelpShortcuts_RunDLL_Common(hwndStub,hAppInstance,lpwszCmdLine,nCmdShow);
  106. #else
  107.     UINT iLen = WideCharToMultiByte(CP_ACP, 0,
  108.                             lpwszCmdLine, -1,
  109.                             NULL, 0, NULL, NULL)+1;
  110.     LPSTR  lpszCmdLine;
  111.     lpszCmdLine = (LPSTR)LocalAlloc(LPTR,iLen);
  112.     if (lpszCmdLine)
  113.     {
  114.         WideCharToMultiByte(CP_ACP, 0,
  115.                             lpwszCmdLine, -1,
  116.                             lpszCmdLine, iLen,
  117.                             NULL, NULL);
  118.         SHHelpShortcuts_RunDLL_Common( hwndStub,
  119.                                        hAppInstance,
  120.                                        lpszCmdLine,
  121.                                        nCmdShow );
  122.         LocalFree(lpszCmdLine);
  123.     }
  124. #endif
  125. }
  126. ///////////////////////////////////////////////////////
  127. //
  128. // SHObjectProperties is an easy way to call the verb "properties" on an object.
  129. // It's easy because the caller doesn't have to deal with LPITEMIDLISTs.
  130. // Note: SHExecuteEx(SEE_MASK_INVOKEIDLIST) works for the SHOP_FILEPATH case,
  131. // but msshrui needs an easy way to do this for printers. Bummer.
  132. //
  133. BOOL WINAPI SHObjectProperties(HWND hwndOwner, DWORD dwType, LPCTSTR lpObject, LPCTSTR lpPage)
  134. {
  135.     LPITEMIDLIST pidl;
  136.     switch (dwType & SHOP_TYPEMASK)
  137.     {
  138.         case SHOP_PRINTERNAME:
  139.             DebugMsg(DM_TRACE, TEXT("SHObjectProperties(SHOP_PRINTERNAME,%s,%s)"),lpObject,lpPage);
  140.             pidl = Printers_GetPidl(NULL, lpObject);
  141.             break;
  142.         case SHOP_FILEPATH:
  143.             DebugMsg(DM_TRACE, TEXT("SHObjectProperties(SHOP_FILEPATH,%s,%s)"),lpObject,lpPage);
  144.             pidl = ILCreateFromPath(lpObject);
  145.             break;
  146. #ifdef WINNT
  147.         case SHOP_VOLUMEGUID:
  148.             {
  149.                 DebugMsg(DM_TRACE, TEXT("SHObjectProperties(SHOP_VOLUMEGUID,%s,%s)"),lpObject,lpPage);
  150.                 return ShowMountedVolumeProperties(lpObject, hwndOwner);
  151.             }
  152.             break;
  153. #endif
  154.         default:
  155.             DebugMsg(TF_WARNING, TEXT("illegal SHObjectProperties type for (%s,%s)"),lpObject,lpPage);
  156.             pidl = NULL;
  157.             break;
  158.     }
  159.     if (pidl)
  160.     {
  161.         SHELLEXECUTEINFO sei =
  162.         {
  163.             SIZEOF(SHELLEXECUTEINFO),
  164.             SEE_MASK_INVOKEIDLIST,      // fMask
  165.             hwndOwner,                  // hwnd
  166.             c_szProperties,             // lpVerb
  167.             NULL,                       // lpFile
  168.             lpPage,                     // lpParameters
  169.             NULL,                       // lpDirectory
  170.             SW_SHOWNORMAL,              // nShow
  171.             NULL,                       // hInstApp
  172.             pidl,                       // lpIDList
  173.             NULL,                       // lpClass
  174.             0,                          // hkeyClass
  175.             0,                          // dwHotKey
  176.             NULL                        // hIcon
  177.         };
  178.         BOOL bRet = ShellExecuteEx(&sei);
  179.         ILFree(pidl);
  180.         return bRet;
  181.     }
  182.     return FALSE;
  183. }