3 回答

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
。

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 已經執行了此遞歸。它在父窗口的子窗口和孫子窗口等上運行,開箱即用,無需您指定此行為或實現它。
- 3 回答
- 0 關注
- 185 瀏覽
添加回答
舉報