2013-05-07 13 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該按鈕的標題(= 「&再試一次」)。

注意:不要忘記副標題字母前的符號(「&」)。