3 回答

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊
根據(jù)您提供的屏幕截圖,僅使用FindWindow/Ex()
函數(shù),您可以獲得編輯控件的 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);
請(qǐng)注意,對(duì)于標(biāo)準(zhǔn) ComboBox 控件(可以使用CBEM_GETCOMBOCONTROL
消息從 ComboBoxEx 控件獲?。?,可以使用CB_GETCOMBOBOXINFO
消息或GetComboBoxInfo()
函數(shù)。該字段中返回編輯控件的 HWND?COMBOBOXINFO.hwndItem
。

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果您正在尋找父窗口的子窗口,您應(yīng)該使用 EnumChildWindows。以下是 C++ 代碼,但可以輕松調(diào)用:您可以將委托編組為回調(diào)的函數(shù)指針。
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;
}
}
請(qǐng)注意,上面我沒(méi)有在回調(diào) lambda 中遞歸調(diào)用 FindChildrenByClass。這不是一個(gè)錯(cuò)誤。EnumChildWindows 已經(jīng)執(zhí)行了此遞歸。它在父窗口的子窗口和孫子窗口等上運(yùn)行,開(kāi)箱即用,無(wú)需您指定此行為或?qū)崿F(xiàn)它。
- 3 回答
- 0 關(guān)注
- 180 瀏覽
添加回答
舉報(bào)