0

「FindWindow」関数で指定されたウィンドウからコントロールのリストを取得する方法は? たとえば、メモ帳ウィンドウへのハンドルがあります

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

次に、「編集」コントロールへのハンドルを作成できます

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

しかし、たとえば、コントロールの完全なリストを取得して配列に記録するにはどうすればよいですか?

4

1 に答える 1

0

昔のやり方でやりました

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() 関数は、コンボボックスに子クラス名を入力します。

于 2014-08-15T19:37:37.243 に答える