2013-05-07 14 views
1

我想COMPLETELY摆脱“脱机工作”消息框。如何在IE 8中摆脱“离线模式”的信息低头?

enter image description here

给予一定的情况下,会出现运行本地 web应用程序的机器上此消息框。 对网络的访问显然是不稳定的,所以瞬间缺乏不应该被阻塞:它只会延迟一些背景通知。网页只需要显示本地资源。该网址看起来像http://localhost:4444/*myApp*/...

机器运行在XP专业版,浏览器是IE8。

我曾尝试以下解决方案没有成功:

  1. 手工取消选中菜单选项文件/脱机工作是不够的。
  2. 通过调用此方法达到每200ms

    [DllImport("wininet.dll")] 
    private extern static bool InternetSetOption(int hInternet, 
    int dwOption, ref INTERNET_CONNECTED_INFO lpBuffer, int dwBufferLength); 
    
    [StructLayout(LayoutKind.Sequential)] 
    struct INTERNET_CONNECTED_INFO 
    { 
        public int dwConnectedState; 
        public int dwFlags; 
    }; 
    private static readonly int INTERNET_STATE_DISCONNECTED = 16; 
    private static readonly int INTERNET_STATE_CONNECTED = 1; 
    private static readonly int ISO_FORCE_DISCONNECTED = 1; 
    private static readonly int INTERNET_OPTION_CONNECTED_STATE = 50; 
    
    private static Timer aTimer; 
    private bool offlineSelected = false; 
    
    public void SetIEOfflineMode(bool offline) 
    { 
        INTERNET_CONNECTED_INFO ici = new INTERNET_CONNECTED_INFO(); 
    
        if (offline) 
        { 
         ici.dwConnectedState = INTERNET_STATE_DISCONNECTED; 
         ici.dwFlags = ISO_FORCE_DISCONNECTED; 
         Debug.WriteLine("switching to offline mode"); 
        } 
        else 
        { 
         ici.dwConnectedState = INTERNET_STATE_CONNECTED; 
         Debug.WriteLine("switching to online mode"); 
        } 
    
        InternetSetOption(0, INTERNET_OPTION_CONNECTED_STATE, ref ici, Marshal.SizeOf(ici)); 
    } 
    
  3. 设置注册表项 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WebCheck\LoadSensLoadLCEauto,然后 no然后 yes
  4. 我试图以编程方式强制联机模式

最后一次尝试几乎奏效。 '离线工作'永远不会被检查,但有时(确实是非常随机)邪恶的消息框出现。问题是,尽管它永远不会被阻塞(工作模式切换到在线,因此页面可以正常工作),但会干扰最终用户。

一句话:尽管看起来有点奇怪,但我们不能歪曲体系结构(本地Web应用程序)。

回答

1

由于其他人不能帮助我,我终于找到了解决方案。有点肮脏,但工作之一。 诀窍是模拟点击“再试一次”按钮。我通过使用user32.dll函数来完成此操作。以下是步骤:

  1. 您首先使用FindWindow函数找到父窗口的句柄。
  2. 从其标题和其父窗口的句柄中找到带有FindWindowEx的按钮。
  3. 你最后发送的点击与SendMessage

这里是必需的功能

// For Windows Mobile, replace user32.dll with coredll.dll 
[DllImport("user32.dll", SetLastError = true)] 
static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] 
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName); 
[DllImport("user32.dll", CharSet = CharSet.Auto)] 
public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); 
[DllImport("user32.dll", SetLastError = true)] 
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle); 

const uint WM_CLOSE = 0x10; 
const uint BM_CLICK = 0x00F5; 

声明下面是使用它们

private bool ClickButton(String window, String button) 
{ 
    IntPtr errorPopUp; 
    IntPtr buttonHandle; 

    bool found = false; 
    try 
    { 
     errorPopUp = FindWindow(null, window.Trim()); 
     found = errorPopUp.ToInt32() != 0; 
     if (found) 
     { 
      found = false; 
      buttonHandle = FindWindowEx(errorPopUp, IntPtr.Zero, null, button.Trim()); 
      found = buttonHandle.ToInt32() != 0; 
      if (found) 
      { 
       SendMessage(buttonHandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero); 
       Trace.WriteLine("Clicked \"" + button + "\" on window named \"" + window + "\""); 
      } 
      else 
      { 
       Debug.WriteLine("Found Window \"" + window + "\" but not its button \"" + button + "\""); 
      } 
     } 

    } 
    catch (Exception ex) 
    { 
     Trace.TraceError(ex.ToString()); 
    } 
    return found; 
} 

window为标题的方法( = “脱机工作”)的窗口和button该按钮的标题(= “&再试一次”)。

注意:不要忘记副标题字母前的符号(“&”)。