How to get a list of Windows applications

xiaoxiao2021-03-06  163

The application column of the Windows Task Manager contains a list of task windows. To get this list, the window must meet the following conditions:

(1) It must be visible (2) containing a title (3) cannot be included by other windows

Below I give the exemplary program and call example:

VC source code (using VC6):

// Get a list of task and add it to the list box. 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;}

// Call example: void cgetapplistdlg :: ONGETAPPLIST () {getApplist (m_listbox1);

VB source code (using VB6, the specific call is very simple, I don't write)

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" () () As long

Private const gw_owner = 4Private const GWL_EXSTYLE = (-20)

Private const ws_ex_toolwindow = & h80private const ws_ex_appwindow = & h40000

// determines whether a task application window function, the window handle parameter 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 '----------------------------------- -------- 'please indicate the source' author: Don just fine 'E-mail: tanaya@163.com' ----------------------- --------------------

转载请注明原文地址:https://www.9cbs.com/read-128443.html

New Post(0)