Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

clenum.c File Reference

#include "precomp.h"

Go to the source code of this file.

Defines

#define IEP_UNICODE   0x1
#define IEP_ENUMEX   0x2
#define MAX_ATOM_SIZE   512
#define ISSTRINGATOM(atom)   ((WORD)(atom) >= 0xc000)

Functions

DWORD BuildHwndList (HDESK hdesk, HWND hwndNext, BOOL fEnumChildren, DWORD idThread, HWND **pphwndFirst)
BOOL InternalEnumWindows (HDESK hdesk, HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam, DWORD idThread, BOOL fEnumChildren)
BOOL WINAPI EnumWindows (WNDENUMPROC lpfn, LPARAM lParam)
BOOL WINAPI EnumChildWindows (HWND hwnd, WNDENUMPROC lpfn, LPARAM lParam)
BOOL EnumThreadWindows (DWORD idThread, WNDENUMPROC lpfn, LPARAM lParam)
BOOL EnumDesktopWindows (HDESK hdesk, WNDENUMPROC lpfn, LPARAM lParam)
INT InternalEnumProps (HWND hwnd, PROPENUMPROC lpfn, LPARAM lParam, UINT flags)
INT WINAPI EnumPropsA (HWND hwnd, PROPENUMPROCA lpfn)
INT WINAPI EnumPropsW (HWND hwnd, PROPENUMPROCW lpfn)
BOOL WINAPI EnumPropsExA (HWND hwnd, PROPENUMPROCEXA lpfn, LPARAM lParam)
BOOL WINAPI EnumPropsExW (HWND hwnd, PROPENUMPROCEXW lpfn, LPARAM lParam)
BOOL InternalEnumObjects (HWINSTA hwinsta, NAMEENUMPROCW lpfn, LPARAM lParam, BOOL fAnsi)
BOOL WINAPI EnumWindowStationsA (WINSTAENUMPROCA lpEnumFunc, LPARAM lParam)
BOOL WINAPI EnumWindowStationsW (WINSTAENUMPROCW lpEnumFunc, LPARAM lParam)
BOOL WINAPI EnumDesktopsA (HWINSTA hwinsta, DESKTOPENUMPROCA lpEnumFunc, LPARAM lParam)
BOOL WINAPI EnumDesktopsW (HWINSTA hwinsta, DESKTOPENUMPROCW lpEnumFunc, LPARAM lParam)

Variables

HWND * phwndCache = NULL


Define Documentation

#define IEP_ENUMEX   0x2
 

Definition at line 16 of file clenum.c.

Referenced by EnumPropsExA(), EnumPropsExW(), and InternalEnumProps().

#define IEP_UNICODE   0x1
 

Definition at line 15 of file clenum.c.

Referenced by EnumPropsExW(), EnumPropsW(), and InternalEnumProps().

#define ISSTRINGATOM atom   )     ((WORD)(atom) >= 0xc000)
 

Definition at line 249 of file clenum.c.

Referenced by InternalEnumProps().

#define MAX_ATOM_SIZE   512
 

Definition at line 248 of file clenum.c.

Referenced by InternalEnumProps().


Function Documentation

DWORD BuildHwndList HDESK  hdesk,
HWND  hwndNext,
BOOL  fEnumChildren,
DWORD  idThread,
HWND **  pphwndFirst
 

Definition at line 37 of file clenum.c.

00043 { 00044 UINT cHwnd; 00045 HWND *phwndFirst; 00046 NTSTATUS Status; 00047 int cTries; 00048 00049 /* 00050 * Allocate a buffer to hold the names. 00051 */ 00052 cHwnd = 64; 00053 phwndFirst = (HWND *)InterlockedExchangePointer(&(PVOID)phwndCache, 0); 00054 if (phwndFirst == NULL) { 00055 phwndFirst = UserLocalAlloc(0, cHwnd * sizeof(HWND)); 00056 if (phwndFirst == NULL) 00057 return 0; 00058 } 00059 00060 Status = NtUserBuildHwndList(hdesk, hwndNext, fEnumChildren, 00061 idThread, cHwnd, phwndFirst, &cHwnd); 00062 00063 /* 00064 * If the buffer wasn't big enough, reallocate 00065 * the buffer and try again. 00066 */ 00067 cTries = 0; 00068 while (Status == STATUS_BUFFER_TOO_SMALL) { 00069 UserLocalFree(phwndFirst); 00070 00071 /* 00072 * If we can't seem to get it right, 00073 * call it quits 00074 */ 00075 if (cTries++ == 10) 00076 return 0; 00077 00078 phwndFirst = UserLocalAlloc(0, cHwnd * sizeof(HWND)); 00079 if (phwndFirst == NULL) 00080 return 0; 00081 00082 Status = NtUserBuildHwndList(hdesk, hwndNext, fEnumChildren, 00083 idThread, cHwnd, phwndFirst, &cHwnd); 00084 } 00085 00086 if (!NT_SUCCESS(Status) || cHwnd <= 1) { 00087 UserLocalFree(phwndFirst); 00088 return 0; 00089 } 00090 00091 *pphwndFirst = phwndFirst; 00092 return cHwnd - 1; 00093 }

BOOL WINAPI EnumChildWindows HWND  hwnd,
WNDENUMPROC  lpfn,
LPARAM  lParam
 

Definition at line 188 of file clenum.c.

References BOOL, InternalEnumWindows(), L, NULL, and TRUE.

Referenced by DdeAbandonTransaction(), DdeEnableCallback(), ProcessSyncDDEMessage(), and WinHelpA().

00192 { 00193 return InternalEnumWindows(NULL, hwnd, lpfn, lParam, 0L, TRUE); 00194 }

BOOL WINAPI EnumDesktopsA HWINSTA  hwinsta,
DESKTOPENUMPROCA  lpEnumFunc,
LPARAM  lParam
 

Definition at line 502 of file clenum.c.

References BOOL, InternalEnumObjects(), and TRUE.

00506 { 00507 return InternalEnumObjects(hwinsta, (NAMEENUMPROCW)lpEnumFunc, lParam, TRUE); 00508 }

BOOL WINAPI EnumDesktopsW HWINSTA  hwinsta,
DESKTOPENUMPROCW  lpEnumFunc,
LPARAM  lParam
 

Definition at line 510 of file clenum.c.

References BOOL, FALSE, and InternalEnumObjects().

00514 { 00515 return InternalEnumObjects(hwinsta, (NAMEENUMPROCW)lpEnumFunc, lParam, FALSE); 00516 }

BOOL EnumDesktopWindows HDESK  hdesk,
WNDENUMPROC  lpfn,
LPARAM  lParam
 

Definition at line 224 of file clenum.c.

References BOOL, FALSE, InternalEnumWindows(), and NULL.

00228 { 00229 return InternalEnumWindows(hdesk, NULL, lpfn, lParam, 0, FALSE); 00230 }

INT WINAPI EnumPropsA HWND  hwnd,
PROPENUMPROCA  lpfn
 

Definition at line 354 of file clenum.c.

References INT, and InternalEnumProps().

00357 { 00358 return InternalEnumProps(hwnd, (PROPENUMPROC)lpfn, 0, 0); 00359 }

BOOL WINAPI EnumPropsExA HWND  hwnd,
PROPENUMPROCEXA  lpfn,
LPARAM  lParam
 

Definition at line 380 of file clenum.c.

References BOOL, IEP_ENUMEX, and InternalEnumProps().

00384 { 00385 return InternalEnumProps(hwnd, (PROPENUMPROC)lpfn, lParam, IEP_ENUMEX); 00386 }

BOOL WINAPI EnumPropsExW HWND  hwnd,
PROPENUMPROCEXW  lpfn,
LPARAM  lParam
 

Definition at line 388 of file clenum.c.

References BOOL, IEP_ENUMEX, IEP_UNICODE, and InternalEnumProps().

00392 { 00393 return InternalEnumProps(hwnd, (PROPENUMPROC)lpfn, lParam, IEP_UNICODE|IEP_ENUMEX); 00394 }

INT WINAPI EnumPropsW HWND  hwnd,
PROPENUMPROCW  lpfn
 

Definition at line 362 of file clenum.c.

References IEP_UNICODE, INT, and InternalEnumProps().

00365 { 00366 return InternalEnumProps(hwnd, (PROPENUMPROC)lpfn, 0, IEP_UNICODE); 00367 }

BOOL EnumThreadWindows DWORD  idThread,
WNDENUMPROC  lpfn,
LPARAM  lParam
 

Definition at line 206 of file clenum.c.

References BOOL, FALSE, InternalEnumWindows(), and NULL.

Referenced by BoostHardError(), GetHardErrorText(), and ThreadShutdownNotify().

00210 { 00211 return InternalEnumWindows(NULL, NULL, lpfn, lParam, idThread, FALSE); 00212 }

BOOL WINAPI EnumWindows WNDENUMPROC  lpfn,
LPARAM  lParam
 

Definition at line 171 of file clenum.c.

References BOOL, FALSE, InternalEnumWindows(), L, and NULL.

Referenced by ConnectConv().

00174 { 00175 return InternalEnumWindows(NULL, NULL, lpfn, lParam, 0L, FALSE); 00176 }

BOOL WINAPI EnumWindowStationsA WINSTAENUMPROCA  lpEnumFunc,
LPARAM  lParam
 

Definition at line 487 of file clenum.c.

References BOOL, InternalEnumObjects(), NULL, and TRUE.

00490 { 00491 return InternalEnumObjects(NULL, (NAMEENUMPROCW)lpEnumFunc, lParam, TRUE); 00492 }

BOOL WINAPI EnumWindowStationsW WINSTAENUMPROCW  lpEnumFunc,
LPARAM  lParam
 

Definition at line 494 of file clenum.c.

References BOOL, FALSE, InternalEnumObjects(), and NULL.

00497 { 00498 return InternalEnumObjects(NULL, (NAMEENUMPROCW)lpEnumFunc, lParam, FALSE); 00499 }

BOOL InternalEnumObjects HWINSTA  hwinsta,
NAMEENUMPROCW  lpfn,
LPARAM  lParam,
BOOL  fAnsi
 

Definition at line 398 of file clenum.c.

References tagNAMELIST::awchNames, BOOL, CHAR, tagNAMELIST::cNames, DWORD, FALSE, MAX_PATH, NT_SUCCESS, NTSTATUS(), NtUserBuildNameList(), NULL, PNAMELIST, Status, TRUE, UINT, UserLocalAlloc, and UserLocalFree.

Referenced by EnumDesktopsA(), EnumDesktopsW(), EnumWindowStationsA(), and EnumWindowStationsW().

00403 { 00404 PNAMELIST pNameList; 00405 DWORD i; 00406 UINT cbData; 00407 PWCHAR pwch; 00408 PCHAR pch; 00409 CHAR achTmp[MAX_PATH]; 00410 BOOL iRetVal; 00411 NTSTATUS Status; 00412 int cTries; 00413 00414 /* 00415 * Allocate a buffer to hold the names. 00416 */ 00417 cbData = 256; 00418 pNameList = UserLocalAlloc(0, cbData); 00419 if (pNameList == NULL) 00420 return FALSE; 00421 00422 Status = NtUserBuildNameList(hwinsta, cbData, pNameList, &cbData); 00423 00424 /* 00425 * If the buffer wasn't big enough, reallocate 00426 * the buffer and try again. 00427 */ 00428 cTries = 0; 00429 while (Status == STATUS_BUFFER_TOO_SMALL) { 00430 UserLocalFree(pNameList); 00431 00432 /* 00433 * If we can't seem to get it right, 00434 * call it quits 00435 */ 00436 if (cTries++ == 10) 00437 break; 00438 00439 pNameList = UserLocalAlloc(0, cbData); 00440 if (pNameList == NULL) 00441 break; 00442 00443 Status = NtUserBuildNameList(hwinsta, cbData, pNameList, &cbData); 00444 } 00445 00446 if (!NT_SUCCESS(Status)) { 00447 UserLocalFree(pNameList); 00448 return FALSE; 00449 } 00450 00451 pwch = pNameList->awchNames; 00452 pch = achTmp; 00453 00454 for (i = 0; i < pNameList->cNames; i++) { 00455 if (fAnsi) { 00456 if (WCSToMB(pwch, -1, &pch, sizeof(achTmp), FALSE) == 00457 sizeof(achTmp)) { 00458 00459 /* 00460 * The buffer may have overflowed, so force it to be 00461 * allocated. 00462 */ 00463 if (WCSToMB(pwch, -1, &pch, -1, TRUE) == 0) { 00464 iRetVal = FALSE; 00465 break; 00466 } 00467 } 00468 iRetVal = (*(NAMEENUMPROCA)lpfn)(pch, lParam); 00469 if (pch != achTmp) { 00470 UserLocalFree(pch); 00471 pch = achTmp; 00472 } 00473 } else { 00474 iRetVal = (*(NAMEENUMPROCW)lpfn)(pwch, lParam); 00475 } 00476 if (!iRetVal) 00477 break; 00478 00479 pwch = pwch + wcslen(pwch) + 1; 00480 } 00481 00482 UserLocalFree(pNameList); 00483 00484 return iRetVal; 00485 }

INT InternalEnumProps HWND  hwnd,
PROPENUMPROC  lpfn,
LPARAM  lParam,
UINT  flags
 

Definition at line 251 of file clenum.c.

References _PROPSET::atom, DWORD, _PROPSET::hData, IEP_ENUMEX, IEP_UNICODE, INT, ISSTRINGATOM, MAX_ATOM_SIZE, NT_SUCCESS, NTSTATUS(), NtUserBuildPropList(), NULL, PPROPSET, PROPSET, Status, UserLocalAlloc, and UserLocalFree.

Referenced by EnumPropsA(), EnumPropsExA(), EnumPropsExW(), and EnumPropsW().

00256 { 00257 DWORD ii; 00258 DWORD cPropSets; 00259 PPROPSET pPropSet; 00260 WCHAR awch[MAX_ATOM_SIZE]; 00261 PVOID pKey; 00262 INT iRetVal; 00263 DWORD cchName; 00264 NTSTATUS Status; 00265 int cTries; 00266 00267 /* 00268 * Allocate a buffer to hold the names. 00269 */ 00270 cPropSets = 32; 00271 pPropSet = UserLocalAlloc(0, cPropSets * sizeof(PROPSET)); 00272 if (pPropSet == NULL) 00273 return -1; 00274 00275 Status = NtUserBuildPropList(hwnd, cPropSets, pPropSet, &cPropSets); 00276 00277 /* 00278 * If the buffer wasn't big enough, reallocate 00279 * the buffer and try again. 00280 */ 00281 cTries = 0; 00282 while (Status == STATUS_BUFFER_TOO_SMALL) { 00283 UserLocalFree(pPropSet); 00284 00285 /* 00286 * If we can't seem to get it right, 00287 * call it quits 00288 */ 00289 if (cTries++ == 10) 00290 return -1; 00291 00292 pPropSet = UserLocalAlloc(0, cPropSets * sizeof(PROPSET)); 00293 if (pPropSet == NULL) 00294 return -1; 00295 00296 Status = NtUserBuildPropList(hwnd, cPropSets, pPropSet, &cPropSets); 00297 } 00298 00299 if (!NT_SUCCESS(Status)) { 00300 UserLocalFree(pPropSet); 00301 return -1; 00302 } 00303 00304 for (ii=0; ii<cPropSets; ii++) { 00305 00306 if (ISSTRINGATOM(pPropSet[ii].atom)) { 00307 00308 pKey = (PVOID)awch; 00309 if (flags & IEP_UNICODE) 00310 cchName = GlobalGetAtomNameW(pPropSet[ii].atom, (LPWSTR)pKey, MAX_ATOM_SIZE); 00311 else 00312 cchName = GlobalGetAtomNameA(pPropSet[ii].atom, (LPSTR)pKey, sizeof(awch)); 00313 00314 /* 00315 * If cchName is zero, we must assume that the property belongs 00316 * to another process. Because we can't get the name, just skip 00317 * it. 00318 */ 00319 if (cchName == 0) 00320 continue; 00321 00322 } else { 00323 pKey = (PVOID)pPropSet[ii].atom; 00324 } 00325 00326 if (flags & IEP_ENUMEX) { 00327 iRetVal = (*(PROPENUMPROCEX)lpfn)(hwnd, pKey, 00328 pPropSet[ii].hData, lParam); 00329 } else { 00330 iRetVal = (*lpfn)(hwnd, pKey, pPropSet[ii].hData); 00331 } 00332 00333 if (!iRetVal) 00334 break; 00335 } 00336 00337 UserLocalFree(pPropSet); 00338 00339 return iRetVal; 00340 }

BOOL InternalEnumWindows HDESK  hdesk,
HWND  hwnd,
WNDENUMPROC  lpfn,
LPARAM  lParam,
DWORD  idThread,
BOOL  fEnumChildren
 

Definition at line 95 of file clenum.c.

References BOOL, BuildHwndList(), FALSE, NULL, phwndCache, TRUE, UINT, UserLocalFree, and ValidateHwnd.

Referenced by EnumChildWindows(), EnumDesktopWindows(), EnumThreadWindows(), and EnumWindows().

00102 { 00103 UINT i; 00104 UINT cHwnd; 00105 HWND *phwndT; 00106 HWND *phwndFirst; 00107 BOOL fSuccess = TRUE; 00108 00109 /* 00110 * Get the hwnd list. It is returned in a block of memory 00111 * allocated with LocalAlloc. 00112 */ 00113 if ((cHwnd = BuildHwndList(hdesk, hwnd, fEnumChildren, idThread, 00114 &phwndFirst)) == -1) { 00115 return FALSE; 00116 } 00117 00118 /* 00119 * In Win 3.1 it was not an error if there were no windows in the thread 00120 */ 00121 if (cHwnd == 0) { 00122 if (idThread == 0) 00123 return FALSE; 00124 else 00125 return TRUE; 00126 } 00127 00128 00129 /* 00130 * Loop through the windows, call the function pointer back for each 00131 * one. End loop if either FALSE is return ed or the end-of-list is 00132 * reached. 00133 */ 00134 phwndT = phwndFirst; 00135 for (i = 0; i < cHwnd; i++) { 00136 00137 /* 00138 * call ValidateHwnd instead of RevalidateHwnd so that 00139 * restricted processes don't see handles they are not 00140 * suppose to see. 00141 */ 00142 if (ValidateHwnd(*phwndT)) { 00143 if (!(fSuccess = (*lpfn)(*phwndT, lParam))) 00144 break; 00145 } 00146 phwndT++; 00147 } 00148 00149 /* 00150 * Free up buffer and return status - TRUE if entire list was enumerated, 00151 * FALSE otherwise. 00152 */ 00153 phwndT = (HWND *)InterlockedExchangePointer(&(PVOID)phwndCache, phwndFirst); 00154 if (phwndT != NULL) { 00155 UserLocalFree(phwndT); 00156 } 00157 return fSuccess; 00158 }


Variable Documentation

HWND* phwndCache = NULL
 

Definition at line 18 of file clenum.c.

Referenced by BuildHwndList(), and InternalEnumWindows().


Generated on Sat May 15 19:43:04 2004 for test by doxygen 1.3.7