Jump to content
  • Advertisement
Sign in to follow this  
hahaha

Get ComboBox Selection

This topic is 4011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The Creation of the ComboBox
//Creates the combo box
bool CGui::CreateComboBox()
{
	m_ComboBoxhWnd = CreateWindow(
		TEXT("Combobox"), 
		NULL,
		WS_CHILD|WS_VISIBLE|LBS_STANDARD|LBS_COMBOBOX,
		135,3,
		150,400,
		m_ToolBarhWnd, (HMENU)ID_COMBOBOX,
		m_hInstance,NULL);

	if(m_ComboBoxhWnd == NULL)return false;
	
	string Values[28] = {"BlueBrick",  "BlueDiamond",  "BluePlatform",  "BlueSphere",
                     "Box",  "Dirt",  "Door",  "Empty",  "Fire",  "Grass",  "Ladder",
                     "Lava",  "Mg",  "Mud",  "Pistol",  "Pole",  "PurpleDiamond",
                     "PurplePlatform",  "PurpleSphere",  "RedBrick",  "RedDiamond",
                     "RedPlatform",  "RedSphere",  "Sand",  "Smg",  "Spikes",
                      "Water",  "Weed"};

	for(int i=0;i<28;i++)
	{
		SendMessage(m_ComboBoxhWnd, CB_ADDSTRING, 0, (LPARAM)Values.c_str());
	}
	SendMessage(m_ComboBoxhWnd, CB_SETCURSEL, 0, 0);
	return true;
}

Message Handling:
case WM_COMMAND:
switch(LOWORD(wParam))
{
	case ID_COMBOBOX:
	  {
		hControl = GetDlgItem(hwnd,ID_COMBOBOX);
		char Buffer[128];
		if(HIWORD(wParam) == CBN_SELCHANGE)
		{         
			int nIndex = SendMessage(hControl , CB_GETCURSEL, 0, 0 );     
			SendMessage(hControl,CB_GETLBTEXT, nIndex,(LPARAM)Buffer); 
       
			MessageBox(hwnd,Buffer,"You Selected:",0);
		}
	  }
	  break;
}

When i run my program the message box comes up with a whole lot of rubbish. All sorts of wierd characters. Any ideas why? THanks

Share this post


Link to post
Share on other sites
Advertisement
What about:
SendMessage((HWND)lParam, CB_GETLBTEXT, 0, (LPARAM)Buffer);
?

Also, what does GetLastError() return after SendMessage returns 0?

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
What about:
SendMessage((HWND)lParam, CB_GETLBTEXT, 0, (LPARAM)Buffer);?


Thanks a lot! That worked. I also changed int nIndex = SendMessage(hControl , CB_GETCURSEL, 0, 0 ); to int nIndex = SendMessage((HWND)lParam , CB_GETCURSEL, 0, 0 ); and it returns the correct index.

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!