获取combobox 的索引值时,索引值重复出现现象。
下列代码简写,只写主体:void init()//初始化
{
...
drop_down_list = CreateWindow(_T("combobox"), NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_HASSTRINGS,
190, 20, 80, 100, hWnd, (HMENU)DROP_DOWN_LIST, hInstance, NULL);
SendMessage(drop_down_list, CB_ADDSTRING, 0, (LPARAM)_T("圆"));
SendMessage(drop_down_list, CB_ADDSTRING, 0, (LPARAM)_T("椭圆"));
....
}
LRESULT CALLBACK WndProc(....)
{
...
case DROP_DOWN_LIST:
{
//获取点击项的索引值
int idx = SendMessage(drop_down_list, CB_GETCURSEL, 0, 0);
AllocConsole();
freopen("conout$", "w", stdout);
cout << idx << endl;
break;
}
}
结果:
问题:为什么点击时会调用这个消息好几次。导致重复刷idx 5次。