/// Get registry values for ShellExtension void PropShell::GetContextRegValues() { CRegKeyEx reg; LONG retVal = 0; retVal = reg.Open(HKEY_CURRENT_USER, f_RegDir); if (retVal != ERROR_SUCCESS) { CString msg; msg.Format(_T("Failed to open registry key HKCU/%s:\n\t%d : %s"), f_RegDir, retVal, GetSysError(retVal).c_str()); LogErrorString(msg); return; } // Read bitmask for shell extension settings DWORD dwContextEnabled = reg.ReadDword(f_RegValueEnabled, 0); if (dwContextEnabled & CONTEXT_F_ENABLED) m_bContextAdded = TRUE; if (dwContextEnabled & CONTEXT_F_ADVANCED) m_bContextAdvanced = TRUE; if (dwContextEnabled & CONTEXT_F_SUBFOLDERS) m_bContextSubfolders = TRUE; }
// Check the registry to see if we have recorded the // column widths lastused for the job pane's list view. // Note that "HKEY_CURRENT_USER\Software\perforce\P4win\Layout\JobListDlg\Column Widths" // is no longer used because we use the "...\Job List\Column Widths" now. void CJobListDlg::RestoreSavedWidths(int *width, int numcols) { CRegKeyEx key; if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, sRegKey, KEY_READ)) { CString result = key.QueryValueString(sRegValue_ColumnWidths); CString sortCols = key.QueryValueString(sRegValue_SortColumns); if(!result.IsEmpty()) { // things can go wrong with the registry setting of the // widths. Use the defaults if the entry is all zeroes. // if ( result != _T("0,0,0,0,0,0,0,0,0,0") ) for(int i=0; i< numcols; i++) width[i]= GetPositiveNumber(result); } if(!sortCols.IsEmpty()) { for(int i=0; i< MAX_SORT_COLUMNS; i++) { m_SortColumns[i]= GetANumber(sortCols); if(!i && !m_SortColumns[i]) m_SortColumns[i] = 1; } m_LastSortColumn= abs(m_SortColumns[0]) - 1; // SortColumns are signed & 1-relative m_SortAscending = m_SortColumns[0] >= 0 ? TRUE : FALSE; } } }
/// Saves given path to registry for ShellExtension, and Context Menu settings void PropShell::SaveMergePath() { TCHAR temp[MAX_PATH] = {0}; LONG retVal = 0; GetModuleFileName(AfxGetInstanceHandle(), temp, MAX_PATH); CRegKeyEx reg; retVal = reg.Open(HKEY_CURRENT_USER, f_RegDir); if (retVal != ERROR_SUCCESS) { CString msg; msg.Format(_T("Failed to open registry key HKCU/%s:\n\t%d : %s"), f_RegDir, retVal, GetSysError(retVal).c_str()); LogErrorString(msg); return; } // Save path to WinMerge(U).exe retVal = reg.WriteString(f_RegValuePath, temp); if (retVal != ERROR_SUCCESS) { CString msg; msg.Format(_T("Failed to set registry value %s:\n\t%d : %s"), f_RegValuePath, retVal, GetSysError(retVal).c_str()); LogErrorString(msg); } // Determine bitmask for shell extension DWORD dwContextEnabled = reg.ReadDword(f_RegValueEnabled, 0); if (m_bContextAdded) dwContextEnabled |= CONTEXT_F_ENABLED; else dwContextEnabled &= ~CONTEXT_F_ENABLED; if (m_bContextAdvanced) dwContextEnabled |= CONTEXT_F_ADVANCED; else dwContextEnabled &= ~CONTEXT_F_ADVANCED; if (m_bContextSubfolders) dwContextEnabled |= CONTEXT_F_SUBFOLDERS; else dwContextEnabled &= ~CONTEXT_F_SUBFOLDERS; retVal = reg.WriteDword(f_RegValueEnabled, dwContextEnabled); if (retVal != ERROR_SUCCESS) { CString msg; msg.Format(_T("Failed to set registry value %s to %d:\n\t%d : %s"), f_RegValueEnabled, dwContextEnabled, retVal, GetSysError(retVal).c_str()); LogErrorString(msg); } }
CWindowsVersion::CWindowsVersion() { m_osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if(!GetVersionEx(&m_osv)) { ASSERT(0); // make sure nothing bad will happen trying to interpret OSVERSIONINFO memset((void*)&m_osv, 0, sizeof(m_osv)); } else { switch(m_osv.dwPlatformId) { case VER_PLATFORM_WIN32s: //Win32s on Windows 3.1. m_winVer = WV_32S; break; case VER_PLATFORM_WIN32_WINDOWS: //WIN32 on 95 or 98 or ME if(m_osv.dwMinorVersion == 0) { m_winVer = WV_95; } else if(m_osv.dwMinorVersion == 10) { m_winVer = WV_98; } if(m_osv.dwMinorVersion == 90) { m_winVer = WV_ME; } break; case VER_PLATFORM_WIN32_NT: //Win32 on Windows NT. if(m_osv.dwMajorVersion == 4) { m_winVer = WV_NT4; } else if(m_osv.dwMajorVersion >= 5) { m_winVer = WV_2K; } break; default: m_winVer = WV_UNKNOWN; break; } } // get the language m_UILang = 0; switch(m_winVer) { case WV_2K: { // Disable this section to emulate Windows NT before Windows 2000, when testing // on Windows 2000 // Use GetUserDefaultUILanguage to find the user's prefered UI language // Declare function pointer LANGID (WINAPI *pfnGetUserDefaultUILanguage) () = NULL ; HMODULE hMKernel32 = LoadLibraryW(L"kernel32.dll") ; pfnGetUserDefaultUILanguage = (unsigned short (WINAPI *)(void)) GetProcAddress(hMKernel32, "GetUserDefaultUILanguage") ; if(NULL != pfnGetUserDefaultUILanguage) m_UILang = pfnGetUserDefaultUILanguage() ; } break; case WV_NT4: { // Running on Windows NT 4.0 or earlier. Get UI language // from locale of .default user in registry: // HKEY_USERS\.DEFAULT\Control Panel\International\Locale CRegKeyEx key; if(ERROR_SUCCESS == key.Open(HKEY_USERS, _T(".DEFAULT\\Control Panel\\International"), KEY_READ)) { CString value = key.QueryValueString(_T("Locale")); m_UILang = (LANGID)_tcstol(value,NULL,16); }; } break; case WV_95: case WV_98: case WV_ME: { // Running on Windows 9x. Get the system UI language from registry: CRegKeyEx key; if(ERROR_SUCCESS == key.Open(HKEY_USERS, _T(".Default\\Control Panel\\desktop\\ResourceLocale"), KEY_READ)) { CString value = key.QueryValueString(_T("")); m_UILang = (LANGID)_tcstol(value, 0, 16); }; } break; } // get the common controls dll version m_comCtl32Version = GetDllVersion(_T("comctl32.dll")); }