感谢coolslob的帮助, 我被这个问题困惑很久的,今天终于找到的合适的解决方案
参考链接如下:
三问文件夹选项更改后刷新的问题
http://topic.csdn.net/u/20081121/11/f5034a2f-26ae-4f74-a357-1fbd33576883.html 再问文件夹选项更改后刷新的问题
http://topic.csdn.net/u/20081108/18/ab4009f0-bfd1-4af6-873d-06ec7837236a.html
在程序中怎么调用设置文件夹选项的功能?
http://topic.csdn.net/u/20081104/11/b79c58c2-7887-4144-87d0-e9486685cb87.html
实现代码如下:
bool ShowAllFilesInExplorer(bool isShowHidden/*对应[显示所有的文件和文件夹]*/, bool isShowSysProtected/*对应[显示受操作系统保护的文件]*/, bool isShowFileExt/*对应[隐藏已知文件类型的扩展名]*/)
{
HKEY hKey = {0};
bool bRet = true;
if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced"), 0, KEY_SET_VALUE, &hKey))
{
DWORD dwShowHidden = isShowHidden ? 1 : 2;
DWORD dwShowSysProtected = isShowSysProtected ? 1 : 0;
DWORD dwShowFileExt= isShowFileExt? 0: 1;
if (ERROR_SUCCESS != ::RegSetValueEx(hKey, TEXT("Hidden"), 0, REG_DWORD, (LPBYTE)&dwShowHidden, (DWORD)sizeof(dwShowHidden))
||ERROR_SUCCESS != ::RegSetValueEx(hKey, TEXT("ShowSuperHidden"), 0, REG_DWORD, (LPBYTE)&dwShowSysProtected, (DWORD)sizeof(dwShowSysProtected))
|| ERROR_SUCCESS != ::RegSetValueEx(hKey, TEXT("HideFileExt"), 0, REG_DWORD, (LPBYTE)&dwShowFileExt, (DWORD)sizeof(dwShowFileExt)))
{
bRet = false;
}
::RegCloseKey(hKey);
}
else
{
bRet = false;
}
if (bRet)
{
::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)TEXT("ShellState"), SMTO_ABORTIFHUNG, 3000, NULL);
::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
}
return bRet;
}