SHdovw与internetexplor
来源:互联网 发布:java注释实例 编辑:程序博客网 时间:2024/05/18 07:52
1. 問題描述
如何取得正在使用的 Interner Explorer 網址
2. 方法
(1) 取得 Internet Explorer 網址
先加入參考 Microsoft HTML Object Library 與 Microsoft Internet Controls
接著請參考以下程式碼與註解
01
this
.lbURL.Items.Clear();
02
// 取得目前 Shell 的所有視窗
03
SHDocVw.ShellWindows shellWindows =
new
SHDocVw.ShellWindowsClass();
04
foreach
(SHDocVw.InternetExplorer ie
in
shellWindows)
05
{
06
// 判斷視窗是否為 iexplore
07
if
(Path.GetFileNameWithoutExtension(ie.FullName).ToLower().Equals(
"iexplore"
))
08
{
09
this
.lbURL.Items.Add(ie.LocationURL);
10
}
11
}
(2) 透過 Windows API GetForegroundWindow 取得正在使用視窗[前景]的控制代碼
將宣告 GetForegroundWindow 部分加入,並且在取得 Internet Explorer 視窗時,判斷是否為正在使用前景視窗
01
//
02
// Windows API : GetForegroundWindow
03
// 取得正在使用視窗[前景]的控制代碼
04
//
05
[DllImport(
"user32.dll"
)]
06
private
static
extern
IntPtr GetForegroundWindow();
07
private
void
timer1_Tick(
object
sender, EventArgs e)
08
{
09
this
.lbURL.Items.Clear();
10
// 取得目前 Shell 的所有視窗
11
SHDocVw.ShellWindows shellWindows =
new
SHDocVw.ShellWindowsClass();
12
foreach
(SHDocVw.InternetExplorer ie
in
shellWindows)
13
{
14
// 判斷視窗是否為 iexplore
15
if
(Path.GetFileNameWithoutExtension(ie.FullName).ToLower().Equals(
"iexplore"
))
16
{
17
// 判斷此 Internet Explorer 是否為正在使用視窗[前景]
18
if
(ie.HWND == GetForegroundWindow().ToInt32())
19
{
20
this
.txtURL.Text = ie.LocationURL;
21
}
22
this
.lbURL.Items.Add(ie.LocationURL);
23
}
24
}
25
}
出处:http://www.dotblogs.com.tw/chou/archive/2010/01/11/12953.aspx
- SHdovw与internetexplor
- 与
- 与
- “” 与 “”
- ##与#
- >> 与 > >
- :与::
- &与&&
- && 与 &
- [[与((
- >>与>>>
- *与++
- *与++
- ++与++
- ->与 .
- :与::
- & | 与&& ||
- &&与&
- SharePoint 2010 之SPGridView编辑和下拉框
- 数据结构_树_赫夫曼树及赫夫曼编码_C++实现
- 怀旧:Turbo C 英文原版 +免安装版 下载
- Zebra 888-TT通过EPL命令校准纸张及条码测试
- 实时计算的一些总结
- SHdovw与internetexplor
- Linux Unix C 中的curses库——curses.h
- TASK_KILLABLE:Linux 中的新进程状态
- 作为程序员的心态
- jquery autoComplete 使用技巧
- POJ 1185 炮兵阵地 状态压缩(DP)
- 心理学,教你怎么去看懂人心
- 数论之求欧拉函数
- 指正《精通正则表达式第3版》关于匹配连续行的错误