V
V
Vyacheslav Bobrov2016-05-23 16:04:55
C++ / C#
Vyacheslav Bobrov, 2016-05-23 16:04:55

SHBrowseForFolder how to force to display computer name?

There is a function to call a dialog box in which the computer name is selected. After that, a window should appear with a message that such a computer is selected.

bool GetFolder(LPTSTR szPath)
{
  szPath[0] = 0;
  bool result = false;
  LPMALLOC pMalloc;
  if (::SHGetMalloc(&pMalloc) == NOERROR) {
    BROWSEINFO bi = { 0 };
    ::ZeroMemory(&bi, sizeof bi);
    bi.lpszTitle = L"Выберите компьютер для подключения";
    bi.ulFlags =  BIF_BROWSEFORCOMPUTER;// BIF_RETURNONLYFSDIRS;
    LPITEMIDLIST pidl =  ::SHBrowseForFolder(&bi); // 
    if (pidl != NULL) {
      if (::SHGetPathFromIDList(pidl, szPath))
        result = true;
      pMalloc->Free(pidl);
    }
    pMalloc->Release();
  }
  return result;
}

The function works great with folders on the local computer. But here the name of the network computer does not show.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2016-05-25
@crazy_prog

Do you still need to complete the task? and I hope you #include included?
//------------------------------------------------ ---------------------------
#define NO_WIN32_LEAN_AND_MEAN
#include
#include
#include
#pragma hdrstop
#include "Unit1.h"
//-- -------------------------------------------------- -----------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//------------------------------------------------ ---------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//------------------------------------------------ ---------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
BROWSEINFO info;
char szDir[MAX_PATH];
char szDisplayName[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;
if(SHGetMalloc(&pShellMalloc) == NO_ERROR)
{
memset(&info, 0x00,sizeof(info));
//info.hwndOwner = Handle;
info.pidlRoot = 0;
info.pszDisplayName = szDisplayName;
info.lpszTitle = "Browse Title";
info.ulFlags = BIF_BROWSEFORCOMPUTER;
info.lpfn = 0;
pidl = SHBrowseForFolder(&info);
if(pidl)
{
if(SHGetPathFromIDList(pidl, szDir))
{
Label1->Caption = szDir;
}
Label2->Caption = info.pszDisplayName;
pShellMalloc->Free(pidl);
}
pShellMalloc->Release();
}
}
//---------------------------------------------- ------------------------------
3ca6df9d44d445a0b9e6d5aef88df21a.jpg

V
Vyacheslav Bobrov, 2016-05-25
@sedoi_starik

Selecting directories works. 489f0ad5db6a4dfbb51c668ff28ae76b.png
But here the choice of the network computer is not present.
dc0976e2eb9441a6a0e462f052e5d53a.pngb1b61361924341c58c2646a58dcc2096.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question