【IE編程】給指定進程設置使用的內嵌IE的版本

1.進程如果使用內嵌IE(IWebBrowser2)時,如何給當前進程設置IE的版本號爲最新的呢?

第1步:添加頭文件browser_feature_control_helper.h

#ifndef BASE_BROWSER_FEATURE_CONTORL_HELPER_H_
#define BASE_BROWSER_FEATURE_CONTORL_HELPER_H_

#include <windows.h>
#include <shlwapi.h>

#include <string>
#include <vector>

class BrowserFeatureControlHelper {
 public:
  static void SetBrowserFeatureControl();
  static DWORD GetBrowserMode();
  static void RemoveBrowserFeature();
};

#endif  // SAMPLE_BROWSER_SRC_BROWSER_FEATURE_CONTORL_HELPER_H_

第2步:添加cpp文件browser_feature_control_helper.cc

#include "browser_feature_control_helper.h"

#include <windows.h>
#include <shlwapi.h>

#include <string>
#include <vector>

#include "base/win/registry.h"

namespace {

const wchar_t kFeaturePath[] = L"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\";

std::vector<std::string> StringSplit(const std::string &text, char sep) {
  std::vector<std::string> tokens;
  std::size_t start = 0, end = 0;
  while ((end = text.find(sep, start)) != std::string::npos) {
    tokens.push_back(text.substr(start, end - start));
    start = end + 1;
  }
  tokens.push_back(text.substr(start));
  return tokens;
}

LONG GetStringFromReg(HKEY key,
                      const std::string& key_name,
                      std::string* value,
                      const std::string& default_value) {
  *value = default_value;
  char buffer[512];
  DWORD buffer_size = sizeof(buffer);
  ULONG nError;
  nError = RegQueryValueExA(
      key, key_name.c_str(), 0, NULL, (LPBYTE)buffer, &buffer_size);
  if (ERROR_SUCCESS == nError) {
    *value = buffer;
  }
  return nError;
}

LONG GetDWORDFromReg(HKEY key,
                     const std::wstring& key_name,
                     DWORD* value,
                     DWORD default_value) {
  *value = default_value;
  DWORD buffer_size = sizeof(DWORD);
  DWORD result = 0;
  LONG nError = ::RegQueryValueExW(key,
                                   key_name.c_str(),
                                   0,
                                   NULL,
                                   reinterpret_cast<LPBYTE>(&result),
                                   &buffer_size);
  if (ERROR_SUCCESS == nError) {
    *value = result;
  }

  return nError;
}

DWORD GetBrowserEmulationMode() {
  // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx

  int browserVersion = 7;
  std::string sBrowserVersion;
  HKEY key;
  bool success = true;
  std::string path("SOFTWARE\\Microsoft\\Internet Explorer");
  LONG nError = RegOpenKeyExA(HKEY_LOCAL_MACHINE, path.c_str(), 0, KEY_QUERY_VALUE, &key);

  if (nError != ERROR_SUCCESS) {
    success = false;
  } else {
    nError = GetStringFromReg(key, "svcVersion", &sBrowserVersion, "7");
    if (nError != ERROR_SUCCESS) {
      nError = GetStringFromReg(key, "version", &sBrowserVersion, "7");
      if (nError != ERROR_SUCCESS) {
        success = false;
      }
    }

    if (RegCloseKey(key) != ERROR_SUCCESS) {
      success = false;
    }
  }

  DWORD mode = -1;
  if (success) {
    browserVersion = std::atoi(StringSplit(sBrowserVersion, '.').at(0).c_str()); // convert base 16 number in s to int
    switch (browserVersion) {
    case 6:
      mode = 6000;
      break;
    case 7:
      mode = 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
      break;
    case 8:
      mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
      break;
    case 9:
      mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
      break;
    case 10:
      mode = 10000;
      break;
    case 11:
      mode = 11000;
      break;

    default:
      // use IE10 mode by default
      mode = -1;
      break;
    }

  } else {
    mode = -1;
  }
  return mode;
}

bool SetBrowserFeatureControlKey(
    std::wstring feature, wchar_t* appName, DWORD value) {
  HKEY key;
  bool success = true;
  std::wstring featuresPath(L"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\");
  std::wstring path(featuresPath + feature);

  LONG nError = RegCreateKeyEx(HKEY_CURRENT_USER, path.c_str(), 0, NULL, REG_OPTION_VOLATILE, KEY_WRITE, NULL, &key, NULL);
  if (nError != ERROR_SUCCESS) {
    success = false;

  } else {
    nError = RegSetValueExW(key, appName, 0, REG_DWORD, (const BYTE*)&value, sizeof(value));
    if (nError != ERROR_SUCCESS) {
      success = false;
    }

    nError = RegCloseKey(key);
    if (nError != ERROR_SUCCESS) {
      success = false;
    }
  }

  return success;
}

void DeleteBrowserFeatureKey(
    const std::wstring& feature, const wchar_t* app_name) {
	HKEY key = NULL;
	std::wstring str_sub_key = kFeaturePath + feature;
	LONG nError = RegOpenKeyEx(HKEY_CURRENT_USER, str_sub_key.c_str(), 0, KEY_WRITE, &key);
	if (nError != ERROR_SUCCESS || NULL == key) {
		return;
	}

	RegDeleteValue(key, app_name);
	RegCloseKey(key);
}

}

// static
void BrowserFeatureControlHelper::SetBrowserFeatureControl() {
  DWORD emulationMode = GetBrowserEmulationMode();

  if (emulationMode > 0) {
    // FeatureControl settings are per-process
    wchar_t moduleFileName[MAX_PATH + 1];
    wchar_t appName[MAX_PATH + 1];

    ZeroMemory(appName, (MAX_PATH + 1) * sizeof(wchar_t));
    GetModuleFileNameW(NULL, moduleFileName, 256);
    wchar_t* pfilename = ::PathFindFileNameW(moduleFileName);

    StrCpyW(appName, pfilename);

    // Windows Internet Explorer 8 and later. The FEATURE_BROWSER_EMULATION feature defines the default emulation mode for Internet
    // Explorer and supports the following values.
    // Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
    SetBrowserFeatureControlKey(L"FEATURE_BROWSER_EMULATION", appName, emulationMode);

    // Internet Explorer 8 or later. The FEATURE_AJAX_CONNECTIONEVENTS feature enables events that occur when the value of the online
    // property of the navigator object changes, such as when the user chooses to work offline. For more information, see the ononline
    // and onoffline events.
    // Default: DISABLED
    SetBrowserFeatureControlKey(L"FEATURE_AJAX_CONNECTIONEVENTS", appName, 1);

    // Internet Explorer 9. Internet Explorer 9 optimized the performance of window-drawing routines that involve clipping regions associated
    // with child windows. This helped improve the performance of certain window drawing operations. However, certain applications hosting the
    // WebBrowser Control rely on the previous behavior and do not function correctly when these optimizations are enabled. The
    // FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION feature can disable these optimizations.
    // Default: ENABLED
    // SetBrowserFeatureControlKey(L"FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", fileName, 1);

    // Internet Explorer 8 and later. By default, Internet Explorer reduces memory leaks caused by circular references between Internet Explorer
    // and the Microsoft JScript engine, especially in scenarios where a webpage defines an expando and the page is refreshed. If a legacy
    // application no longer functions with these changes, the FEATURE_MANAGE_SCRIPT_CIRCULAR_REFS feature can disable these improvements.
    // Default: ENABLED
    // SetBrowserFeatureControlKey(L"FEATURE_MANAGE_SCRIPT_CIRCULAR_REFS", fileName, 1);

    // Windows Internet Explorer 8. When enabled, the FEATURE_DOMSTORAGE feature allows Internet Explorer and applications hosting the WebBrowser
    // Control to use the Web Storage API. For more information, see Introduction to Web Storage.
    // Default: ENABLED
    // SetBrowserFeatureControlKey(L"FEATURE_DOMSTORAGE ", fileName, 1);

    // Internet Explorer 9. The FEATURE_GPU_RENDERING feature enables Internet Explorer to use a graphics processing unit (GPU) to render content.
    // This dramatically improves performance for webpages that are rich in graphics.
    // Default: DISABLED
    SetBrowserFeatureControlKey(L"FEATURE_GPU_RENDERING", appName, 1);

    // Internet Explorer 9. By default, the WebBrowser Control uses Microsoft DirectX to render webpages, which might cause problems for
    // applications that use the Draw method to create bitmaps from certain webpages. In Internet Explorer 9, this method returns a bitmap
    // (in a Windows Graphics Device Interface (GDI) wrapper) instead of a GDI metafile representation of the webpage. When the
    // FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI feature is enabled, the following conditions cause the Draw method to use GDI instead of DirectX
    // to create the resulting representation. The GDI representation will contain text records and vector data, but is not guaranteed to be
    // similar to the same represenation returned in earlier versions of the browser:
    //    The device context passed to the Draw method points to an enhanced metafile.
    //    The webpage is not displayed in IE9 Standards mode.
    // By default, this feature is ENABLED for applications hosting the WebBrowser Control. This feature is ignored by Internet Explorer and
    // Windows Explorer. To enable this feature by using the registry, add the name of your executable file to the following setting.
    SetBrowserFeatureControlKey(L"FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI", appName, 0);

    // Windows 8 introduces a new input model that is different from the Windows 7 input model. In order to provide the broadest compatibility
    // for legacy applications, the WebBrowser Control for Windows 8 emulates the Windows 7 mouse, touch, and pen input model (also known as the
    // legacy input model). When the legacy input model is in effect, the following conditions are true:
    //    Windows pointer messages are not processed by the Trident rendering engine (mshtml.dll).
    //    Document Object Model (DOM) pointer and gesture events do not fire.
    //    Mouse and touch messages are dispatched according to the Windows 7 input model.
    //    Touch selection follows the Windows 7 model ("drag to select") instead of the Windows 8 model ("tap to select").
    //    Hardware accelerated panning and zooming is disabled.
    //    The Zoom and Pan Cascading Style Sheets (CSS) properties are ignored.
    // The FEATURE_NINPUT_LEGACYMODE feature control determines whether the legacy input model is enabled
    // Default: ENABLED
    SetBrowserFeatureControlKey(L"FEATURE_NINPUT_LEGACYMODE", appName, 0);

    // Internet Explorer 7 consolidated HTTP compression and data manipulation into a centralized component in order to improve performance and
    // to provide greater consistency between transfer encodings (such as HTTP no-cache headers). For compatibility reasons, the original
    // implementation was left in place. When the FEATURE_DISABLE_LEGACY_COMPRESSION feature is disabled, the original compression implementation
    // is used.
    // Default: ENABLED
    // SetBrowserFeatureControlKey(L"FEATURE_DISABLE_LEGACY_COMPRESSION", fileName, 1);

    // When the FEATURE_LOCALMACHINE_LOCKDOWN feature is enabled, Internet Explorer applies security restrictions on content loaded from the
    // user's local machine, which helps prevent malicious behavior involving local files:
    //    Scripts, Microsoft ActiveX controls, and binary behaviors are not allowed to run.
    //    Object safety settings cannot be overridden.
    //    Cross-domain data actions require confirmation from the user.
    // Default: DISABLED
    // SetBrowserFeatureControlKey(L"FEATURE_LOCALMACHINE_LOCKDOWN", fileName, 0);

    // Internet Explorer 7 and later. When enabled, the FEATURE_BLOCK_LMZ_??? feature allows ??? stored in the Local Machine zone to be
    // loaded only by webpages loaded from the Local Machine zone or by webpages hosted by sites in the Trusted Sites list. For more information,
    // see Security and Compatibility in Internet Explorer 7.
    // Default: DISABLED
    //    FEATURE_BLOCK_LMZ_IMG can block images that try to load from the user's local file system. To opt in, add your process name and set 
    //                          the value to 0x00000001.
    //    FEATURE_BLOCK_LMZ_OBJECT can block objects that try to load from the user's local file system. To opt in, add your process name and
    //                          set the value to 0x00000001.
    //    FEATURE_BLOCK_LMZ_SCRIPT can block script access from the user's local file system. To opt in, add your process name and set the value
    //                          to 0x00000001.
    // SetBrowserFeatureControlKey(L"FEATURE_BLOCK_LMZ_OBJECT", fileName, 0);
    // SetBrowserFeatureControlKey(L"FEATURE_BLOCK_LMZ_OBJECT", fileName, 0);
    // SetBrowserFeatureControlKey(L"FEATURE_BLOCK_LMZ_SCRIPT", fileName, 0);

    // Internet Explorer 8 and later. When enabled, the FEATURE_DISABLE_NAVIGATION_SOUNDS feature disables the sounds played when you open a
    // link in a webpage.
    // Default: DISABLED
    SetBrowserFeatureControlKey(L"FEATURE_DISABLE_NAVIGATION_SOUNDS", appName, 1);

    // Windows Internet Explorer 7 and later. Prior to Internet Explorer 7, href attributes of a objects supported the javascript prototcol;
    // this allowed webpages to execute script when the user clicked a link. For security reasons, this support was disabled in Internet
    // Explorer 7. For more information, see Event 1034 - Cross-Domain Barrier and Script URL Mitigation.
    // When enabled, the FEATURE_SCRIPTURL_MITIGATION feature allows the href attribute of a objects to support the javascript prototcol. 
    // Default: DISABLED
    SetBrowserFeatureControlKey(L"FEATURE_SCRIPTURL_MITIGATION", appName, 1);

    // For Windows 8 and later, the FEATURE_SPELLCHECKING feature controls this behavior for Internet Explorer and for applications hosting
    // the web browser control (WebOC). When fully enabled, this feature automatically corrects grammar issues and identifies misspelled words
    // for the conditions described earlier.
    //    (DWORD) 00000000 - Features are disabled.
    //    (DWORD) 00000001 - Features are enabled for the conditions described earlier. (This is the default value.)
    //    (DWORD) 00000002 - Features are enabled, but only for elements that specifically set the spellcheck attribute to true.
    SetBrowserFeatureControlKey(L"FEATURE_SPELLCHECKING", appName, 0);

    // When enabled, the FEATURE_STATUS_BAR_THROTTLING feature limits the frequency of status bar updates to one update every 200 milliseconds.
    // Default: DISABLED
    SetBrowserFeatureControlKey(L"FEATURE_STATUS_BAR_THROTTLING", appName, 1);

    // Internet Explorer 7 or later. When enabled, the FEATURE_TABBED_BROWSING feature enables tabbed browsing navigation shortcuts and
    // notifications. For more information, see Tabbed Browsing for Developers.
    // Default: DISABLED
    // SetBrowserFeatureControlKey(L"FEATURE_TABBED_BROWSING", fileName, 1);

    // When enabled, the FEATURE_VALIDATE_NAVIGATE_URL feature control prevents Windows Internet Explorer from navigating to a badly formed URL.
    // Default: DISABLED
    SetBrowserFeatureControlKey(L"FEATURE_VALIDATE_NAVIGATE_URL", appName, 1);

    // When enabled,the FEATURE_WEBOC_DOCUMENT_ZOOM feature allows HTML dialog boxes to inherit the zoom state of the parent window.
    // Default: DISABLED
    SetBrowserFeatureControlKey(L"FEATURE_WEBOC_DOCUMENT_ZOOM", appName, 0);

    // The FEATURE_WEBOC_POPUPMANAGEMENT feature allows applications hosting the WebBrowser Control to receive the default Internet Explorer
    // pop-up window management behavior.
    // Default: ENABLED
    SetBrowserFeatureControlKey(L"FEATURE_WEBOC_POPUPMANAGEMENT", appName, 0);

    // Applications hosting the WebBrowser Control should ensure that window resizing and movement events are handled appropriately for the
    // needs of the application. By default, these events are ignored if the WebBrowser Control is not hosted in a proper container. When enabled,
    // the FEATURE_WEBOC_MOVESIZECHILD feature allows these events to affect the parent window of the application hosting the WebBrowser Control.
    // Because this can lead to unpredictable results, it is not considered desirable behavior.
    // Default: DISABLED
    // SetBrowserFeatureControlKey(L"FEATURE_WEBOC_MOVESIZECHILD", fileName, 0);

    // The FEATURE_ADDON_MANAGEMENT feature enables applications hosting the WebBrowser Control
    // to respect add-on management selections made using the Add-on Manager feature of Internet Explorer.
    // Add-ons disabled by the user or by administrative group policy will also be disabled in applications that enable this feature.
    SetBrowserFeatureControlKey(L"FEATURE_ADDON_MANAGEMENT", appName, 0);

    // Internet Explorer 10. When enabled, the FEATURE_WEBSOCKET feature allows script to create and use WebSocket objects.
    // The WebSocketobject allows websites to request data across domains from your browser by using the WebSocket protocol.
    // Default: ENABLED
    SetBrowserFeatureControlKey(L"FEATURE_WEBSOCKET", appName, 1);

    // When enabled, the FEATURE_WINDOW_RESTRICTIONS feature adds several restrictions to the size and behavior of popup windows:
    //    Popup windows must appear in the visible display area.
    //    Popup windows are forced to have status and address bars.
    //    Popup windows must have minimum sizes.
    //    Popup windows cannot cover important areas of the parent window.
    // When enabled, this feature can be configured differently for each security zone by using the URLACTION_FEATURE_WINDOW_RESTRICTIONS URL
    // action flag. 
    // Default: ENABLED
    SetBrowserFeatureControlKey(L"FEATURE_WINDOW_RESTRICTIONS", appName, 0);

    // Internet Explorer 7 and later. The FEATURE_XMLHTTP feature enables or disables the native XMLHttpRequest object.
    // Default: ENABLED
    // SetBrowserFeatureControlKey(L"FEATURE_XMLHTTP", fileName, 1);
  }
}

// static
DWORD BrowserFeatureControlHelper::GetBrowserMode() {
  return GetBrowserEmulationMode();
}

// static
void BrowserFeatureControlHelper::RemoveBrowserFeature() {
  wchar_t module_filename[MAX_PATH + 1];
  wchar_t app_name[MAX_PATH + 1];
  ZeroMemory(app_name, (MAX_PATH + 1) * sizeof(wchar_t));
  ZeroMemory(module_filename, (MAX_PATH + 1) * sizeof(wchar_t));
  GetModuleFileNameW(NULL, module_filename, MAX_PATH);
  wchar_t* filename = ::PathFindFileNameW(module_filename);
  StrCpyW(app_name, filename);

  DeleteBrowserFeatureKey(L"FEATURE_ACTIVEX_REPURPOSEDETECTION", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_ADDON_MANAGEMENT", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_AJAX_CONNECTIONEVENTS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_ALIGNED_TIMERS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_ALLOW_HIGHFREQ_TIMERS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_BEHAVIORS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_BLOCK_CROSS_PROTOCOL_FILE_NAVIGATION", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_BLOCK_LMZ_IMG", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_BLOCK_LMZ_OBJECT", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_BLOCK_LMZ_SCRIPT", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_BROWSER_EMULATION", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_DISABLE_ISO_2022_JP_SNIFFING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_DISABLE_ISO_2022_JP_SNIFFING_V2", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_DISABLE_MK_PROTOCOL", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_DISABLE_SQM_UPLOAD_FOR_APP", app_name);
  DeleteBrowserFeatureKey(L"Feature_Enable_Compat_Logging", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_ENABLE_DYNAMIC_OBJECT_CACHING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_ENABLE_SCRIPT_PASTE_URLACTION_IF_PROMPT", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_ENABLE_WEB_CONTROL_VISUALS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_ENFORCE_BSTR", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_FEEDS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_FORCE_DISABLE_UNTRUSTEDPROTOCOL", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_GPU_RENDERING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_HIGH_RESOLUTION_AWARE", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_HTTP_USERNAME_PASSWORD_DISABLE", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_INTERNET_SHELL_FOLDERS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_LAYOUT9_QUIRKS_EMULATION", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_LEGACY_DISPPARAMS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_LOCALMACHINE_LOCKDOWN", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_MAXCONNECTIONSPER1_0SERVER", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_MAXCONNECTIONSPERSERVER", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_MIME_HANDLING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_MIME_SNIFFING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_NINPUT_LEGACYMODE", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_OBJECT_CACHING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_PAINT_INSIDE_WMPAINT", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_PRIVATE_FONT_SETTING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_PROTOCOL_LOCKDOWN", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_RESTRICT_ABOUT_PROTOCOL_IE7", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_SAFE_BINDTOOBJECT", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_SCRIPTURL_MITIGATION", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_SECURITYBAND", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_SHOW_APP_PROTOCOL_WARN_DIALOG", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_TABBED_BROWSING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_USE_LEGACY_JSCRIPT", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_USE_QME_FOR_TOPLEVEL_DOCS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_USE_SECURITY_THUNKS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_USE_WEBOC_OMNAVIGATOR_IMPLEMENTATION", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_VALIDATE_NAVIGATE_URL", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_VIEWLINKEDWEBOC_IS_UNSAFE", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_WEBOC_DOCUMENT_ZOOM", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_WINDOW_RESTRICTIONS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_XSSFILTER", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_ZONE_ELEVATION", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_DISABLE_NAVIGATION_SOUNDS", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_SPELLCHECKING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_STATUS_BAR_THROTTLING", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_WEBOC_POPUPMANAGEMENT", app_name);
  DeleteBrowserFeatureKey(L"FEATURE_WEBSOCKET", app_name);
}

第3步:主函數調用

int main()
{
	// 給進程設置瀏覽器版本號
	BrowserFeatureControlHelper::SetBrowserFeatureControl();
	
    //to do 
    ...............

	//移除瀏覽器版本號
	BrowserFeatureControlHelper::RemoveBrowserFeature();
	

	system("pause");
    return 0;
}

結果:

BrowserFeatureControlHelper::SetBrowserFeatureControl()設置後:

BrowserFeatureControlHelper::RemoveBrowserFeature();刪除後:

 

demo如下:【IE編程】給指定進程設置使用的內嵌IE的版本

 

發佈了45 篇原創文章 · 獲贊 21 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章