Reputation: 19
Alright so I had a question about checking for the ComboBox item, I currently have used "ComboBox_AddString" to add the items and I was using ComboBox_GetText passing that off to a wchar_t, then checking if that wchar_t equals to L"Minecraft" EVERYTHING in the debugger matches for variable names but it skips over it like it's not equivalent. Is there a "mainstream" way of checking for selected ComboBox Items.
wchar_t* szProccessToKill = new wchar_t[20];
GetWindowText(hUserBox, szProccessToKill, 20);
wchar_t* szGameSelect = new wchar_t[20];
ComboBox_GetText(comboBox, szGameSelect, 20);
if (szGameSelect == L"Minecraft")
{
MessageBox(NULL, L"HAI", L"NULL", NULL);
}
This is the whole code if you want to take a look at it and let me know if there was a better way, I need this to work because it is a GameLauncher and I decided to have a ComboBox instead of millions of buttons. I seen people use SendMessage but I didn't know why since ComboBox_AddString worked perfectly.
case WM_CREATE:
{
CreateWindowEx(NULL, BUTTON, L"Check for process", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX , 5, 35, 150, 25, hwnd, (HMENU)2, NULL, NULL);
comboBox = CreateWindow(L"combobox", L"", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST , 250, 5, 100, 25, hwnd, (HMENU)1, NULL, NULL);
ComboBox_AddString(comboBox, L"Minecraft");
ComboBox_AddString(comboBox, L"Smite");
CreateWindow(BUTTON, L"Launch", WS_CHILD | WS_VISIBLE, 250, 30, 100, 25, hwnd, (HMENU)4, NULL, NULL);
hUserBox = CreateWindow(L"static", L"Awaiting Commands...", WS_CHILD | WS_VISIBLE | WS_BORDER, 5, 5, 240, 25, hwnd, NULL, NULL, NULL);
break;
}
case WM_COMMAND:
switch (LOWORD(wparam))
{
case 4:
{
wchar_t* szProccessToKill = new wchar_t[20];
GetWindowText(hUserBox, szProccessToKill, 20);
wchar_t* szGameSelect = new wchar_t[20];
ComboBox_GetText(comboBox, szGameSelect, 20);
if (szGameSelect == L"Minecraft")
{
MessageBox(NULL, L"HAI", L"NULL", NULL);
}
Upvotes: 0
Views: 856
Reputation: 308520
The problem is here:
if (szGameSelect == L"Minecraft")
This isn't a string comparison! It's comparing two pointers, which of course won't be equal. Instead you need wcscmp
:
if (wcscmp(szGameSelect, L"Minecraft") == 0)
Upvotes: 4