zoukankan      html  css  js  c++  java
  • 关于在IWebBrowser中无法响应Ctrl+C等快捷键的解决方法

    最近在WIN32项目中用到IWebBrower2接口,发现复制粘贴等快捷键无法使用,后再网上查询到可以再消息循环阶段拦截IE的消息进行处理,代码如下:

     1 if (msg.message >= WM_KEYDOWN  && msg.message < WM_KEYLAST) {
     2       TCHAR szClassName[256] = {0};
     3       ::GetClassName(msg.hwnd, szClassName, 256);
     4       if (_tcsicmp(szClassName, _T("Internet Explorer_Server")) == 0) {
     5         HMODULE hModule = ::LoadLibrary(_T("OLEACC.DLL"));
     6         if (hModule) {
     7           LRESULT lRes;
     8           UINT nMsg = ::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
     9           ::SendMessageTimeout(msg.hwnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes);
    10           LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress(hModule, _T("ObjectFromLresult"));
    11           if (pfObjectFromLresult)  {
    12             CComPtr<IServiceProvider> spServiceProv;
    13             HRESULT hr = (*pfObjectFromLresult)(lRes, IID_IServiceProvider, 0, (void**)&spServiceProv);
    14             if (SUCCEEDED(hr)) {
    15               IWebBrowser2* pWebBrowser2 = NULL;
    16               hr = spServiceProv->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&pWebBrowser2);
    17               IOleInPlaceActiveObject* pOleInPlaceActiveObject = NULL;
    18               hr = pWebBrowser2->QueryInterface(IID_IOleInPlaceActiveObject, (LPVOID*)&pOleInPlaceActiveObject);
    19               if (hr == S_OK && pOleInPlaceActiveObject) {
    20                 hr = pOleInPlaceActiveObject->TranslateAccelerator(&msg);
    21                 DWORD dw = ::GetLastError();
    22                 if (hr == S_OK) {
    23                   continue;
    24                 }
    25               }
    26             }
    27           }
    28           ::FreeLibrary( hModule );
    29         }
    30       }
    31     }
  • 相关阅读:
    6. Flask请求和响应
    5. Flask模板
    FW:Software Testing
    What is the difference between modified duration, effective duration and duration?
    How to push master to QA branch in GIT
    FTPS Firewall
    Query performance optimization of Vertica
    (Forward)5 Public Speaking Tips That'll Prepare You for Any Interview
    (转)The remote certificate is invalid according to the validation procedure
    Change
  • 原文地址:https://www.cnblogs.com/siceblue/p/3133491.html
Copyright © 2011-2022 走看看