亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

按類查找子窗口

按類查找子窗口

C#
蕭十郎 2023-09-16 15:55:20
在第三方應用程序中選擇照片時,我無法獲取“編輯”字段句柄。Spy++ 顯示一切正確,但FindWindow失敗。我可以獲得父窗口本身的句柄。我想我需要尋找子窗口。我可以得到一些句柄GetWindow,但不清楚它們是什么。窗口標題為空。FindWindowEx根本不起作用,返回0。我這樣指示:IntPtr hwndchild = (hwnd, IntPtr.Zero, null, "Edit")
查看完整描述

3 回答

?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

根據您提供的屏幕截圖,僅使用FindWindow/Ex()函數,您可以獲得編輯控件的 HWND,如下所示:

IntPtr?hwndDlg?=?FindWindow(null,?"Choose?an?image");
IntPtr?hwndCBEx?=?FindWindowEx(hwndDlg,?IntPtr.Zero,?"ComboBoxEx32",?null);
IntPtr?hwndCB?=?FindWindowEx(hwndCBEx,?IntPtr.Zero,?"ComboBox",?null);
IntPtr?hwndEdit?=?FindWindowEx(hwndCB,?IntPtr.Zero,?"Edit",?null);

但是,一旦獲得了 ComboBoxEx 控件的 HWND,獲取其 Edit 控件的 HWND 的正確CBEM_GETEDITCONTROL方法是使用以下消息:

const?int?CBEM_GETEDITCONTROL?=?1031;
IntPtr?hwndDlg?=?FindWindow(null,?"Choose?an?image");
IntPtr?hwndCBEx?=?FindWindowEx(hwndDlg,?IntPtr.Zero,?"ComboBoxEx32",?null);
IntPtr?hwndEdit?=?SendMessage(hwndCBEx,?CBEM_GETEDITCONTROL,?0,?0);

請注意,對于標準 ComboBox 控件(可以使用CBEM_GETCOMBOCONTROL消息從 ComboBoxEx 控件獲?。?,可以使用CB_GETCOMBOBOXINFO消息或GetComboBoxInfo()函數。該字段中返回編輯控件的 HWND?COMBOBOXINFO.hwndItem。



查看完整回答
反對 回復 2023-09-16
?
BIG陽

TA貢獻1859條經驗 獲得超6個贊

如果您正在尋找父窗口的子窗口,您應該使用 EnumChildWindows。以下是 C++ 代碼,但可以輕松調用:您可以將委托編組為回調的函數指針。


std::vector<HWND> FindChildrenByClass(HWND parent, const std::string& target_class)

{

    struct EnumWndParam {

        std::vector<HWND> output;

        std::string target;

    } enum_param;


    enum_param.target = target_class;


    EnumChildWindows(

        parent,

        [](HWND wnd, LPARAM lparam) -> BOOL {

            auto param = reinterpret_cast<EnumWndParam*>(lparam);

            char class_name[512];

            GetClassName(wnd, class_name, 512);

            if (param->target == class_name)

                param->output.push_back(wnd);

            return TRUE;

        },

        reinterpret_cast<LPARAM>(&enum_param)

    );


    return enum_param.output;

}


int main()

{

    auto windows = FindChildrenByClass( reinterpret_cast<HWND>(0x0061024A), "Edit");

    for (auto wnd : windows) {

        std::cout << std::hex << wnd << std::endl;

    }

}

請注意,上面我沒有在回調 lambda 中遞歸調用 FindChildrenByClass。這不是一個錯誤。EnumChildWindows 已經執行了此遞歸。它在父窗口的子窗口和孫子窗口等上運行,開箱即用,無需您指定此行為或實現它。


查看完整回答
反對 回復 2023-09-16
?
寶慕林4294392

TA貢獻2021條經驗 獲得超8個贊

就像有人已經假設的那樣。嘗試 EnumChildWindow 方法。


查看完整回答
反對 回復 2023-09-16
  • 3 回答
  • 0 關注
  • 185 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號