MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / WinGetList

Function WinGetList

source/script2.cpp:2813–2850  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2811
2812
2813void WinGetList(ResultToken &aResultToken, BuiltInFunctionID aCmd, LPTSTR aTitle, LPTSTR aText, LPTSTR aExcludeTitle, LPTSTR aExcludeText)
2814// Helper function for WinGet() to avoid having a WindowSearch object on its stack (since that object
2815// normally isn't needed).
2816{
2817 WindowSearch ws;
2818 ws.mFindLastMatch = true; // Must set mFindLastMatch to get all matches rather than just the first.
2819 if (aCmd == FID_WinGetList)
2820 if ( !(ws.mArray = Array::Create()) )
2821 _f_throw_oom;
2822 // Check if we were asked to "list" or count the active window:
2823 if (USE_FOREGROUND_WINDOW(aTitle, aText, aExcludeTitle, aExcludeText))
2824 {
2825 HWND target_window; // Set by the macro below.
2826 SET_TARGET_TO_ALLOWABLE_FOREGROUND(g->DetectHiddenWindows)
2827 if (aCmd == FID_WinGetCount)
2828 {
2829 _f_return_i(target_window != NULL); // i.e. 1 if a window was found.
2830 }
2831 // Otherwise, it's FID_WinGetList:
2832 if (target_window)
2833 // Since the target window has been determined, we know that it is the only window
2834 // to be put into the array:
2835 ws.mArray->Append((__int64)(size_t)target_window);
2836 // Otherwise, return an empty array.
2837 _f_return(ws.mArray);
2838 }
2839 // Enumerate all windows which match the criteria:
2840 // If aTitle is ahk_id nnnn, the Enum() below will be inefficient. However, ahk_id is almost unheard of
2841 // in this context because it makes little sense, so no extra code is added to make that case efficient.
2842 if (ws.SetCriteria(*g, aTitle, aText, aExcludeTitle, aExcludeText)) // These criteria allow the possibility of a match.
2843 EnumWindows(EnumParentFind, (LPARAM)&ws);
2844 //else leave ws.mFoundCount set to zero (by the constructor).
2845 if (aCmd == FID_WinGetList)
2846 // Return the array even if it is empty:
2847 _f_return(ws.mArray);
2848 else // FID_WinGetCount
2849 _f_return_i(ws.mFoundCount);
2850}
2851
2852void WinGetControlList(ResultToken &aResultToken, HWND aTargetWindow, bool aFetchHWNDs); // Forward declaration.
2853

Callers 1

BIF_DECLFunction · 0.85

Calls 2

SetCriteriaMethod · 0.80
AppendMethod · 0.45

Tested by

no test coverage detected