问题描述
- 怎么sendmessage选中Combobox的某一项
-
用mfc 调用window api的 sendmessage函数,
选中Combobox的任意一项不知道怎么写啊,请大侠帮忙!
解决方案
SendMessage(hwndComboBox, CB_GETCURSEL, 0, 0);
获取组合框的索引
解决方案二:
如果你是跨线程或者进程做的话,直接sendmessage给commbox不好做,
你可以自定义一个WM_USER+1的消息,然后在你的combox的parentwindow上去接收这个消息,然后让调用combox的select方法去选中某项
解决方案三:
SendMessage(hwndComboBox, CB_SETCURSEL, 0, 0);
设置组合框的默认项
解决方案四:
int index;
SendMessage(hComBox, CB_INSERTSTRING, 0, (LPARAM)_T("请选择"));
SendMessage(hComBox, CB_INSERTSTRING, 0, (LPARAM)_T("1 - AAA"));
index = (int)SendMessage(hComBox, CB_INSERTSTRING, 0, (LPARAM)_T("2 - BBB"));
SendMessage(hComBox, CB_SETCURSEL, index, 0);
SendMessage(hComBox, CB_INSERTSTRING, 0, (LPARAM)_T("3 - CCC"));
这样将 2 - BBB 选中。
解决方案五:
你试试这段代码可以不,当然你首先要先用spy++看看你要看到的window的title,也就是caption是多少。而且这段代码只支持有一个combox的,如果有多个,你需要enumwindow多个了。
HWND hMainWnd = FindWindowEx(NULL, NULL, NULL, L"Test MFC Window");
if (hMainWnd)
{
HWND hComboxWnd = FindWindowEx(hMainWnd, NULL, L"ComboBox", NULL);
if (hComboxWnd)
{
SendMessage(hComboxWnd, CB_SETCURSEL, 2, 0);
}
printf("Finde Main WND");
}
解决方案六:
SendMessage(hwnd, CB_SETCURSEL, 30, 0);
//if(second_dropdown_index <= 16)
//{
// clickpos_y += n_dropdown_height * second_dropdown_index;
// ClickPos(hwnd,168,clickpos_y);
//}
//else
//{
// for (int i=0; i < second_dropdown_index - 16 ; i++)
// {
// ClickPos(hwnd,266,410); //第二个下拉框 向下按钮
// }
// ClickPos(hwnd,168,410); //最后一项
//}
Sleep(1000);
ClickPos(hwnd,168,clickpos_y);
选不中第30项
时间: 2024-11-26 01:59:17