1

How to get the list of the controls from the window, specified by "FindWindow" function? For example I have a handle to the Notepad window by

HWND Window = FindWindow(L"Notepad", L"dummy.txt - Notepad");

then I can make a handle to an "Edit" control by

HWND WindowEX = FindWindowEx(Window, NULL, L"EDIT", NULL);

but how can I get a full list of the controls and record them in the array for example?

user3754079
  • 21
  • 1
  • 5
  • 1
    What about using the [`EnumChildWindows()`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms633494(v=vs.85).aspx) function, and inspect the properties of the resulting child windows (e.g. using `GetWindowInfo()`)? – πάντα ῥεῖ Aug 15 '14 at 10:13
  • EnumChildWindows() function requires EnumChildProc callback function. I'm really new in programming, I don't know how to use it, especially in CLR. I've tried for a few hours now but with no luck. – user3754079 Aug 15 '14 at 10:22
  • 1
    Why are you using the native API with CLR at all? Why not using the Visual Studio MSVC extensions, to deal with managed code? – πάντα ῥεῖ Aug 15 '14 at 10:28
  • Can you point me out what exactly MSVC extensions I should use. I'm only a couple of weeks in programming. – user3754079 Aug 15 '14 at 10:35
  • http://www.codeproject.com/Articles/19354/Quick-C-CLI-Learn-C-CLI-in-less-than-minutes – πάντα ῥεῖ Aug 15 '14 at 10:44
  • Thanks. Seems like a useful article. – user3754079 Aug 15 '14 at 10:55
  • That site contains more stuff to get you started with [`System::Windows::Window`](http://msdn.microsoft.com/en-us/library/system.windows.window(v=vs.110).aspx) class etc. also. – πάντα ῥεῖ Aug 15 '14 at 10:58

1 Answers1

0

I've done it the old way

array<HWND>^ childs = gcnew array<HWND>(1000);
array<String^>^ childsnames = gcnew array<String^>(1000);
int childcount = 0;
public:
    delegate bool EnumDelegate(HWND hWnd, int lParam);
public:
    [DllImport("user32.dll", EntryPoint = "EnumChildWindows", ExactSpelling = false, CharSet = CharSet::Unicode, SetLastError = true)]
    static bool EnumChildWindows(HWND hwndParent, EnumDelegate ^lpEnumCallbackFunction, int lParam);

bool enumchildproc(HWND hWnd, int lParam)
    {
        int nLength = GetWindowTextLength(hWnd);
        LPWSTR strbTitle = (LPWSTR)VirtualAlloc((LPVOID)NULL,
            (DWORD)(nLength + 1), MEM_COMMIT,
            PAGE_READWRITE);
        //GetWindowText(hWnd, strbTitle, 255);
        GetClassNameW(hWnd, strbTitle, 255);
        String ^strTitle = gcnew String(strbTitle);
        childs[childcount] = hWnd;
        childsnames[childcount] = strTitle;
        childcount++;
        return true;
    }

void refreshChilds(HWND Parent, ComboBox^ cb)
    {
        cb->Items->Clear();
        childcount = 0;
        int i = 0;
        Array::Clear(childs, 0, 1000);
        Array::Clear(childsnames, 0, 1000);
        EnumDelegate ^filter = gcnew EnumDelegate(this, &MyForm::enumchildproc);
        EnumChildWindows(Parent, filter, 0);
        for (i = 0; i < childcount; i++)
        {
            cb->Items->Add(childsnames[i]);
        }
    }

refreshChilds() function will fill the combobox with childs classnames.

user3754079
  • 21
  • 1
  • 5