C# 如何摆脱;“离线模式”;IE 8中的消息?
我想彻底摆脱“脱机工作”消息框 为了提供一些上下文信息,此消息框出现在运行本地webapp的计算机上。 对网络的访问显然是不稳定的,因此暂时的缺乏不应该被阻止:它只会延迟一些后台通知。网页只需要显示本地资源。URL看起来像C# 如何摆脱;“离线模式”;IE 8中的消息?,c#,internet-explorer,winapi,internet-explorer-8,C#,Internet Explorer,Winapi,Internet Explorer 8,我想彻底摆脱“脱机工作”消息框 为了提供一些上下文信息,此消息框出现在运行本地webapp的计算机上。 对网络的访问显然是不稳定的,因此暂时的缺乏不应该被阻止:它只会延迟一些后台通知。网页只需要显示本地资源。URL看起来像http://localhost:4444/*myApp*/… 这台机器在XP pro上运行,浏览器是IE8 我尝试了以下解决方案,但没有成功: 手动取消选中“文件/脱机工作”菜单选项是不够的 将注册表项HKEY\U LOCAL\U MACHINE\Software\Micr
http://localhost:4444/*myApp*/…
这台机器在XP pro上运行,浏览器是IE8
我尝试了以下解决方案,但没有成功:
HKEY\U LOCAL\U MACHINE\Software\Microsoft\Windows\CurrentVersion\WebCheck\LoadSens
和LoadLCE
设置为auto
,然后no
再yes
[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));
}
一句话:我们不能改变架构(本地web应用程序),即使它看起来有点奇怪。因为其他人帮不了我,我终于找到了解决方案。有点脏,但很管用。 诀窍是模拟点击“重试”按钮。我是通过使用
user32.dll
函数实现的。以下是步骤:
FindWindow
函数找到父窗口的句柄李>
FindWindowEx
的按钮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
是窗口的标题(=“脱机工作”)和按钮的标题(“&重试”)
注意:别忘了前面带副标题的字母和(&)。因为其他人帮不了我,我终于找到了解决办法。有点脏,但很管用。 诀窍是模拟点击“重试”按钮。我是通过使用
user32.dll
函数实现的。以下是步骤:
FindWindow
函数找到父窗口的句柄李>
FindWindowEx
的按钮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
是窗口的标题(=“脱机工作”)和按钮的标题(“&重试”)
注意:不要忘记副标题字母前面的符号和(&)