客户端程序内嵌Webbrowser控件时,默认情况都是使用IE7兼容模式打开网页的。但是IE7有很多新的特性不支持,导致无法正常显示出来,所以需要强制使用高版本的IE内核来加载、渲染。
1 void ChangeRegedit(const wchar_t* pExeName) 2 { 3 if ( NULL == pExeName ) 4 return ; 5 TCHAR szVersion[64] = {0}; 6 DWORD dwSize = 64; 7 HKEY hKey; 8 // 先获取IE版本 9 if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Internet Explorer"), 0, KEY_READ, &hKey)) 10 { 11 //首先读取IE11的位置 12 DWORD dwIeVersion = 0; 13 if ( ERROR_SUCCESS == RegQueryValueEx(hKey, L"svcVersion", 0, NULL, (LPBYTE)szVersion, &dwSize) ) 14 { 15 TCHAR *pos = _tcschr(szVersion, TEXT(‘.‘)); 16 if ( pos ) 17 dwIeVersion = _ttoi(szVersion); 18 } 19 if ( dwIeVersion == 0 ) 20 {//读取IE低版本的位置 21 if ( ERROR_SUCCESS == (hKey, L"Version", 0, NULL, (LPBYTE)szVersion, &dwSize) ) 22 { 23 TCHAR *pos = _tcschr(szVersion, TEXT(‘.‘)); 24 if (NULL == pos) 25 { 26 RegCloseKey(hKey); 27 return ; 28 } 29 *pos = 0; 30 dwIeVersion = _ttoi(szVersion); 31 } 32 } 33 RegCloseKey(hKey); 34 switch( dwIeVersion ) 35 { 36 case 11: dwIeVersion = 11001; break; 37 case 10: dwIeVersion = 10001; break; 38 case 9: dwIeVersion = 9999; break; 39 case 8: dwIeVersion = 8888; break; 40 default: return ; 41 } 42 // 设置应用程序使用的IE版本 43 if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", 0, KEY_WRITE, &hKey)) 44 { 45 dwSize = sizeof(dwIeVersion); 46 RegSetValueEx(hKey, pExeName, 0, REG_DWORD, (LPBYTE)&dwIeVersion, dwSize); 47 RegCloseKey(hKey); 48 } 49 } 50 }
转载:http://blog.csdn.net/mfcing/article/details/50460433
时间: 2024-09-30 00:04:37