1、在VC里,要打开一个文件,获取文件路径,只要用CFileDialog类来实现。  
   现在我想让用户选择一个文件夹,获取这个文件夹的路径,应该怎么实现?
   是否有类似CFileDialog选择打开文件的对话框那样,可以选择文件夹的类?2、在局域网内,程序要访问另一台机器某个固定的共享文件,
   如果这台机器启动后未曾访问过那台机器(访问要验证用户名和密码),程序将访问失败! 
   请问在这种情况下能否在程序中验证另一台机器的用户名密码,如何实现?

解决方案 »

  1.   

    1.
    LPMALLOC pMalloc;
      /* Gets the Shell's default allocator */
      if (::SHGetMalloc(&pMalloc) == NOERROR)
      {
          BROWSEINFO bi;
          char pszBuffer[MAX_PATH];
          LPITEMIDLIST pidl;
          // Get help on BROWSEINFO struct - it's got all the bit settings.
          bi.hwndOwner = GetSafeHwnd();
          bi.pidlRoot = NULL;
          bi.pszDisplayName = pszBuffer;
          bi.lpszTitle = _T("get the directory for input");
          bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
          bi.lpfn = NULL;
          bi.lParam = 0;
          // This next call issues the dialog box.
          if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
          {
              if (::SHGetPathFromIDList(pidl, pszBuffer))
              {
                  // At this point pszBuffer contains the selected path */.
                  //DoingSomethingUseful(pszBuffer);
    this->SetDlgItemText (IDC_IN,pszBuffer);          }
              // Free the PIDL allocated by SHBrowseForFolder.
              pMalloc->Free(pidl);
          }
          // Release the shell's allocator.
          pMalloc->Release();
        }
    2.net api,NetShareAdd...
      

  2.   

    1
    http://www.codeguru.com/Cpp/W-D/dislog/   先查看Dialog for selecting folders类2
    DWORD WNetAddConnection2(
      LPNETRESOURCE lpNetResource,  // connection details
      LPCTSTR lpPassword,           // password
      LPCTSTR lpUsername,           // user name
      DWORD dwFlags                 // connection options
    );
    -------------
    lpLocalName :Points to a null-terminated string that specifies the name of a local device to redirect, such as "F:" or "LPT1". The string is treated in a case-insensitive manner. 
    If the string is empty, or if lpLocalName is NULL, the function makes a connection to the network resource without redirecting a local device.