您现在的位置:首页 >> 软件开发 >> 内容

C# WINFORM获取活动窗体标题名的函数代码

时间:2023-12-12 23:13:44 点击:

  核心提示://窗口标题判断************** if (GetActiveWindowTitle() == '棕化线监控软件') MessageBox.Show('ok'); //窗口标题判断*****...

 

        //窗口标题判断**************

        if (GetActiveWindowTitle() == "棕化线监控软件") MessageBox.Show("ok");

        //窗口标题判断**************

 

         //*************下面是获取活动窗体标题名的函数代码*****

         [DllImport("user32.dll")]
         static extern IntPtr GetForegroundWindow();

         [DllImport("user32.dll")]
         static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);

         private string GetActiveWindowTitle()
         {
             const int nChars = 256;
             IntPtr handle = IntPtr.Zero;
             StringBuilder Buff = new StringBuilder(nChars);
             handle = GetForegroundWindow();

             if (GetWindowText(handle, Buff, nChars) > 0)
             {
                 return Buff.ToString();
             }
             return null;
         }
         //*************下面是获取活动窗体标题名的函数代码*****   

 

作者:站长 来源:网络
相关文章
  • 没有相关文章
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 陈工笔记(www.dui580.com) © 2024 版权所有 All Rights Reserved.
  • 站长:陈工 微信号:chengongbiji QQ:24498854
  • Powered by 陈工