汤姆熊猫

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

[C#]取得当前活动窗体的Title

 1 [DllImport("user32.dll")]
2 static extern IntPtr GetForegroundWindow();
3
4 [DllImport("user32.dll")]
5 static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
6
7 private string GetActiveWindowTitle()
8 {
9 const int nChars = 256;
10 IntPtr handle = IntPtr.Zero;
11 StringBuilder Buff = new StringBuilder(nChars);
12 handle = GetForegroundWindow();
13
14 if (GetWindowText(handle, Buff, nChars) > 0)
15 {
16 return Buff.ToString();
17 }
18 return null;
19 }
posted on 2012-03-01 13:33  汤姆熊猫  阅读(575)  评论(0)    收藏  举报