Пример #1
1
//---------------------------------------------------------------------------
// UnregisterServer
//---------------------------------------------------------------------------
BOOL UnregisterServer(CLSID clsid, LPTSTR lpszTitle) {
  TCHAR szCLSID[GUID_SIZE + 1];
  TCHAR szCLSIDKey[GUID_SIZE + 32];
  TCHAR szKeyTemp[MAX_PATH + GUID_SIZE];
  LPWSTR pwsz;

  StringFromIID(clsid, &pwsz);
  if(pwsz) {
#ifdef UNICODE
    lstrcpy(szCLSID, pwsz);
#else
    WideCharToMultiByte(CP_ACP, 0, pwsz, -1, szCLSID, ARRAYSIZE(szCLSID), NULL, NULL);
#endif
    //free the string
    LPMALLOC pMalloc;
    CoGetMalloc(1, &pMalloc);
    pMalloc->Free(pwsz);
    pMalloc->Release();
  }

  lstrcpy(szCLSIDKey, TEXT("CLSID\\"));
  lstrcat(szCLSIDKey, szCLSID);

  wsprintf(szKeyTemp, TEXT("*\\shellex\\ContextMenuHandlers\\%s"), lpszTitle);
  RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);

  wsprintf(szKeyTemp, TEXT("%s\\%s"), szCLSIDKey, TEXT("InprocServer32"));
  RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);
  RegDeleteKey(HKEY_CLASSES_ROOT, szCLSIDKey);

  return TRUE;
}
Пример #2
0
/* #FN#
   Responds to TVN_DELETEITEM message in order to release the memory
   allocated by the shell folders */
void
/* #AS#
   Nothing */
CShellTree::
OnDeleteShellItem(
	NMHDR   *pNMHDR, /* #IN# */
	LRESULT *pResult /* #OUT# */
)
{
	LPTVITEMDATA lptvid   = NULL;
	LPMALLOC     lpMalloc = NULL;
	HRESULT      hr;

	NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW *)pNMHDR;

	/* Let's free the memory for the TreeView item data */
	hr = SHGetMalloc( &lpMalloc );
	if( FAILED(hr) )
		return;

	lptvid = (LPTVITEMDATA)pNMTreeView->itemOld.lParam;
	lptvid->lpsfParent->Release();
	lpMalloc->Free( lptvid->lpi );
	lpMalloc->Free( lptvid->lpifq );
	lpMalloc->Free( lptvid );
	lpMalloc->Release();

} /* #OF# CShellTree::OnDeleteShellItem */
Пример #3
0
bool DirectoryRefDialog(HWND hWnd,char *Result)
{
    bool r = false;
    LPMALLOC Memory;
    LPCSTR Buffer;
    LPITEMIDLIST Ret;
    LPITEMIDLIST Root;
    SHGetMalloc(&Memory);
    Buffer = (LPSTR)Memory->Alloc(1000);
    SHGetSpecialFolderLocation(hWnd,CSIDL_DESKTOP,&Root);
    ZeroMemory(&BI,sizeof(BROWSEINFO));
    BI.hwndOwner = hWnd;
    BI.pidlRoot = Root;
    BI.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS;
    BI.lpszTitle = "展開先を指定してください";
    BI.pszDisplayName = (LPSTR)Buffer;
    BI.lpfn = BrowseCallbackProc;
    Ret = SHBrowseForFolder(&BI);
    if (SHGetPathFromIDList(Ret,(LPSTR)Buffer))
    {
        lstrcpy(Result,Buffer);
        r = true;
    }
    Memory->Free(Ret);
    Memory->Free(Root);
    Memory->Free((void*)Buffer);
    return r;
}
Пример #4
0
// YOU must free the returned string
char * getSpecialFolder (int nFolder, HWND hWnd)
{
    LPMALLOC pMalloc;
    LPITEMIDLIST pidl;

    ArrayPtr<char> str = new char [MAX_PATH + 30];
    if (str == 0)
	throw AppException (WHERE, ERR_OUT_OF_MEMORY);

    if (FAILED (SHGetMalloc (&pMalloc)))
	return NULL;

    if (FAILED (SHGetSpecialFolderLocation (hWnd, nFolder, &pidl))) {
	pMalloc->Release ();
	return NULL;
    }

    if (SHGetPathFromIDList (pidl, str) != TRUE) {
	pMalloc->Free (pidl);
	pMalloc->Release ();
	return NULL;
    }

    pMalloc->Free (pidl);
    pMalloc->Release ();

    return str.detach ();
}
//----------------------------------------------------------------------------------------
static void GetWindowsFolder(int folder, nsFileSpec& outDirectory)
//----------------------------------------------------------------------------------------
{

    if (gGetSpecialPathProc) {
        TCHAR path[MAX_PATH];
        HRESULT result = gGetSpecialPathProc(NULL, path, folder, true);
        
        if (!SUCCEEDED(result)) 
            return;

        // Append the trailing slash
        int len = PL_strlen(path);
        if (len>1 && path[len-1] != '\\') 
        {
            path[len]   = '\\';
            path[len + 1] = '\0';
        }
        outDirectory = path;
        return;
    }

    LPMALLOC pMalloc = NULL;
    LPSTR pBuffer = NULL;
    LPITEMIDLIST pItemIDList = NULL;
    int len;
 
    // Get the shell's allocator. 
    if (!SUCCEEDED(SHGetMalloc(&pMalloc))) 
        return;

    // Allocate a buffer
    if ((pBuffer = (LPSTR) pMalloc->Alloc(MAX_PATH + 2)) == NULL) 
        return; 
 
    // Get the PIDL for the folder. 
    if (!SUCCEEDED(SHGetSpecialFolderLocation( 
            NULL, folder, &pItemIDList)))
        goto Clean;
 
    if (!SUCCEEDED(SHGetPathFromIDList(pItemIDList, pBuffer)))
        goto Clean;

    // Append the trailing slash
    len = PL_strlen(pBuffer);
    pBuffer[len]   = '\\';
    pBuffer[len + 1] = '\0';

    // Assign the directory
    outDirectory = pBuffer;

Clean:
    // Clean up. 
    if (pItemIDList)
        pMalloc->Free(pItemIDList); 
    if (pBuffer)
        pMalloc->Free(pBuffer); 

	pMalloc->Release();
} // GetWindowsFolder
Пример #6
0
void CShellContextMenu::SetObjects(const QStringList &strList)
{
	// free all allocated datas
	if (m_psfFolder && bDelete)
		m_psfFolder->Release ();
	m_psfFolder = NULL;
	FreePIDLArray (m_pidlArray);
	m_pidlArray = NULL;
	
	// get IShellFolder interface of Desktop (root of shell namespace)
	IShellFolder * psfDesktop = NULL;
	SHGetDesktopFolder (&psfDesktop);	// needed to obtain full qualified pidl

	// ParseDisplayName creates a PIDL from a file system path relative to the IShellFolder interface
	// but since we use the Desktop as our interface and the Desktop is the namespace root
	// that means that it's a fully qualified PIDL, which is what we need
	LPITEMIDLIST pidl = NULL;
	
	psfDesktop->ParseDisplayName (NULL, 0, (LPOLESTR)strList[0].utf16(), NULL, &pidl, NULL);

	// now we need the parent IShellFolder interface of pidl, and the relative PIDL to that interface
	LPITEMIDLIST pidlItem = NULL;	// relative pidl
	SHBindToParentEx (pidl, IID_IShellFolder, (void **) &m_psfFolder, NULL);
	free (pidlItem);
	// get interface to IMalloc (need to free the PIDLs allocated by the shell functions)
	LPMALLOC lpMalloc = NULL;
	SHGetMalloc (&lpMalloc);
	lpMalloc->Free (pidl);

	// now we have the IShellFolder interface to the parent folder specified in the first element in strArray
	// since we assume that all objects are in the same folder (as it's stated in the MSDN)
	// we now have the IShellFolder interface to every objects parent folder
	
	IShellFolder * psfFolder = NULL;
	nItems = strList.size ();
	for (int i = 0; i < nItems; i++)
	{
                pidl=0;
		psfDesktop->ParseDisplayName (NULL, 0, (LPOLESTR)strList[i].utf16(), NULL, &pidl, NULL);
                if (pidl)
                {
                     m_pidlArray = (LPITEMIDLIST *) realloc (m_pidlArray, (i + 1) * sizeof (LPITEMIDLIST));
                     // get relative pidl via SHBindToParent
                     SHBindToParentEx (pidl, IID_IShellFolder, (void **) &psfFolder, (LPCITEMIDLIST *) &pidlItem);
                     m_pidlArray[i] = CopyPIDL (pidlItem);	// copy relative pidl to pidlArray
                     free (pidlItem);
                     lpMalloc->Free (pidl);		// free pidl allocated by ParseDisplayName
                     psfFolder->Release ();
                }
	}
	lpMalloc->Release ();
	psfDesktop->Release ();

	bDelete = TRUE;	// indicates that m_psfFolder should be deleted by CShellContextMenu
}
Пример #7
0
// Main routine
CString XSHBrowseForFolder(HWND hwnd,char* title,char* _path) {
  char path[MAX_PATH]; path[0]='\0';

  // Remove the last slash bar
  if (strlen(_path)>0)
  if (_path[strlen(_path)-1]=='\\')
    _path[strlen(_path)-1]='\0';

  // Get IMalloc Interface
  LPMALLOC Mymal;
  if (SHGetMalloc(&Mymal)!=NOERROR)
    return path;
  
  // Build Root directory (My Computer)
  LPITEMIDLIST Mylist;
  if (SHGetSpecialFolderLocation(hwnd,CSIDL_DRIVES,&Mylist)==NOERROR) {

    // Convert _path into browse data
    LPITEMIDLIST MyItemlist=XSHBFF_PathConvert(hwnd,_path);
    
    // Parameter structure for callback
    char Thispath[MAX_PATH]; Thispath[0]='\0';
    LPARAM CParam[2];
    CParam[0]=(LPARAM) MyItemlist;
    CParam[1]=(LPARAM) Thispath;
    // Fill the BROWSEINFO structure
    BROWSEINFO br;
    br.hwndOwner=hwnd;       // hwnd
    br.pidlRoot=NULL;        // root
    br.pszDisplayName=path;  // buffer
    br.lpszTitle=title;      // title
    br.ulFlags=BIF_RETURNONLYFSDIRS;  // dir
    br.lpfn=XSHBFF_CallbackProc;      // callback
    br.lParam=(LPARAM) CParam;          // callback params
    br.iImage=0;             // image
    // And Call SHBrowseForFolder
    LPITEMIDLIST UserList;
    if ( (UserList = SHBrowseForFolder(&br)) != NULL) {
      if (strlen(Thispath)==0) {  // No value in path
        // Convert UserList to a string
        if (SHGetPathFromIDList(UserList,path)==FALSE)
          path[0]='\0';
      } else
        strcpy(path,Thispath);
      Mymal->Free(UserList);
    }
    if (MyItemlist) Mymal->Free(MyItemlist);
    Mymal->Free(Mylist);
  }
  return path;
}
void CBitTorrentSettingsPage::OnTorrentsBrowse() 
{
	TCHAR szPath[MAX_PATH];
	LPITEMIDLIST pPath;
	LPMALLOC pMalloc;
	BROWSEINFO pBI;
		
	ZeroMemory( &pBI, sizeof(pBI) );
	pBI.hwndOwner		= AfxGetMainWnd()->GetSafeHwnd();
	pBI.pszDisplayName	= szPath;
	pBI.lpszTitle		= _T("Select folder for torrents:");
	pBI.ulFlags			= BIF_RETURNONLYFSDIRS;
	
	pPath = SHBrowseForFolder( &pBI );

	if ( pPath == NULL ) return;

	SHGetPathFromIDList( pPath, szPath );
	SHGetMalloc( &pMalloc );
	pMalloc->Free( pPath );
	pMalloc->Release();
	
	UpdateData( TRUE );
	m_sTorrentPath = szPath;
	UpdateData( FALSE );
}
Пример #9
0
void COptFont::OnBrowseFont() 
{
	BROWSEINFO brw;
	LPMALLOC pMalloc;
	LPITEMIDLIST ret;
	char dir[MAX_PATH];

	if (NOERROR == ::SHGetMalloc(&pMalloc) ) {

		m_BrowseFont.GetWindowText(szCacheDir, MAX_PATH);

		memset(&brw, 0, sizeof(BROWSEINFO));
		brw.hwndOwner = this->GetSafeHwnd();
		brw.pszDisplayName = dir;
		brw.lpszTitle = "Select Font Directory...";
		brw.ulFlags = 0L;
		brw.lpfn = LocCbck;

		ret = SHBrowseForFolder(&brw);
		if (ret != NULL) {
			if (::SHGetPathFromIDList(ret, dir)) {
				m_BrowseFont.SetWindowText(dir);
			}
			pMalloc->Free(ret);
		}
		pMalloc->Release();
	}
}
Пример #10
0
bool CComDialog::PopFolderDlg(OUT char* path, IN char* title, IN BFFCALLBACK cb)
{ 
    BROWSEINFO bi;
	ZeroMemory(&bi, sizeof(BROWSEINFO));    

//初始化入口参数bi开始****************************
    bi.hwndOwner = _hwnd;//::AfxGetMainWnd()->GetSafeHwnd();
    bi.pidlRoot = NULL;
    bi.pszDisplayName = path;//此参数如为NULL则不能显示对话框
    bi.lpszTitle = title;
    bi.ulFlags = 0;
    bi.lpfn = cb;
/*    bi.iImage= IDR_MAINFRAME;*/
//初始化入口参数bi结束*****************************

    LPITEMIDLIST pIDList = SHBrowseForFolder(&bi);//调用显示选择对话框
    if (pIDList)
    {
        SHGetPathFromIDList(pIDList, path);
        //取得文件夹路径到Buffer里
		LPMALLOC lpMalloc;
		if (FAILED(SHGetMalloc(&lpMalloc))) 
			return false;
		//释放内存
		lpMalloc->Free(pIDList);
		lpMalloc->Release();

		return true;
    }
	else
	{
		return false;
	}
}
Пример #11
0
bool plBrowseFolder::GetFolder(char *path, const char *startPath, const char *title, HWND hwndOwner)
{
    BROWSEINFO bi;
    memset(&bi, 0, sizeof(bi));
    bi.hwndOwner    = hwndOwner;
    bi.lpszTitle    = title;
    bi.lpfn         = BrowseCallbackProc;
    bi.lParam       = (LPARAM) startPath;

    ITEMIDLIST *iil = SHBrowseForFolder(&bi);
    // Browse failed, or cancel was selected
    if (!iil)
        return false;
    // Browse succeded.  Get the path.
    else
        SHGetPathFromIDList(iil, path);

    // Free the memory allocated by SHBrowseForFolder
    LPMALLOC pMalloc;
    SHGetMalloc(&pMalloc);
    pMalloc->Free(iil);
    pMalloc->Release();

    return true;
}
Пример #12
0
 BOOL	GetSpecialFolder(UINT SpecialFolder, CString &SpecialFolderString)

{
	HRESULT hr;

	LPITEMIDLIST pidl;

	hr = SHGetSpecialFolderLocation(NULL, SpecialFolder, &pidl);

    if(SUCCEEDED(hr))
		{
		// Convert the item ID list's binary representation into a file system path
		char szPath[_MAX_PATH];

		if(SHGetPathFromIDList(pidl, szPath))
			{
			// Allocate a pointer to an IMalloc interface
			LPMALLOC pMalloc;

			// Get the address of our task allocator's IMalloc interface
			hr = SHGetMalloc(&pMalloc);

			// Free the item ID list allocated by SHGetSpecialFolderLocation
			pMalloc->Free(pidl);

			// Free our task allocator
			pMalloc->Release();

			// Work with the special folder's path (contained in szPath)
			SpecialFolderString = szPath;	SpecialFolderString += "\\";
			return TRUE;
			}
		}
	return FALSE;
}
Пример #13
0
void CSettingsDictPage::OnBrowseLocation()
{
	TCHAR szPath[_MAX_PATH];
	CString strTitle = LoadString(IDS_DICT_LOCATION_PROMPT);

	BROWSEINFO info;
	ZeroMemory(&info, sizeof(info));
	info.hwndOwner = m_hWnd;
	info.pszDisplayName = szPath;
	info.lpszTitle = strTitle;
	info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_USENEWUI;
	info.lpfn = BrowseCallbackProc;
	info.lParam = (LPARAM) this;

	LPITEMIDLIST pItem = SHBrowseForFolder(&info);
	if (pItem == NULL)
		return;

	if (SHGetPathFromIDList(pItem, szPath))
	{
		PathRemoveBackslash(szPath);
		m_strDictLocation = szPath;
		UpdateData(false);
	}

	LPMALLOC pMalloc;
	if (SUCCEEDED(SHGetMalloc(&pMalloc)))
		pMalloc->Free(pItem);
}
Пример #14
0
AnsiString PathUtil::GetUserDirectory() {
	AnsiString userDir = "./";

#ifdef __WIN32__
	char buffer[MAX_PATH];
	buffer[0] = '\0';
	LPITEMIDLIST pidl = NULL;
	LPMALLOC pMalloc;
	if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
		SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl);
		if (pidl) {
			SHGetPathFromIDList(pidl, buffer);
		}
		pMalloc->Free(pidl);
		userDir = AnsiString(buffer);
	}
#elif __MACOSX__
	FSRef fileRef;
	OSStatus error = FSFindFolder(kUserDomain, kApplicationSupportFolderType, true, &fileRef);
	if (error == noErr) {
		char buffer[MAX_PATH];
		error = FSRefMakePath(&fileRef, (UInt8 *)buffer, sizeof(buffer));
		if (error == noErr)
			userDir = buffer;

	}
#elif __IPHONEOS__
	char path[MAX_PATH];
	IOS_GetDataDir(path);
	userDir = AnsiString(path);
#endif

	return userDir;
}
Пример #15
0
bool SelDirectory ( HWND hWnd, LPCTSTR strTitle, CString &strDir )  
{  
	BROWSEINFO bi;  
	char szDisplayName[MAX_PATH] = {0};  

	bi.hwndOwner = hWnd;  
	bi.pidlRoot = NULL;  
	bi.pszDisplayName = szDisplayName;  
	bi.lpszTitle = strTitle;  
	bi.ulFlags = 0;  
	bi.lpfn = BrowserCallbackProc;  
	bi.lParam = (LPARAM)(LPCTSTR)strDir;  
	bi.iImage = NULL;  

	// 显示目录选择对话框,如果按了取消,那么piid为NULL  
	ITEMIDLIST* piid = ::SHBrowseForFolder ( &bi );  

	if ( piid == NULL )  return false;  

	// 得到选择的目录  
	BOOL bValidPath = ::SHGetPathFromIDList ( piid, szDisplayName );  
	if ( ! bValidPath ) return false;  

	LPMALLOC lpMalloc;  
	HRESULT hr = ::SHGetMalloc ( &lpMalloc );
	assert(hr == NOERROR);  
	lpMalloc->Free ( piid );  
	lpMalloc->Release ();  

	if ( szDisplayName[0] == '\0' ) return false; //用户选择的可能的虚拟文件系统  

	strDir = szDisplayName;  

	return true;
}
Пример #16
0
void Playlist::AddDir(Bool do_recurse)
{
	BROWSEINFO brw;
	LPMALLOC pMalloc;
	LPITEMIDLIST ret;
	char dir[MAX_PATH];

	Bool res = GF_FALSE;
	if (NOERROR == ::SHGetMalloc(&pMalloc) ) {
		memset(&brw, 0, sizeof(BROWSEINFO));
		brw.hwndOwner = this->GetSafeHwnd();
		brw.pszDisplayName = dir;
		brw.lpszTitle = "Select Directory...";
		brw.ulFlags = 0L;
		brw.lpfn = LocCbck;

		ret = SHBrowseForFolder(&brw);
		if (ret != NULL) {
			if (::SHGetPathFromIDList(ret, dir)) res = GF_TRUE;
			pMalloc->Free(ret);
		}
		pMalloc->Release();
	}
	if (!res) return;
	strcpy(szCacheDir, dir);

	gf_enum_directory(dir, GF_FALSE, pl_enum_dir_item, this, NULL);
	if (do_recurse) gf_enum_directory(dir, GF_FALSE, pl_enum_dir_dirs, this, NULL);
	m_all_dead_entries=-1;
	RefreshList();
}
Пример #17
0
CString Directories::browseForDir(CString title)
{
  static char buffer[1024];
  LPMALLOC pMalloc;
  LPITEMIDLIST pidl;
  
  CString res;
  
  if(SUCCEEDED(SHGetMalloc(&pMalloc))) {
    BROWSEINFO bi;
    ZeroMemory(&bi, sizeof(bi));
    bi.hwndOwner = m_hWnd;
    bi.lpszTitle = title;
    bi.pidlRoot = 0;
    bi.ulFlags = BIF_RETURNONLYFSDIRS;
    bi.lpfn = browseCallbackProc;
    bi.lParam = (LPARAM)(LPCTSTR)initialFolderDir;
    
    pidl = SHBrowseForFolder(&bi);
    
    if(pidl) {
      if(SHGetPathFromIDList(pidl, buffer)) {
        res = buffer;
      }
      pMalloc->Free(pidl);
      pMalloc->Release();
    }
  }
  return res;
}
Пример #18
0
/*!	特殊フォルダのパスを取得する
	SHGetSpecialFolderPath API(shell32.dll version 4.71以上が必要)と同等の処理をする

	@param [in] nFolder CSIDL (constant special item ID list)
	@param [out] pszPath 特殊フォルダのパス

	@author ryoji
	@date 2007.05.19 新規
	@date 2017.06.24 novice SHGetFolderLocation()に変更

	@note SHGetFolderLocation()は、shell32.dll version 5.00以上が必要
*/
BOOL GetSpecialFolderPath( int nFolder, LPTSTR pszPath )
{
	BOOL bRet = FALSE;
	HRESULT hres;
	LPITEMIDLIST pidl = NULL;

#if (WINVER >= _WIN32_WINNT_WIN2K)
	hres = ::SHGetFolderLocation( NULL, nFolder, NULL, 0, &pidl );
	if( SUCCEEDED( hres ) ){
		bRet = ::SHGetPathFromIDList( pidl, pszPath );
		::CoTaskMemFree( pidl );
	}
#else
	LPMALLOC pMalloc;

	hres = ::SHGetMalloc( &pMalloc );
	if( FAILED( hres ) )
		return FALSE;

	hres = ::SHGetSpecialFolderLocation( NULL, nFolder, &pidl );
	if( SUCCEEDED( hres ) ){
		bRet = ::SHGetPathFromIDList( pidl, pszPath );
		pMalloc->Free( (void*)pidl );
	}

	pMalloc->Release();
#endif

	return bRet;
}
Пример #19
0
// only one full qualified PIDL has been passed
void CShellContextMenu::SetObjects(LPITEMIDLIST pidl)
{
	// free all allocated datas
	if (m_psfFolder && bDelete)
		m_psfFolder->Release ();
	m_psfFolder = NULL;
	FreePIDLArray (m_pidlArray);
	m_pidlArray = NULL;

		// full qualified PIDL is passed so we need
	// its parent IShellFolder interface and its relative PIDL to that
	LPITEMIDLIST pidlItem = NULL;
	SHBindToParent ((LPCITEMIDLIST) pidl, IID_IShellFolder, (void **) &m_psfFolder, (LPCITEMIDLIST *) &pidlItem);	

	m_pidlArray = (LPITEMIDLIST *) malloc (sizeof (LPITEMIDLIST));	// allocate ony for one elemnt
	m_pidlArray[0] = CopyPIDL (pidlItem);


	// now free pidlItem via IMalloc interface (but not m_psfFolder, that we need later
	LPMALLOC lpMalloc = NULL;
	SHGetMalloc (&lpMalloc);
	lpMalloc->Free (pidlItem);
	lpMalloc->Release();

	nItems = 1;
	bDelete = TRUE;	// indicates that m_psfFolder should be deleted by CShellContextMenu
}
Пример #20
0
//------------------------------------------------------------------------------
void __fastcall TPrefsForm::BrowseButtonClick(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 = LMessagesOpt.SelectFolder;
    info.ulFlags = BIF_NEWDIALOGSTYLE; //BIF_RETURNONLYFSDIRS;
    info.lpfn = 0;
    pidl = SHBrowseForFolder(&info);

    if(pidl) {
      if(SHGetPathFromIDList(pidl, szDir))
        BackupPath->Text = szDir;

      pShellMalloc->Free(pidl);
    }

    pShellMalloc->Release();
  }
}
void SetCertDirDlg::OnBnClickedButton1()
{
	LPMALLOC pMalloc;
    
    if( SUCCEEDED( SHGetMalloc( &pMalloc ) ) ) 
    {
        TCHAR szTitle[] = _T("Choose Directory for storing certificates.");
        BROWSEINFO bi;
        ZeroMemory( &bi, sizeof( bi ) );
        bi.hwndOwner = NULL;
        bi.pszDisplayName = NULL;
        bi.lpszTitle = szTitle;
        bi.pidlRoot = NULL;
		bi.ulFlags = BIF_RETURNONLYFSDIRS;
        
        LPITEMIDLIST pidl = SHBrowseForFolder( &bi );
        if( pidl ) 
        {
            TCHAR szDir[MAX_PATH];
            if( SHGetPathFromIDList( pidl, szDir ) ) 
            {
				m_CertificatePath.SetWindowText(szDir);
				m_CertificatePath.SetFocus();
            }
            pMalloc->Free(pidl); 
            pMalloc->Release();
        }
    }
}
Пример #22
0
//---------------------------------------------------------------------------
// UnregisterServer
//---------------------------------------------------------------------------
BOOL UnregisterServer(CLSID clsid, LPTSTR lpszTitle)
{
/*!
 * This function removes the keys from registry
 * NOTE: we can do this better with Qt
 */

    TCHAR szCLSID[GUID_SIZE + 1];
    TCHAR szCLSIDKey[GUID_SIZE + 32];
    TCHAR szKeyTemp[MAX_PATH + GUID_SIZE];
    LPTSTR pwsz;

    StringFromIID(clsid, &pwsz);
    if(pwsz) {
        lstrcpy(szCLSID, pwsz);
        //free the string
        LPMALLOC pMalloc;
        CoGetMalloc(1, &pMalloc);
        pMalloc->Free(pwsz);
        pMalloc->Release();
    }

    lstrcpy(szCLSIDKey, TEXT("CLSID\\"));
    lstrcat(szCLSIDKey, szCLSID);

    wsprintf(szKeyTemp, TEXT("*\\shellex\\ContextMenuHandlers\\%s"), lpszTitle);
    RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);

    wsprintf(szKeyTemp, TEXT("%s\\%s"), szCLSIDKey, TEXT("InprocServer32"));
    RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);
    RegDeleteKey(HKEY_CLASSES_ROOT, szCLSIDKey);

    return TRUE;
}
Пример #23
0
bool system_alert_choose_scenario(char *chosen_dir)
{
#if defined(__WIN32__)
	BROWSEINFO bi = { 0 };
	TCHAR path[MAX_PATH];
	bi.lpszTitle = _T("Select a scenario to play:");
	bi.pszDisplayName = path;
	bi.lpfn = browse_callback_proc;
	bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | 0x00000200; // no "New Folder" button
	LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
	if (pidl)
	{
		SHGetPathFromIDList(pidl, path);
#ifdef UNICODE
		WideCharToMultiByte(CP_UTF8, 0, path, -1, chosen_dir, 256, NULL, NULL);
#else
		strncpy(chosen_dir, path, 255);
#endif
		LPMALLOC pMalloc = NULL;
		SHGetMalloc(&pMalloc);
		pMalloc->Free(pidl);
		pMalloc->Release();
		return true;
	}
#endif
	return false;
}
Пример #24
0
std::string DirectorySelectDlg( HWND hParent, const TCHAR* title,  const TCHAR* old )
{

	std::string result;

	LPMALLOC pMalloc;
	if( ::SHGetMalloc( &pMalloc ) == NOERROR )
	{
		BROWSEINFO bi = {0};

		bi.hwndOwner = hParent;
		bi.lpszTitle = title;
		bi.ulFlags = 0;
		bi.lpfn = DirectorySelect_Callback;
		bi.lParam = ( LPARAM )old;

		TCHAR pszBuffer[MAX_PATH];
		if( LPITEMIDLIST pidl =::SHBrowseForFolder( &bi ) )
		{
			if( ::SHGetPathFromIDList( pidl, pszBuffer ) )
			{
				result = pszBuffer;
			}
			pMalloc->Free( pidl );
		}
		pMalloc->Release();
	}
	return result;
}
Пример #25
0
void CConfigFile::OnBtnFolder() 
{
	// TODO: Add your control notification handler code here
	//Open file folder dialogue box
	LPMALLOC   pMalloc;  
	if   (::SHGetMalloc(&pMalloc)   ==   NOERROR)   
	{   
		BROWSEINFO   bi;   
		TCHAR   pszBuffer[MAX_PATH];   
		LPITEMIDLIST   pidl;   
		bi.hwndOwner   =   this->m_hWnd;   
		bi.pidlRoot   =   NULL;   
		bi.pszDisplayName   =   pszBuffer;   
		bi.lpszTitle   =   _T(ConvertString("select folder"));   
		bi.ulFlags   =   BIF_RETURNFSANCESTORS   |   BIF_RETURNONLYFSDIRS;   
		bi.lpfn   =   NULL;   
		bi.lParam   =   0;   
		bi.iImage   =   0;   
		if   ((pidl   =   ::SHBrowseForFolder(&bi))   !=   NULL)   
		{   
			if   (::SHGetPathFromIDList(pidl,   pszBuffer))   
			{
				m_CSFile.Empty();
				m_CSFile  =  pszBuffer;  
				SetDlgItemText(IDC_EDIT_EXPORT, pszBuffer);
			}
			else
			{
				return;   
			}
			pMalloc->Free(pidl);   
		}   
		pMalloc->Release();   
	} 
}
bool CBrowseForFolder::SelectFolder()
{
	bool bRet = false;

	LPITEMIDLIST pidl;
	if ((pidl = ::SHBrowseForFolder(&m_bi)) != NULL)
	{
		m_strPath.Empty();
		if (::SHGetPathFromIDList(pidl, m_szSelected))
		{
			bRet = true;
			m_strPath = m_szSelected;
		}

		LPMALLOC pMalloc;
		//Retrieve a pointer to the shell's IMalloc interface
		if (SUCCEEDED(SHGetMalloc(&pMalloc)))
		{
			// free the PIDL that SHBrowseForFolder returned to us.
			pMalloc->Free(pidl);
			// release the shell's IMalloc interface
			(void)pMalloc->Release();
		}
	}
	m_hwnd = NULL;

	return bRet;
}
Пример #27
0
BOOL PageSystem::BrowseForFolder(HWND hOwner, TCHAR* szTitle, TCHAR* szRetval)
{
    BROWSEINFO info;
    LPITEMIDLIST itemidlist;
    TCHAR szDirectory[_MAX_PATH];
    LPMALLOC pMalloc;
    memset(szDirectory, 0, _MAX_PATH * sizeof(TCHAR));

    if (::SHGetMalloc(&pMalloc) == NOERROR)
    {
        info.hwndOwner = hOwner;
        info.pidlRoot = NULL;
        info.pszDisplayName = szDirectory;
        info.lpszTitle = szTitle;
        info.ulFlags = 0;
        info.lpfn = NULL;

        itemidlist = SHBrowseForFolder(&info);
        if (itemidlist != NULL)
        {
            SHGetPathFromIDList(itemidlist, szRetval);
            pMalloc->Free(itemidlist);
            pMalloc->Release();
            return TRUE;
        }
        else // User clicked Cancel
        {
            pMalloc->Release();
            return FALSE;
        }
    }
    else
        return FALSE;
}
Пример #28
0
int CFolderDialog::DoModal()
{
	int nReturn = IDOK;

	// initialize the result to the starting folder value
	m_strFinalFolderName = m_strInitialFolderName;

	ITEMIDLIST* piid = NULL;

	// call the shell function
	piid = ::SHBrowseForFolder(&m_bi);

	// process the result
	if (piid && ::SHGetPathFromIDList(piid, m_szPath)) {
		m_strFinalFolderName = m_szPath;
		nReturn = IDOK;
	} else {
		nReturn = IDCANCEL;
	}

	// Release the ITEMIDLIST if we got one
	if (piid) {
		LPMALLOC lpMalloc;
		VERIFY(::SHGetMalloc(&lpMalloc) == NOERROR);
		lpMalloc->Free(piid);
		lpMalloc->Release();
	}

	return nReturn;
}
Пример #29
0
BOOL Util::SelectFolder(HWND hWnd, LPSTR lpszFolder, LPCSTR lpszTitle,
		UINT ulFlag) {
	BROWSEINFO bi;
	ITEMIDLIST *pidl;

	memset(&bi, 0, sizeof(bi));

	bi.hwndOwner = hWnd;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = lpszFolder;
	bi.lpszTitle = lpszTitle;
//	bi.ulFlags = BIF_RETURNONLYFSDIRS;BIF_NEWDIALOGSTYLE
	bi.ulFlags = ulFlag;
	bi.lpfn = NULL;
	bi.lParam = 0;
	bi.iImage = 0;

	pidl = SHBrowseForFolder(&bi);

	if (pidl) {
		SHGetPathFromIDList(pidl, lpszFolder);

		LPMALLOC lpMalloc;

		if (SUCCEEDED(SHGetMalloc(&lpMalloc))) {
			lpMalloc->Free(pidl);
			lpMalloc->Release();
		}

		return TRUE;
	}

	return FALSE;
}
Пример #30
0
CString CFilePro::GetSelectedFolder()
{
	BROWSEINFO bi;  
	ZeroMemory(&bi,sizeof(BROWSEINFO));  
	LPMALLOC pMalloc;  
	LPITEMIDLIST pidl = SHBrowseForFolder(&bi);  

	if(!pidl )
	{
		m_strErrMsg = "用户取消";
		return "";
	}

	CString strFolderOut = "";
	TCHAR * path = new TCHAR[MAX_PATH];   

	SHGetPathFromIDList(pidl,path);  
	if(SUCCEEDED(SHGetMalloc(&pMalloc))) 
	{  
		pMalloc->Free(pidl);  
		pMalloc->Release();  
	}

	strFolderOut = path;
	delete [] path;
	return strFolderOut;
}