Пример #1
0
BOOL CDirDialog::DoBrowse(CWnd *pwndParent)
{

    if( ! m_strSelDir.IsEmpty() )
    {
        m_strSelDir.TrimRight();
        if( m_strSelDir.Right(1) == "\\" || m_strSelDir.Right(1) == "//" )
            m_strSelDir = m_strSelDir.Left(m_strSelDir.GetLength() - 1);
    }

    LPMALLOC pMalloc;
    if (SHGetMalloc (&pMalloc)!= NOERROR)
        return FALSE;

    BROWSEINFO bInfo;
    LPITEMIDLIST pidl;
    ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO));

    if (!m_strInitDir.IsEmpty ())
    {
        OLECHAR       olePath[MAX_PATH];
        ULONG         chEaten;
        ULONG         dwAttributes;
        HRESULT       hr;
        LPSHELLFOLDER pDesktopFolder;
        //
        // Get a pointer to the Desktop's IShellFolder interface.
        //
        if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
        {
#ifndef UNICODE
            MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir.GetBuffer(MAX_PATH), -1,
                                olePath, MAX_PATH);
            m_strInitDir.ReleaseBuffer (-1);
#else
			wcscpy( olePath, m_strInitDir );
#endif

            //
            // Convert the path to an ITEMIDLIST.
            //
            hr = pDesktopFolder->ParseDisplayName(NULL,
                                                NULL,
                                                olePath,
                                                &chEaten,
                                                &pidl,
                                                &dwAttributes);
            if (FAILED(hr))
            {
                pMalloc ->Free (pidl);
                pMalloc ->Release ();
                return FALSE;
            }
            bInfo.pidlRoot = pidl;

        }
    }
    bInfo.hwndOwner = pwndParent == NULL ? NULL : pwndParent->GetSafeHwnd();
    bInfo.pszDisplayName = m_strPath.GetBuffer (MAX_PATH);
    bInfo.lpszTitle = (m_strTitle.IsEmpty()) ? "Open" : m_strTitle;
    bInfo.ulFlags = BIF_RETURNFSANCESTORS
                    | BIF_RETURNONLYFSDIRS
                    | (m_bStatus ? BIF_STATUSTEXT : 0);

    bInfo.lpfn = BrowseCtrlCallback;  // address of callback function
    bInfo.lParam = (LPARAM)this;      // pass address of object to callback function

    if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL)
    {
        return FALSE;
    }
    m_strPath.ReleaseBuffer();
    m_iImageIndex = bInfo.iImage;

    if (::SHGetPathFromIDList(pidl, m_strPath.GetBuffer(MAX_PATH)) == FALSE)
    {
        pMalloc ->Free(pidl);
        pMalloc ->Release();
        return FALSE;
    }

    m_strPath.ReleaseBuffer();

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

    return TRUE;
}
Пример #2
0
BOOL showContextMenu (HWND hDlg, TCHAR* FName, WNDPROC menuProc)
{
	TCHAR* FileName = PathFindFileName (FName);
	TCHAR FilePath [MAX_PATH];
	lstrcpy (FilePath, FName);
	*PathFindFileName (FilePath) = L'\0';
	
	LPSHELLFOLDER DesktopFolder;
	if (NOERROR != SHGetDesktopFolder (&DesktopFolder))
	{
		return FALSE;
	}
	
	LPITEMIDLIST ParentPidl;
	ULONG Eaten;
	if (S_OK != DesktopFolder->ParseDisplayName (hDlg, 0, FilePath, &Eaten, &ParentPidl, 0))
	{
		return FALSE;
	}
	
	LPSHELLFOLDER ParentFolder;
	if (S_OK != DesktopFolder->BindToObject (ParentPidl, 0, IID_IShellFolder, (void**)&ParentFolder))
	{
		return FALSE;
	}
	
	LPITEMIDLIST Pidl;
	if (S_OK != ParentFolder->ParseDisplayName (hDlg, 0, FileName, &Eaten, &Pidl, 0))
	{
		return FALSE;
	}	

	LPCONTEXTMENU CM;
	if (S_OK != ParentFolder->GetUIObjectOf (hDlg, 1, (LPCITEMIDLIST*)&Pidl, IID_IContextMenu, 0, (void**)&CM))
	{
		return FALSE;
	}
	
	HMENU hMenu = CreatePopupMenu ();
	if (hMenu == NULL) 
	{
		return FALSE;
	}
	
	CM->QueryContextMenu (hMenu, 0, 1, 0x7FFF, CMF_EXTENDEDVERBS | CMF_EXPLORE);
	
	WNDPROC defWndProc = (WNDPROC) SetWindowLong (hDlg, GWL_WNDPROC, (LONG)menuProc);
	SetProp (hDlg, L"defWndProc", (HANDLE) defWndProc);
	
	POINT pt;
	GetCursorPos (&pt);
	int Cmd = TrackPopupMenu (hMenu,
		TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD,
		pt.x, pt.y, 0, hDlg, 0);


	SetWindowLong (hDlg, GWL_WNDPROC, (LONG) RemoveProp (hDlg, L"defWndProc"));
		
	if (Cmd)
	{
		// Set up a CMINVOKECOMMANDINFO structure.
		CMINVOKECOMMANDINFO CI;
		ZeroMemory (&CI, sizeof(CMINVOKECOMMANDINFO));
		CI.cbSize = sizeof (CMINVOKECOMMANDINFO);
		CI.hwnd = hDlg;
		CI.lpVerb = (LPCSTR) MAKEINTRESOURCE(Cmd - 1);
		CI.lpParameters = "";
		CI.lpDirectory = "";
		CI.nShow = SW_SHOWNORMAL;
		CM->InvokeCommand (&CI);
	}
	
	return DestroyMenu (hMenu);
}
Пример #3
0
LPITEMIDLIST GetCurrentFolder()
{
/*
	How To Convert a File Path to an ITEMIDLIST
	http://support.microsoft.com/default.aspx?scid=kb;en-us;132750
*/
	LPITEMIDLIST   pidl;
	LPSHELLFOLDER  pDesktopFolder;
	TCHAR          szPath[ MAX_PATH ];
#ifndef PA_UNICODE
	OLECHAR        olePath[ MAX_PATH ];
#endif
	ULONG          chEaten;
	ULONG          dwAttributes;
	HRESULT        hr;

	//
	// Get the path we need to convert.
	//
	GetCurrentDirectory( MAX_PATH, szPath );

	//
	// Get a pointer to the Desktop's IShellFolder interface.
	//
	if( SUCCEEDED( SHGetDesktopFolder( &pDesktopFolder ) ) )
	{

		//
		// IShellFolder::ParseDisplayName requires the file name be in
		// Unicode.
		//
#ifndef	PA_UNICODE	
		MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH );
#endif
		//
		// Convert the path to an ITEMIDLIST.
		//
		// hr = pDesktopFolder->lpVtbl->ParseDisplayName(
		hr = pDesktopFolder->ParseDisplayName(
			( HWND__ * )pDesktopFolder,
			NULL,
#ifndef PA_UNICODE			
			olePath,
#else
			szPath,
#endif			
			&chEaten,
			&pidl,
			&dwAttributes
		);
	
		if( FAILED( hr ) )
		{
			// Handle error.
			return NULL;
		}
	
		//
		// pidl now contains a pointer to an ITEMIDLIST for .\readme.txt.
		// This ITEMIDLIST needs to be freed using the IMalloc allocator
		// returned from SHGetMalloc().
		//
	
		// release the desktop folder object
		// pDesktopFolder->lpVtbl->Release();
		pDesktopFolder->Release();

		return pidl;
	}
	else
	{
		return NULL;
	}
}
Пример #4
0
int CDirDialog::DoBrowse ()
{/////////////////////////////////////////

    LPMALLOC pMalloc;
    if (SHGetMalloc (&pMalloc)!= NOERROR)
    {
        return 0;
    }

    BROWSEINFO bInfo;
    LPITEMIDLIST pidl;
    ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO));

     if (!m_strInitDir.IsEmpty ())
     {
          OLECHAR       olePath[MAX_PATH];
          ULONG         chEaten;
          ULONG         dwAttributes;
          HRESULT       hr;
          LPSHELLFOLDER pDesktopFolder;
          // // Get a pointer to the Desktop's IShellFolder interface. //
          if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
          {

               //
               // IShellFolder::ParseDisplayName requires the file name be in Unicode.
               //
               MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir.GetBuffer (MAX_PATH), -1,
                    olePath, MAX_PATH);

               m_strInitDir.ReleaseBuffer (-1);
               //
               // Convert the path to an ITEMIDLIST.
               //
               hr = pDesktopFolder->ParseDisplayName(NULL,
                    NULL,
                    olePath,
                    &chEaten,
                    &pidl,
                    &dwAttributes);
               if (FAILED(hr))
               {
                    pMalloc ->Free (pidl);
                    pMalloc ->Release ();
                    return 0;
               }
               bInfo.pidlRoot = pidl;
          }
     }
          bInfo.hwndOwner = NULL;
          bInfo.pszDisplayName = m_strPath.GetBuffer (MAX_PATH);
          bInfo.lpszTitle = (m_strTitle.IsEmpty()) ? "Open":m_strTitle;
          bInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;


          if ((pidl = ::SHBrowseForFolder (&bInfo)) == NULL)
          {
               return 0;
          }
          m_strPath.ReleaseBuffer ();
          m_iImageIndex = bInfo.iImage;

          if (::SHGetPathFromIDList(pidl,m_strPath.GetBuffer (MAX_PATH)) == FALSE)
          {
               pMalloc ->Free (pidl);
               pMalloc ->Release ();
               return 0;
          }

    m_strPath.ReleaseBuffer ();

    pMalloc ->Free (pidl);
    pMalloc ->Release ();
     return 1;
}
Пример #5
0
/*!	独自拡張プロパティシートのウィンドウプロシージャ
	@author ryoji
	@date 2007.05.25 新規
*/
static LRESULT CALLBACK PropSheetWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	switch( uMsg ){
	case WM_SHOWWINDOW:
		// 追加ボタンの位置を調整する
		if( wParam ){
			HWND hwndBtn;
			RECT rcOk;
			RECT rcTab;
			POINT pt;

			hwndBtn = ::GetDlgItem( hwnd, 0x02000 );
			::GetWindowRect( ::GetDlgItem( hwnd, IDOK ), &rcOk );
			::GetWindowRect( PropSheet_GetTabControl( hwnd ), &rcTab );
			pt.x = rcTab.left;
			pt.y = rcOk.top;
			::ScreenToClient( hwnd, &pt );
			::MoveWindow( hwndBtn, pt.x, pt.y, DpiScaleX(140), rcOk.bottom - rcOk.top, FALSE );
		}
		break;

	case WM_COMMAND:
		// 追加ボタンが押された時はその処理を行う
		if( HIWORD( wParam ) == BN_CLICKED && LOWORD( wParam ) == 0x02000 ){
			HWND hwndBtn = ::GetDlgItem( hwnd, 0x2000 );
			RECT rc;
			POINT pt;

			// メニューを表示する
			::GetWindowRect( hwndBtn, &rc );
			pt.x = rc.left;
			pt.y = rc.bottom;
			GetMonitorWorkRect( pt, &rc );	// モニタのワークエリア

			HMENU hMenu = ::CreatePopupMenu();
			::InsertMenu( hMenu, 0, MF_BYPOSITION | MF_STRING, 100, LS(STR_SHELL_MENU_OPEN) );
			::InsertMenu( hMenu, 1, MF_BYPOSITION | MF_STRING, 101, LS(STR_SHELL_MENU_IMPEXP) );

			int nId = ::TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD,
										( pt.x > rc.left )? pt.x: rc.left,
										( pt.y < rc.bottom )? pt.y: rc.bottom,
										0, hwnd, NULL );
			::DestroyMenu( hMenu );

			// 選択されたメニューの処理
			switch( nId ){
			case 100:	// 設定フォルダを開く
				TCHAR szPath[_MAX_PATH];
				GetInidir( szPath );

				// フォルダの ITEMIDLIST を取得して ShellExecuteEx() で開く
				// Note. MSDN の ShellExecute() の解説にある方法でフォルダを開こうとした場合、
				//       フォルダと同じ場所に <フォルダ名>.exe があるとうまく動かない。
				//       verbが"open"やNULLではexeのほうが実行され"explore"では失敗する
				//       (フォルダ名の末尾に'\\'を付加してもWindows 2000では付加しないのと同じ動作になってしまう)
				LPSHELLFOLDER pDesktopFolder;
				if( SUCCEEDED(::SHGetDesktopFolder(&pDesktopFolder)) ){
					LPMALLOC pMalloc;
					if( SUCCEEDED(::SHGetMalloc(&pMalloc)) ){
						LPITEMIDLIST pIDL;
						WCHAR pwszDisplayName[_MAX_PATH];
						_tcstowcs(pwszDisplayName, szPath, _countof(pwszDisplayName));
//#ifdef _UNICODE
//						pwszDisplayName = szPath;
//#else
//						WCHAR wszPath[_MAX_PATH];
//						::MultiByteToWideChar( CP_ACP, 0, szPath, -1, wszPath, _MAX_PATH );
//						pwszDisplayName = wszPath;
//#endif
						if( SUCCEEDED(pDesktopFolder->ParseDisplayName(NULL, NULL, pwszDisplayName, NULL, &pIDL, NULL)) ){
							SHELLEXECUTEINFO si;
							::ZeroMemory( &si, sizeof(si) );
							si.cbSize   = sizeof(si);
							si.fMask    = SEE_MASK_IDLIST;
							si.lpVerb   = _T("open");
							si.lpIDList = pIDL;
							si.nShow    = SW_SHOWNORMAL;
							::ShellExecuteEx( &si );	// フォルダを開く
							pMalloc->Free( (void*)pIDL );
						}
						pMalloc->Release();
					}
					pDesktopFolder->Release();
				}
				break;
			case 101:	// インポート/エクスポートの起点リセット(起点を設定フォルダにする)
				int nMsgResult = MYMESSAGEBOX(
					hwnd,
					MB_OKCANCEL | MB_ICONINFORMATION,
					GSTR_APPNAME,
					LS(STR_SHELL_IMPEXPDIR)
				);
				if( IDOK == nMsgResult )
				{
					DLLSHAREDATA *pShareData = &GetDllShareData();
					GetInidir( pShareData->m_sHistory.m_szIMPORTFOLDER );
					AddLastChar( pShareData->m_sHistory.m_szIMPORTFOLDER, _countof2(pShareData->m_sHistory.m_szIMPORTFOLDER), _T('\\') );
				}
				break;
			}
		}
		break;

	case WM_DESTROY:
		::SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)s_pOldPropSheetWndProc );
		break;
	}

	return ::CallWindowProc( s_pOldPropSheetWndProc, hwnd, uMsg, wParam, lParam );
}
int CDirectoryDlg::DoModal()
{
    LPMALLOC        pMalloc;
    BROWSEINFO      bi;
    LPITEMIDLIST    pidl;
    LPSHELLFOLDER   pDesktopFolder;
    TCHAR           szInitialPath[MAX_PATH];
    OLECHAR         oleInitialPath[MAX_PATH];
    ULONG           chEaten;
    ULONG           dwAttributes;
    HRESULT         hr;
    CFileStatus     FileStatus;

    lstrcpy(szInitialPath, m_strInitialDir);

    /*  IMPORTANT NOTE: Do not forget that the path may not be existent,
        SHBrowseForFolder reacts very vexing to this fact. So assure that the
        path is valid and exists.
    */

    
    if(!CFile::GetStatus(m_strInitialDir, FileStatus)) 
    {
        ::GetCurrentDirectory(MAX_PATH, m_strInitialDir.GetBuffer(MAX_PATH+1));
        m_strInitialDir.ReleaseBuffer();
        lstrcpy(szInitialPath, m_strInitialDir);
    }
    

    //
    // Get a pointer to the Desktop's IShellFolder interface.
    //
    hr = SHGetDesktopFolder(&pDesktopFolder);

    if (FAILED(hr))
    {
        UTIL_DisplaySysError(hr, NULL, NULL);
        return IDABORT;
    }

    //
    // IShellFolder::ParseDisplayName requires the file name be in
    // Unicode.
    //
    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szInitialPath, -1,
                        oleInitialPath, MAX_PATH);

    //
    // Convert the path to an ITEMIDLIST.
    //
    hr = pDesktopFolder->ParseDisplayName(NULL,
                                          NULL,
                                          oleInitialPath,
                                          &chEaten,
                                          &pidl,
                                          &dwAttributes);

    //release the desktop folder object
    pDesktopFolder->Release();

    if (FAILED(hr))
    {
        UTIL_DisplaySysError(hr, NULL, NULL);
        return IDABORT;
    }

    //
    // pidl now contains a pointer to an ITEMIDLIST for .\readme.txt.
    // This ITEMIDLIST needs to be freed using the IMalloc allocator
    // returned from SHGetMalloc().
    //
    hr = SHGetMalloc(&pMalloc);

    if(FAILED(hr)) 
    {
        UTIL_DisplaySysError(hr, NULL, NULL);
        return IDABORT;
    }

    HWND    hWndTop;
    HWND    hWndOwner = CWnd::GetSafeOwner_(NULL, &hWndTop);

    ZeroMemory(&bi,sizeof(bi));
    bi.hwndOwner = hWndOwner;
    bi.pidlRoot = NULL;
    bi.pszDisplayName = NULL;
    bi.lpszTitle = "";
    bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_VALIDATE;
    bi.lpfn = BrowsePathCallbackProc;
    bi.lParam = (LPARAM)szInitialPath;

    pidl = SHBrowseForFolder(&bi);

	if (hWndTop != NULL)
    {
        EnableWindow(hWndTop, TRUE);
    }

    if (pidl)
    {
        SHGetPathFromIDList(pidl, szInitialPath);
        pMalloc->Free(pidl);
        pMalloc->Release();
        m_strDirectory = szInitialPath;
    }
    if(m_strDirectory.IsEmpty())
    {
        return IDCANCEL;
    }
    return IDOK;
}
Пример #7
0
/**
 * Begin a saved search.
 */
JNIEXPORT jlong JNICALL WindowsSavedSearch_METHOD(beginSearch)
    ( JNIEnv *env, jclass, jstring jPath )
{
    jstring_to_c const cPath( env, jPath );

    SavedSearch*    cSavedSearch = NULL;
    bool            error = false;
    LPITEMIDLIST    pidl = NULL;
    LPSHELLFOLDER   pDesktop = NULL;
    HRESULT         result;

    if ( FAILED( ::CoInitialize( NULL ) ) )
        goto error;

    cSavedSearch = new SavedSearch;

    if ( FAILED( ::SHGetMalloc( &cSavedSearch->m_pMalloc ) ) )
        goto error;

    //
    // We have to start at the filesystem root (the "Desktop" in Windows).
    //
    if ( FAILED( ::SHGetDesktopFolder( &pDesktop ) ) )
        goto error;

    //
    // ParseDisplayName() wants UTF-16, so convert the path first.
    //
    WCHAR wPath[ MAX_PATH ];
    if ( !LC_toWCHAR( cPath, wPath, sizeof wPath ) )
        goto error;

    result = pDesktop->ParseDisplayName( NULL, NULL, wPath, NULL, &pidl, NULL );
    if ( FAILED( result ) )
        goto error;

    //
    // Binding the path of what we want relative to the Desktop gets us the
    // PIDL for the path of the saved search file.
    //
    result = pDesktop->BindToObject(
        pidl, NULL, IID_IShellFolder,
        reinterpret_cast<void**>( &cSavedSearch->m_pFolder )
    );
    if ( FAILED( result ) )
        goto error;

    //
    // We can now start the enumeration of the saved search file which runs the
    // search.
    //
    result = cSavedSearch->m_pFolder->EnumObjects(
        NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &cSavedSearch->m_pEnumIDList
    );
    if ( result == S_FALSE || FAILED( result ) )
        goto error;

    goto done;

error:
    error = true;
done:
    if ( pDesktop )
        pDesktop->Release();
    if ( cSavedSearch && cSavedSearch->m_pMalloc && pidl )
        cSavedSearch->m_pMalloc->Free( pidl );
    if ( error ) {
        delete cSavedSearch;
        return 0;
    }
    return reinterpret_cast<jlong>( cSavedSearch );
}
Пример #8
0
int CBrowse::DoBrowse()
{
   LPMALLOC pMalloc;
   if (SHGetMalloc (&pMalloc)!= NOERROR)
      return 0;

   BROWSEINFO bInfo;
   LPITEMIDLIST pidl;
   ZeroMemory((PVOID) &bInfo,sizeof (BROWSEINFO));

   // set up InitDir as Root
   if (!m_strInitDir.IsEmpty())
   {
      OLECHAR       olePath[MAX_PATH];
      ULONG         chEaten;
      ULONG         dwAttributes;
      HRESULT       hr;
      LPSHELLFOLDER pDesktopFolder;
      // 
      // Get a pointer to the Desktop's IShellFolder interface. 
      //
      if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
      {
         //
         // IShellFolder::ParseDisplayName requires the file name be in Unicode.
         //
         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, m_strInitDir.GetBuffer(MAX_PATH), -1,
               olePath, MAX_PATH);

         m_strInitDir.ReleaseBuffer (-1);
         //
         // Convert the path to an ITEMIDLIST.
         //
         hr = pDesktopFolder->ParseDisplayName(NULL,
               NULL,
               olePath,
               &chEaten,
               &pidl,
               &dwAttributes);
         if (FAILED(hr))
         {
            pMalloc ->Free (pidl);
            pMalloc ->Release ();
            return 0;
         }
         bInfo.pidlRoot = pidl;
      }
   }
   bInfo.hwndOwner = AfxGetMainWnd()->m_hWnd;
   bInfo.pszDisplayName = m_strPath.GetBuffer(MAX_PATH);
   bInfo.lpszTitle = m_strTitle;
   bInfo.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
   bInfo.lpfn = BrowseCtrlCallback;  // address of callback function
   bInfo.lParam = (LPARAM)this;      // pass address of object to callback function

   if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL)
      return 0;

   m_strPath.ReleaseBuffer();
   m_iImageIndex = bInfo.iImage;

   if (::SHGetPathFromIDList(pidl,m_strPath.GetBuffer(MAX_PATH)) == FALSE)
   {
      pMalloc->Free(pidl);
      pMalloc->Release();
      return 0;
   }

   m_strPath.ReleaseBuffer();

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

   return 1;
}
Пример #9
0
LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify) {
  switch (codeNotify) {
    case BN_CLICKED:    // The user pressed a button
    case LBN_SELCHANGE: // The user changed the selection in a ListBox control
//  case CBN_SELCHANGE: // The user changed the selection in a DropList control (same value as LBN_SELCHANGE)
    {
      char szBrowsePath[MAX_PATH];
      int nIdx = FindControlIdx(id);
      // Ignore if the dialog is in the process of being created
      if (g_done || nIdx < 0)
        break;
      if (pFields[nIdx].nType == FIELD_BROWSEBUTTON)
        --nIdx;
      FieldType *pField = pFields + nIdx;
      switch (pField->nType) {
        case FIELD_FILEREQUEST: {
          OPENFILENAME ofn={0,};

          ofn.lStructSize = sizeof(ofn);
          ofn.hwndOwner = hConfigWindow;
          ofn.lpstrFilter = pField->pszFilter;
          ofn.lpstrFile = szBrowsePath;
          ofn.nMaxFile  = sizeof(szBrowsePath);
          ofn.Flags = pField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER);

          GetWindowText(pField->hwnd, szBrowsePath, sizeof(szBrowsePath));

        tryagain:
          if ((pField->nFlags & FLAG_SAVEAS) ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn)) {
            mySetWindowText(pField->hwnd, szBrowsePath);
            break;
          }
          else if (szBrowsePath[0] && CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
            szBrowsePath[0] = '\0';
            goto tryagain;
          }

          break;
        }

        case FIELD_DIRREQUEST: {
          BROWSEINFO bi;

          bi.hwndOwner = hConfigWindow;
          bi.pidlRoot = NULL;
          bi.pszDisplayName = szBrowsePath;
          bi.lpszTitle = pField->pszText;
#ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 0x0040
#endif
          bi.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
          bi.lpfn = BrowseCallbackProc;
          bi.lParam = nIdx;
          bi.iImage = 0;

          if (pField->pszRoot) {
            LPSHELLFOLDER sf;
            ULONG eaten;
            LPITEMIDLIST root;
            int ccRoot = (lstrlen(pField->pszRoot) * 2) + 2;
            LPWSTR pwszRoot = (LPWSTR) MALLOC(ccRoot);
            MultiByteToWideChar(CP_ACP, 0, pField->pszRoot, -1, pwszRoot, ccRoot);
            SHGetDesktopFolder(&sf);
            sf->ParseDisplayName(hConfigWindow, NULL, pwszRoot, &eaten, &root, NULL);
            bi.pidlRoot = root;
            sf->Release();
            FREE(pwszRoot);
          }
//          CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
          LPITEMIDLIST pResult = SHBrowseForFolder(&bi);
          if (!pResult)
            break;

          if (SHGetPathFromIDList(pResult, szBrowsePath)) {
            mySetWindowText(pField->hwnd, szBrowsePath);
          }

          LPMALLOC pMalloc;
          if (!SHGetMalloc(&pMalloc)) {
            pMalloc->Free(pResult);
          }

          break;
        }

        case FIELD_LINK:
        case FIELD_BUTTON:
          // Allow the state to be empty - this might be useful in conjunction
          // with the NOTIFY flag
          if (*pField->pszState)
            ShellExecute(hMainWindow, NULL, pField->pszState, NULL, NULL, SW_SHOWDEFAULT);
          break;
      }

      if (pField->nFlags & LBS_NOTIFY) {
        // Remember which control was activated then pretend the user clicked Next
        g_NotifyField = nIdx + 1;
        // the next button must be enabled or nsis will ignore WM_COMMAND
        BOOL bWasDisabled = EnableWindow(hNextButton, TRUE);
        FORWARD_WM_COMMAND(hMainWindow, IDOK, hNextButton, BN_CLICKED, mySendMessage);
        if (bWasDisabled)
          EnableWindow(hNextButton, FALSE);
      }
    }
    break;
  }
  return 0;
}
Пример #10
0
//  Snapshots a directory and displays the items in the listview control
int DirList_Fill(HWND hwnd, const WCHAR* lpszDir, DWORD grfFlags, const WCHAR* lpszFileSpec,
                 BOOL bExcludeFilter, BOOL bNoFadeHidden, int iSortFlags, BOOL fSortRev) {

    WCHAR wszDir[MAX_PATH];

    LPSHELLFOLDER lpsfDesktop = NULL;
    LPSHELLFOLDER lpsf = NULL;

    LPITEMIDLIST pidl = NULL;
    LPITEMIDLIST pidlEntry = NULL;

    LPENUMIDLIST lpe = NULL;

    LV_ITEM lvi;
    LPLV_ITEMDATA lplvid;

    ULONG chParsed = 0;
    ULONG dwAttributes = 0;

    DL_FILTER dlf;
    SHFILEINFO shfi = { 0 };

    DLDATA* lpdl = (DLDATA*)GetProp(hwnd, pDirListProp);

    // Initialize default icons
    SHGetFileInfo(L"Icon", FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(SHFILEINFO),
                  SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON | SHGFI_SYSICONINDEX);
    lpdl->iDefIconFolder = shfi.iIcon;

    SHGetFileInfo(L"Icon", FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(SHFILEINFO),
                  SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON | SHGFI_SYSICONINDEX);
    lpdl->iDefIconFile = shfi.iIcon;

    // First of all terminate running icon thread
    DirList_TerminateIconThread(hwnd);

    // A Directory is strongly required
    if (!lpszDir || !*lpszDir)
        return (-1);

    lstrcpy(lpdl->szPath, lpszDir);

    // Init ListView
    SendMessage(hwnd, WM_SETREDRAW, 0, 0);
    ListView_DeleteAllItems(hwnd);

    // Init Filter
    DirList_CreateFilter(&dlf, lpszFileSpec, bExcludeFilter);

    // Init lvi
    lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
    lvi.iItem = 0;
    lvi.iSubItem = 0;
    lvi.pszText = LPSTR_TEXTCALLBACK;
    lvi.cchTextMax = MAX_PATH;
    lvi.iImage = I_IMAGECALLBACK;

    // Convert Directory to a UNICODE string
    /*MultiByteToWideChar(CP_ACP,
                        MB_PRECOMPOSED,
                        lpszDir,
                        -1,
                        wszDir,
                        MAX_PATH);*/
    lstrcpy(wszDir, lpszDir);

    // Get Desktop Folder
    if (NOERROR == SHGetDesktopFolder(&lpsfDesktop)) {

        // Convert wszDir into a pidl
        if (NOERROR ==
            lpsfDesktop->ParseDisplayName(hwnd, NULL, wszDir, &chParsed, &pidl, &dwAttributes)) {

            // Bind pidl to IShellFolder
            if (NOERROR == lpsfDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&lpsf)) {

                // Create an Enumeration object for lpsf
                if (NOERROR == lpsf->EnumObjects(hwnd, grfFlags, &lpe)) {

                    // Enumerate the contents of lpsf
                    while (NOERROR == lpe->Next(1, &pidlEntry, NULL)) {

                        // Add found item to the List
                        // Check if it's part of the Filesystem
                        dwAttributes = SFGAO_FILESYSTEM | SFGAO_FOLDER;

                        lpsf->GetAttributesOf(1, (LPCITEMIDLIST*)pidlEntry, &dwAttributes);

                        if (dwAttributes & SFGAO_FILESYSTEM) {

                            // Check if item matches specified filter
                            if (DirList_MatchFilter(lpsf, pidlEntry, &dlf)) {

                                lplvid = (LV_ITEMDATA*)CoTaskMemAlloc(sizeof(LV_ITEMDATA));

                                lplvid->pidl = pidlEntry;
                                lplvid->lpsf = lpsf;

                                lpsf->AddRef();

                                lvi.lParam = (LPARAM)lplvid;

                                // Setup default Icon - Folder or File
                                lvi.iImage = (dwAttributes & SFGAO_FOLDER) ? lpdl->iDefIconFolder
                                                                           : lpdl->iDefIconFile;

                                ListView_InsertItem(hwnd, &lvi);

                                lvi.iItem++;
                            }
                        }

                    } // IEnumIDList::Next()

                    lpe->Release();

                } // IShellFolder::EnumObjects()

            } // IShellFolder::BindToObject()

        } // IShellFolder::ParseDisplayName()

        lpsfDesktop->Release();

    } // SHGetDesktopFolder()

    if (lpdl->pidl)
        CoTaskMemFree(lpdl->pidl);

    if (lpdl->lpsf)
        lpdl->lpsf->Release();

    // Set lpdl
    lpdl->cbidl = IL_GetSize(pidl);
    lpdl->pidl = pidl;
    lpdl->lpsf = lpsf;
    lpdl->bNoFadeHidden = bNoFadeHidden;

    // Set column width to fit window
    ListView_SetColumnWidth(hwnd, 0, LVSCW_AUTOSIZE_USEHEADER);

    // Sort before display is updated
    DirList_Sort(hwnd, iSortFlags, fSortRev);

    // Redraw Listview
    SendMessage(hwnd, WM_SETREDRAW, 1, 0);

    // Return number of items in the control
    return (ListView_GetItemCount(hwnd));
}