prop.cpp
资源名称:shell.rar [点击查看]
上传用户:xhy777
上传日期:2007-02-14
资源大小:24088k
文件大小:27k
源码类别:
系统编程
开发平台:
Visual C++
- #include "precomp.hxx"
- #pragma hdrstop
- #include "util.h"
- #include "dll.h"
- #include "resource.h"
- #include "prop.h"
- #include <shellids.h> // IDH_ values
- #include "shlguidp.h"
- #include "inetreg.h"
- STDAPI SHGetIDispatchForFolder(LPCITEMIDLIST pidl, IWebBrowserApp **ppauto); // <shdocvw.h>
- typedef struct {
- HWND hDlg;
- BOOL bDirty;
- BOOL bInitDone;
- IPersistFolder* ppf;
- TCHAR szMyDocs[ MAX_PATH ];
- } CUSTINFO;
- TCHAR g_szPropTitle[ MAX_PATH + 32 ];
- const static DWORD rgdwHelpTarget[] = {
- IDD_TARGET_TXT, IDH_MYDOCS_TARGET,
- IDD_TARGET, IDH_MYDOCS_TARGET,
- IDD_FIND, IDH_MYDOCS_FIND_TARGET,
- IDD_BROWSE, IDH_MYDOCS_BROWSE,
- IDD_RESET, IDH_MYDOCS_RESET,
- 0, 0
- };
- LPTSTR GetMessageTitle( VOID )
- {
- if (!(*g_szPropTitle))
- {
- TCHAR szFormat[ 64 ];
- TCHAR szName[ MAX_PATH ];
- LoadString( g_hInstance, IDS_PROP_ERROR_TITLE, szFormat, ARRAYSIZE(szFormat) );
- GetMyDocumentsDisplayName( szName, ARRAYSIZE(szName) );
- wnsprintf( g_szPropTitle, ARRAYSIZE(g_szPropTitle), szFormat, szName );
- }
- return g_szPropTitle;
- }
- // pPath is assumed to be MAX_PATH big
- void GetTargetPath( HWND hDlg, LPTSTR pPath )
- {
- TCHAR szUnExPath[ MAX_PATH ];
- *pPath = 0;
- szUnExPath[0] = 0;
- GetDlgItemText( hDlg, IDD_TARGET, szUnExPath, ARRAYSIZE(szUnExPath) );
- if (szUnExPath[0])
- {
- // Turn "c:" into "c:", but don't change other paths:
- PathAddBackslash(szUnExPath);
- PathRemoveBackslash(szUnExPath);
- ExpandEnvironmentStrings( szUnExPath, pPath, MAX_PATH );
- }
- }
- // Check known key in the registry to see if policy has disabled changing
- // of My Docs location.
- BOOL CanChangePersonalPath( void )
- {
- HKEY hkey;
- BOOL bChange = TRUE;
- if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"), 0, KEY_READ, &hkey))
- {
- bChange = (ERROR_SUCCESS != RegQueryValueEx(hkey, TEXT("DisablePersonalDirChange"), NULL, NULL, NULL, NULL));
- RegCloseKey(hkey);
- }
- return bChange;
- }
- BOOL InitTargetPage( HWND hDlg, LPARAM lParam )
- {
- TCHAR szPath[ MAX_PATH ];
- CUSTINFO *pci;
- TCHAR szFormat[ MAX_PATH ];
- TCHAR szText[ ARRAYSIZE(szFormat) + MAX_NAME_LEN ];
- TCHAR szName[ MAX_PATH ];
- *g_szPropTitle = 0;
- pci = (CUSTINFO *)LocalAlloc(LPTR, sizeof(*pci));
- if (pci == NULL)
- return FALSE;
- SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pci);
- pci->hDlg = hDlg;
- // Fill in title/instructions...
- GetMyDocumentsDisplayName( szName, ARRAYSIZE(szName) );
- if (lstrlen(szName) > MAX_NAME_LEN)
- {
- lstrcpy( &szName[MAX_NAME_LEN], TEXT("...") );
- }
- LoadString(g_hInstance, IDS_PROP_INSTRUCTIONS, szFormat, ARRAYSIZE(szFormat));
- wnsprintf(szText, ARRAYSIZE(szText), szFormat, szName);
- SetDlgItemText( hDlg, IDD_INSTRUCTIONS, szText );
- // Limit edit field to MAX_PATH-13 characters. Why -13?
- // Well, 13 is the number of characters in a DOS style 8.3
- // filename with a '', and CreateDirectory will fail if you try to create
- // a directory that can't at least contain 8.3 file names.
- SendDlgItemMessage( hDlg, IDD_TARGET, EM_SETLIMITTEXT, MAX_DIR_PATH, 0 );
- // Check whether path can be changed
- if (CanChangePersonalPath())
- {
- // set up autocomplete in target edit box:
- HRESULT hr = CoCreateInstance(CLSID_ACListISF, NULL, CLSCTX_INPROC_SERVER, IID_IPersistFolder, (void **)&(pci->ppf));
- if (SUCCEEDED(hr))
- {
- IAutoComplete2* pac;
- // Create the AutoComplete Object
- hr = CoCreateInstance(CLSID_AutoComplete, NULL, CLSCTX_INPROC_SERVER, IID_IAutoComplete2, (void **)&pac);
- if (SUCCEEDED(hr))
- {
- hr = pac->Init(GetDlgItem(hDlg, IDD_TARGET), pci->ppf, NULL, NULL);
- // Set the autocomplete options
- DWORD dwOptions = 0;
- if (SHRegGetBoolUSValue(REGSTR_PATH_AUTOCOMPLETE, REGSTR_VAL_USEAUTOAPPEND, FALSE, /*default:*/FALSE))
- {
- dwOptions |= ACO_AUTOAPPEND;
- }
- if (SHRegGetBoolUSValue(REGSTR_PATH_AUTOCOMPLETE, REGSTR_VAL_USEAUTOSUGGEST, FALSE, /*default:*/TRUE))
- {
- dwOptions |= ACO_AUTOSUGGEST;
- }
- pac->SetOptions(dwOptions);
- pac->Release();
- }
- }
- }
- else
- {
- // Make edit field read only
- SendDlgItemMessage( hDlg, IDD_TARGET, EM_SETREADONLY, (WPARAM)TRUE, 0L );
- ShowWindow( GetDlgItem( hDlg, IDD_RESET ), SW_HIDE );
- ShowWindow( GetDlgItem( hDlg, IDD_FIND ), SW_HIDE );
- ShowWindow( GetDlgItem( hDlg, IDD_BROWSE ), SW_HIDE );
- }
- SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_DONT_VERIFY, NULL, SHGFP_TYPE_CURRENT, szPath);
- if (szPath[0])
- {
- SetDlgItemText(hDlg, IDD_TARGET, szPath);
- lstrcpy(pci->szMyDocs, szPath);
- }
- LPITEMIDLIST pidlMyDocs = MyDocsIDList();
- if (pidlMyDocs)
- {
- SHFILEINFO sfi;
- SHGetFileInfo((LPCTSTR)pidlMyDocs, 0, &sfi, SIZEOF(sfi), SHGFI_ICON | SHGFI_LARGEICON | SHGFI_PIDL);
- if (sfi.hIcon)
- {
- if (sfi.hIcon = (HICON)SendDlgItemMessage(hDlg, IDD_ITEMICON, STM_SETICON, (WPARAM)sfi.hIcon, 0L))
- DestroyIcon(sfi.hIcon);
- }
- ILFree(pidlMyDocs);
- }
- pci->bInitDone = TRUE;
- return TRUE;
- }
- int MyMoveFiles( HWND hDlg, LPCTSTR pNewPath, LPCTSTR pOldPath, LPCTSTR pMyPicsPath, BOOL *pfResetMyPics )
- {
- TCHAR szSrcPath[ MAX_PATH + 1 ]; // +1 for double null
- TCHAR szDestPath[ MAX_PATH ];
- SHFILEOPSTRUCT FileOp;
- BOOL fMyPicsCollide = FALSE;
- memset(&szSrcPath, 0, sizeof(szSrcPath));
- memset(&szDestPath, 0, sizeof(szDestPath));
- memset(&FileOp, 0, sizeof(FileOp));
- ASSERT( pfResetMyPics );
- if( *pfResetMyPics && pMyPicsPath && *pMyPicsPath )
- {
- LPTSTR pszMyPicsName = PathFindFileName( pMyPicsPath );
- PathCombine( szDestPath, pNewPath, pszMyPicsName );
- DWORD dwAtt;
- if( PathFileExistsAndAttributes( szDestPath, &dwAtt ))
- {
- fMyPicsCollide = (FILE_ATTRIBUTE_DIRECTORY == (FILE_ATTRIBUTE_DIRECTORY & dwAtt));
- }
- }
- FileOp.hwnd = hDlg;
- FileOp.wFunc = FO_MOVE;
- // While we'll no longer create a duplicate MyPictures, using this
- // flag will create "Copy of..." for other duplicated folders. Adding
- // full folder merging capabilities to SHFileOperation would require
- // numerous changes to the copy engine.
- FileOp.fFlags = FOF_RENAMEONCOLLISION;
- if( fMyPicsCollide )
- {
- ChangeMyPicsPath( szDestPath, pMyPicsPath ); // szDestPath set above
- // Don't want ResetMyPictures to be called later on
- *pfResetMyPics = FALSE;
- // Move items in current MyPics to new location
- PathCombine( szSrcPath, pMyPicsPath, TEXT("*.*") );
- FileOp.pFrom = szSrcPath;
- FileOp.pTo = szDestPath;
- int iResult = SHFileOperation( &FileOp );
- if( 0 != iResult || FileOp.fAnyOperationsAborted )
- {
- return iResult;
- }
- RemoveDirectory( pMyPicsPath );
- // FileOp.pFrom is double
English
