- 作者:xiaoxiao
- 发表时间:2020-12-23 10:55
- 来源:未知
来自:唐细刚的专栏
http://blog.csdn.net/tanaya/archive/2004/08/11/71041.aspx
Windows任务管理器的应用程序栏包含任务窗口的列表。要获取此列表,窗口必须满足以下几个条件:
(1) 必须可见(2) 包含一个标题(3) 不能被其他窗口包含
下面我给出源程序和调用示例:
VC++源代码(使用VC6):
//获取任务列表且添加到列表框中.BOOL GetAppList(CListBox &LstBox){ CString strCaption; LstBox.ResetContent(); ASSERT_VALID(AfxGetMainWnd()); CWnd *pWnd=AfxGetMainWnd()->GetWindow(GW_HWNDFIRST); if(pWnd==NULL) return FALSE; while(pWnd) { if(pWnd->IsWindowVisible() && pWnd->GetWindowTextLength() && !pWnd->GetOwner()) { pWnd->GetWindowText(strCaption); LstBox.AddString(strCaption); } pWnd=pWnd->GetWindow(GW_HWNDNEXT); } return TRUE;}
//调用示例:void CGetAppListDlg::OnGetAppList() { GetAppList(m_ListBox1);}
VB源代码(使用VB6,具体调用很简单,我就不写了)
Option ExplicitPrivate Declare Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As LongPrivate Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function GetDesktopWindow Lib "user32" () As Long
Private Const GW_OWNER = 4Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_TOOLWINDOW = &H80Private Const WS_EX_APPWINDOW = &H40000
//判断窗口是否为任务应用函数,参数为窗口句柄Public Function IsTaskbarApp(ByVal hwnd As Long) As Boolean Dim ExtendStyle As Long Dim hParent As Long Dim BoolIsTaskBarApp As Boolean ExtendStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE) hParent = GetParent(hwnd) BoolIsTaskBarApp = CBool((IsWindowVisible(hwnd) <> 0) And _ (GetWindow(hwnd, GW_OWNER) = 0) And _ (hParent = 0 Or hParent = GetDesktopWindow())) If (ExtendStyle And WS_EX_TOOLWINDOW) Then BoolIsTaskBarApp = False If (ExtendStyle And WS_EX_APPWINDOW) Then BoolIsTaskBarApp = True IsTaskbarApp = BoolIsTaskBarAppEnd Function