Enumerate all windows in the system in CTreeCtrl! (Ii)

zhaozj2021-02-08  290

Sender: Cvisual (Beibei), Letter Area: Visualc

Title: Enumerate all the windows in the system in CTREECTRL! (Ii)

Sending station: BBS Shuimu Tsinghua Station (Tue May 19 14:37:24 1998)

This is the implementation of the file

// WinList.cpp: Implementation File

//

#include "stdafx.h"

#include "mfc.h"

#include "WinList.h"

#include "mfcapi.h"

#ifdef _Debug

#define new debug_new

#undef this_file

Static char this_file [] = __file__;

#ENDIF

/

// CWINLIST DIALOG

CWINList :: CWINLIST (CWND * PParent / * = null * /)

: Cdialog (cwinlist :: IDd, pparent)

{

// {{AFX_DATA_INIT (CWINLIST)

// Note: The classwizard will add member initialization here

//}} AFX_DATA_INIT

}

Void Cwinlist :: DODATAEXCHANGE (CDataExchange * PDX)

{

CDIALOG :: DODATAEXCHANGE (PDX);

// {{AFX_DATA_MAP (CWINLIST)

DDX_Control (pdx, idtree, m_tree);

//}} AFX_DATA_MAP

}

Begin_Message_Map (CWINLIST, CDIALOG)

// {{AFX_MSG_MAP (CWINLIST)

ON_BN_CLICKED (iDRefresh, OnRefresh)

ON_NOTIFY (TVn_Selchanged, IDtree, OnselchangeDtree)

//}} AFX_MSG_MAP

END_MESSAGE_MAP ()

/

// CWINLIST MESSAGE HANDLERS

Static CDWordArray WinArray;

Static unsigned long level;

Static int ignore [10];

STATIC HWND HPREVWND;

Bool Callback CWINList :: EnumChildProc (HWND HWND, LPARAM LPARAM)

{

Ignore [Level] ;

IG (Ignore [Level 1]) IGNORE [Level 1] -;

Else

{WinArray.Add ((unsigned long) ((unsigned long) hWnd);

Level ; Ignore [Level 1] = 0;

EnumChildWindows (HWND, ENUMCHILDPROC, (long) 0);

Level -;

}

Return True;

}

Bool Callback CWINList :: EnumWindowsProc (HWND HWND, LPARAM LPARAM)

{

WinArray.Add (UNSIGNED Long) HWND);

Level = 1; Ignore [Level 1] = 0;

EnumChildWindows (HWND, ENUMCHILDPROC, (long) 0);

Return True;

}

Void CWINList :: BuiltTree (HWND HWND)

{Char Temp [90];

CHAR TEXT [50];

Char Name [20]; TreeItem.hparent = rootArray [rootpt];

:: getWindowText (HWND, Text, 50);

:: getClassName (HWND, NAME, 20);

Sprintf (TEMP, "[% 04x]: {% s}:% s", hwnd, name, text);

TreeItem.Item.psztext = TEMP;

TreeItem.Item.lparam = (unsigned long) hwnd;

HtreeItem Tempitem = m_tree.insertitem (& TreeItem);

RootArray [rootpt 1] = Tempitem;

}

Void Cwinlist :: DrawFlash (HWND HWND)

{

HDC HDC;

Rect RC;

HPEN HPEN

:: getWindowRect (hwnd, & rc);

HDC = :: getwindowdc (hwnd);

:: Setrop2 (HDC, R2_NOT);

HPEN = :: Createpen (PS_INSIDEFRAME, 5 * GetSystemMetrics, RGB (255, 0, 0));

:: SELECTOBJECT (HDC, HPEN);

:: SelectObject (HDC, getStockObject (null_brush));

:: Rectangle (HDC, 0, 0, Rc.right-rc.left, rc.bottom-rc.top);

:: ReleaseDC (HWND, HDC);

:: DeleteObject (HPEN);

}

Void cwinlist :: Refresh ()

{RootArray [0] = TVi_root;

Rootpt = 0;

TreeItem.hinsertafter = TVi_last;

TreeItem.Item.mask = TVIF_Text | TVIF_PARAM;

WinArray.removeall ();

M_Tree.SetFont (& Treefont);

m_tree.deleteallItems ();

Level = 0;

For (int J = 0; j <10; j ) ignore [j] = 0;

ENUMWINDOWS (ENUMWINDOWSPROC, (Long) 0);

For (int i = 0; i

{Rootpt = (int) ((WinArray [i] & 0xffff00) >> 16);

Builttree ((hwnd) (WinArray [I] & 0x0000FFFF);

}

}

BOOL CWINList :: OnInitdialog ()

{

CDIALOG :: OnInitdialog ();

// Todo: Add Extra Initialization Here

m_hselected = null;

HPREVWND = NULL;

Refresh ();

Return True; // Return True UnsS you set the focus to a control

// Exception: OCX Property Pages SHOULD RETURN FALSE

}

Void cwinlist :: onRefresh ()

{

// Todo: Add Your Control Notification Handler Code Here

Refresh ();

}

Void Cwinlist :: OnSelchangeDtree (NmHDR * PNMHDR, LRESULT * PRESULT) {

NM_TreeView * pnmtreeview = (nm_treeview *) PNMHDR;

// Todo: Add Your Control Notification Handler Code Here

HWND HWND = (hwnd) PNMTreeView-> itemnew.lparam;

M_HSelected = hwnd;

IF (HPREVWND) DrawFlash (HPREVWND);

Hprevwnd = hwnd;

Drawflash (hwnd);

* PRESULT = 0;

}

Bool cwinlist :: destroywindow ()

{

// Todo: Add Your Specialized Code Here and / or Call The Base Class

IF (HPREVWND) DrawFlash (HPREVWND);

Return CDialog :: destroyWindow ();

}

/

// DLL EXPORT Interface

EXTERN "C"

HWND FAR PASCAL EXPORT SEARCHWINDOW ()

{

CWINLIST WINLIST;

IF (WinList.Domodal () == iDok)

Return WinList.m_Hselected;

Else

Return (HWND) NULL;

}

-

┌ ---- ┐

│Babe │

└ ---- ┘

※ Source: · BBS Shuimu Tsinghua Station bbs.net.tsinghua.edu.cn · [from: bbs.nju.edu.cn]

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

New Post(0)