[Win32] Troubles selecting ComboBox items

I have a ComboBox, defined like this in my resource file:
COMBOBOX IDCB_RESOLUTION, 50,50,50,150, CBS_DROPDOWNLIST | WS_TABSTOP | WS_VSCROLL

It's inside a dialog. Adding items to it works, but somehow I can't seem to select an item with sending the SETCURSEL message... Here's the code from the Callback function:
1
2
3
4
5
6
7
8
case WM_INITDIALOG:
		HWND HCbBox = GetDlgItem(hWnd, IDCB_RESOLUTION);
		std::string strarr[] = {"Hello", "World"};
		std::string* end = strarr + sizeof(strarr);
		auto lambda = [HCbBox](std::string a){return ComboBox_AddString(HCbBox, a.c_str());};
		std::for_each(strarr,end,lambda);
		ComboBox_SetCurSel(HCbBox,0);
		break;

The items appear in the ComboBox but somehow no item is initially selected.

NVM, it seems my pointers were wrong somehow, which probably broke the function. Using a vector instead works.
Last edited on
I was testing this - and I found that std::string* end = strarr + sizeof(strarr); didn't work
for me - as a matter of fact it crashed.

I changed it to std::string* end = &strarr[2]; and it was ok.
Well, thinking a bit about it, I probably should have had sizeof(strarr)/sizeof(std::string) instead.
Last edited on
Topic archived. No new replies allowed.