读书人

C#怎么获取任务管理器中应用程序列表名

发布时间: 2012-04-26 14:01:31 作者: rapoo

C#如何获取任务管理器中应用程序列表名称
如题~

注意是应用程序标题名称,非进程名

求代码~

[解决办法]

C# code
DllImport("User32")] private extern static int GetWindow(int hWnd, int wCmd); [DllImport("User32")] private extern static int GetWindowLongA(int hWnd, int wIndx); [DllImport("user32", CharSet = CharSet.Auto)] private extern static int GetWindowTextLength(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool GetWindowText(int hWnd, StringBuilder title, int maxBufSize); private const int GW_HWNDFIRST = 0; private const int GW_HWNDNEXT = 2; private const int GWL_STYLE = (-16); private const int WS_VISIBLE = 268435456; private const int WS_BORDER = 8388608; public List <string> GetRunApplicationList(Form appForm) {     try     {         List <string> appString = new List <string>();         int handle = (int)appForm.Handle;         int hwCurr;         hwCurr = GetWindow(handle, GW_HWNDFIRST);         while (hwCurr > 0)         {             int isTask = (WS_VISIBLE | WS_BORDER);             int lngStyle = GetWindowLongA(hwCurr, GWL_STYLE);             bool taskWindow = ((lngStyle & isTask) == isTask);             if (taskWindow)             {                 int length = GetWindowTextLength(new IntPtr(hwCurr));                 StringBuilder sb = new StringBuilder(2 * length + 1);                 GetWindowText(hwCurr, sb, sb.Capacity);                 string strTitle = sb.ToString();                 if (!string.IsNullOrEmpty(strTitle))                 {                     appString.Add(strTitle);                 }             }             hwCurr = GetWindow(hwCurr, GW_HWNDNEXT);         }         return appString;     }     catch (Exception ex)     {         throw new ApplicationInfoException("读取应用程序信息时出错:" + ex.Message);     } }
[解决办法]
进程.MainWindowTitle不是应用程序名吗
我做过一个简单的任务管理器,能得到应用程序名的

读书人网 >C#

热点推荐