#region User32.dll定義
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public static extern Int32 FindWindow( string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
public static extern Int32 FindWindowEx( Int32 hwndParent, Int32 hwndChildAfter, string lpszClass, string lpszWindow);
// 同期送信
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern Int32 SendMessage( Int32 hWnd, Int32 Msg, Int32 wParam, ref Int32 lParam);
// 非同期送信
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", EntryPoint = "PostMessage", SetLastError = true)]
public static extern bool PostMessage( Int32 hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);
#region メッセージ一覧
public static class WINDOW_MESSAGE
{
public const Int32 WM_KEYDOWN = 0x0100;
}
#endregion
#region キー一覧
public static class KEY_CODE
{
public const Int32 VK_F5 = 0x74;
}
#endregion
#endregion
///
/// 指定されたウィンドウ名のInternetExploreに画面更新キー(F5)を送ります。
///
///
public static bool F5RefreshIE(string windowName)
{
int hwnd;
int hwndTmp = FindWindowEx(0, 0, "IEFrame", windowName);
if (hwndTmp == 0)
return false;
else
hwnd = hwndTmp;
hwndTmp = FindWindowEx(hwnd, 0, "Frame Tab", null);
if (hwndTmp != 0) hwnd = hwndTmp;
hwndTmp = FindWindowEx(hwnd, 0, "TabWindowClass", null);
if (hwndTmp != 0) hwnd = hwndTmp;
hwndTmp = FindWindowEx(hwnd, 0, "Shell DocObject View", null);
if (hwndTmp != 0) hwnd = hwndTmp;
hwndTmp = FindWindowEx(hwnd, 0, "Internet Explorer_Server", null);
if (hwndTmp != 0) hwnd = hwndTmp;
//Int32 param = 0; // パラメータなし
//SendMessage(hwnd, MessageList.WM_KEYDOWN, KEY_LIST.VK_F5, ref param);
//param = 0;
//SendMessage(hwnd, MessageList.WM_KEYUP, KEY_LIST.VK_F5, ref param);
PostMessage(hwnd, WINDOW_MESSAGE.WM_KEYDOWN, KEY_CODE.VK_F5, 0);
return true;
}
///
/// 任意のInternetExploreに画面更新キー(F5)を送ります。
///
public static bool F5RefreshIE()
{
return F5RefreshIE(null);
}
///
/// 指定されたウィンドウに画面更新キー(F5)を送ります。
///
public static bool F5RefreshIE(Int32 hwnd)
{
if (hwnd == 0) return false;
PostMessage(hwnd, WINDOW_MESSAGE.WM_KEYDOWN, KEY_CODE.VK_F5, 0);
return true;
}